Getx: App freeze on transition in iOS when Get.snackbar is open and swipe right gesture executed

Created on 6 Nov 2020  Â·  10Comments  Â·  Source: jonataslaw/getx

Describe the bug
When I use Get.toNamed() to new screen, then open snackbar on onTab() of a button, and while snackbar is showing using iOS native swipe right function the screen freezes while in transition.

**Reproduction code
example:

void main() => runApp(MaterialApp(home: Home()));

class Home extends StatefulWidget {

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {

//init etc.
//I use DefaultTabController in this class

  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(context){
   super.build(context);
   return ...
      Scaffold(
      appBar: AppBar(title: Text("Start page")),
      body: Center(
        child: Obx(() => Text("Click button to go to next page")),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () => Get.toNamed('/my_new_page'),
      ));
 }
}

class MyNewPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {

    return BaseResponsiveWidget(builder: (context, sizingInformation) {
      return Scaffold(
          resizeToAvoidBottomInset: false,
          body: Container(child: Text("MyNewPage")),
          floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () => Get.Snackbar("Title", "Body"),
      ));
      );
   })

To Reproduce
Steps to reproduce the behavior:

  1. Widget with button -> onTab() => Get.toNamed('/new_widget')
  2. In new Widget have button with -> onTab() => Get.snackbar()
  3. swipe rigth on iOS device to go to previous widget
  4. App freezes

Expected behavior
Get.Snackbar should be closed before transition

Screenshots
grafik

Flutter Version:
1.22.0 • channel stable

Getx Version:
get: '^3.15.0'

Describe on which device you found the bug:
all iOS devices

Minimal reproduce code
s.o.

Waiting for customer response

Most helpful comment

@jonataslaw, I put an example below that is easier to reproduce. If you comment on the Get.scnackbar line and uncomment Scaffold.of(context).showSnackBar(snackBar) line you can see that the problem doesn’t happen, that is, the flutter’s SnackBar doesn’t cause a freeze if we swipe to return to the previous screen.

import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(GetMaterialApp(
    initialRoute: '/home',
    defaultTransition: Transition.cupertino,
    popGesture: true,
    getPages: [
      GetPage(name: '/home', page: () => Home()),
      GetPage(name: '/my_new_page', page: () => MyNewPage()),
    ],
  ));
}

class Home extends StatelessWidget {
  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(title: Text("Start page")),
      body: Center(
        child: RaisedButton(
          child: Text("Click button to go to next page"),
          onPressed: () => Get.toNamed('/my_new_page'),
        ),
      ),
    );
  }
}

class MyNewPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('New Page'),
      ),
      body: SnackBarPage(),
    );
  }
}

class SnackBarPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: ElevatedButton(
        onPressed: () {
          final snackBar = SnackBar(
            content: Text('Yay! A SnackBar!'),
          );

          // Not freeze
          // Scaffold.of(context).showSnackBar(snackBar);

          // Freeze
          Get.snackbar('title', 'message');
        },
        child: Text('Show SnackBar'),
      ),
    );
  }
}

Every child of route since version 1.17 needs to be involved with an iOS motion detector.
I added to GetPageRoute, but I think it will be necessary to add to GetBottomSheetRoute, SnackRoute and GetDialogRoute.

This will require some code refactor, but will likely be fixed in the next update.

Thanks for the reproduction code, this will make my job a lot easier.

All 10 comments

I can confirm this issue. I have it too for all my iOS devices. 😊

Yes I have it too ...

Please, can you check the Flutter's snackbar also have the same problem?

https://flutter.dev/docs/cookbook/design/snackbars

Try this:

void main() {
  runApp(GetMaterialApp(
    home: Home(),
    popGesture: true,
    defaultTransition: Transition.cupertino,
  ));
}

@eduardoflorence Thanks for your reply! I tried your solution, but the freeze still exists.

@jonataslaw, I put an example below that is easier to reproduce. If you comment on the Get.scnackbar line and uncomment Scaffold.of(context).showSnackBar(snackBar) line you can see that the problem doesn’t happen, that is, the flutter’s SnackBar doesn’t cause a freeze if we swipe to return to the previous screen.

import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(GetMaterialApp(
    initialRoute: '/home',
    defaultTransition: Transition.cupertino,
    popGesture: true,
    getPages: [
      GetPage(name: '/home', page: () => Home()),
      GetPage(name: '/my_new_page', page: () => MyNewPage()),
    ],
  ));
}

class Home extends StatelessWidget {
  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(title: Text("Start page")),
      body: Center(
        child: RaisedButton(
          child: Text("Click button to go to next page"),
          onPressed: () => Get.toNamed('/my_new_page'),
        ),
      ),
    );
  }
}

class MyNewPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('New Page'),
      ),
      body: SnackBarPage(),
    );
  }
}

class SnackBarPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: ElevatedButton(
        onPressed: () {
          final snackBar = SnackBar(
            content: Text('Yay! A SnackBar!'),
          );

          // Not freeze
          // Scaffold.of(context).showSnackBar(snackBar);

          // Freeze
          Get.snackbar('title', 'message');
        },
        child: Text('Show SnackBar'),
      ),
    );
  }
}

@jonataslaw, I put an example below that is easier to reproduce. If you comment on the Get.scnackbar line and uncomment Scaffold.of(context).showSnackBar(snackBar) line you can see that the problem doesn’t happen, that is, the flutter’s SnackBar doesn’t cause a freeze if we swipe to return to the previous screen.

import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(GetMaterialApp(
    initialRoute: '/home',
    defaultTransition: Transition.cupertino,
    popGesture: true,
    getPages: [
      GetPage(name: '/home', page: () => Home()),
      GetPage(name: '/my_new_page', page: () => MyNewPage()),
    ],
  ));
}

class Home extends StatelessWidget {
  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(title: Text("Start page")),
      body: Center(
        child: RaisedButton(
          child: Text("Click button to go to next page"),
          onPressed: () => Get.toNamed('/my_new_page'),
        ),
      ),
    );
  }
}

class MyNewPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('New Page'),
      ),
      body: SnackBarPage(),
    );
  }
}

class SnackBarPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: ElevatedButton(
        onPressed: () {
          final snackBar = SnackBar(
            content: Text('Yay! A SnackBar!'),
          );

          // Not freeze
          // Scaffold.of(context).showSnackBar(snackBar);

          // Freeze
          Get.snackbar('title', 'message');
        },
        child: Text('Show SnackBar'),
      ),
    );
  }
}

Every child of route since version 1.17 needs to be involved with an iOS motion detector.
I added to GetPageRoute, but I think it will be necessary to add to GetBottomSheetRoute, SnackRoute and GetDialogRoute.

This will require some code refactor, but will likely be fixed in the next update.

Thanks for the reproduction code, this will make my job a lot easier.

me too. is there way to fix it?

Get 3.25.4 Version still same issue . When it does woking ?

any progress here?

Was this page helpful?
0 / 5 - 0 ratings