Getx: Snackbar doesn't show until the user interacts with the screen

Created on 29 Apr 2020  ·  4Comments  ·  Source: jonataslaw/getx

Describe the bug
The snackbar will not show on the screen until it is touched

To Reproduce
Steps to reproduce the behavior:
When using get.snackbar it doesn't show the snackbar until the app is interacted with

Expected behavior
The snackbar to show as soon as it's called even if the app isn't being interacted with

Screenshots
github-small

Flutter Version:
v1.17.0-3.2.pre

Get Version:
^2.0.7-dev

Describe on which device you found the bug:
Android Studio emulator and Oneplus 3

Minimal reproduce code
Get.snackbar("Snatched \(^ o ^)/","test",snackPosition: SnackPosition.BOTTOM,duration: Duration(seconds: 1),colorText: Colors.black, backgroundColor: Colors.pink[200]);

Most helpful comment

Its will solve your problem:

GetBar(title: "Snatched \(^ o ^)/", message: "test",snackPosition: SnackPosition.BOTTOM,duration: Duration(seconds: 1),colorText: Colors.black, backgroundColor: Colors.pink[200]).show();

I don't know your code to say if it's a bug with Flutter's Scheduler.binding, or your code already has a Scheduler.binding or something that prevents it from starting, but basically it is only being updated when the user touches the screen. This is not a Get problem, but using the raw API described above will solve it, because it does not use Scheduler.binding, and it is the cause of the problem.
Note - Scheduler.binding is a Flutter API that prevents a function from being called during the build method, this prevents errors when, for example, someone puts a snackbar on initState, but in your case, either you are already using it, or your code is preventing it from being heard, so the only way is to remove it.

All 4 comments

Its will solve your problem:

GetBar(title: "Snatched \(^ o ^)/", message: "test",snackPosition: SnackPosition.BOTTOM,duration: Duration(seconds: 1),colorText: Colors.black, backgroundColor: Colors.pink[200]).show();

I don't know your code to say if it's a bug with Flutter's Scheduler.binding, or your code already has a Scheduler.binding or something that prevents it from starting, but basically it is only being updated when the user touches the screen. This is not a Get problem, but using the raw API described above will solve it, because it does not use Scheduler.binding, and it is the cause of the problem.
Note - Scheduler.binding is a Flutter API that prevents a function from being called during the build method, this prevents errors when, for example, someone puts a snackbar on initState, but in your case, either you are already using it, or your code is preventing it from being heard, so the only way is to remove it.

Okay thankyou i think it was caused by it being inside an async function so i've moved the Get.snackbar outside of that function and it shows instantly. Also is there a way to set the textcolor with GetBar as it wont take colorText as an option?

Okay thankyou i think it was caused by it being inside an async function so i've moved the Get.snackbar outside of that function and it shows instantly. Also is there a way to set the textcolor with GetBar as it wont take colorText as an option?

 GetBar(
          titleText:
              Text(
                "Snatched \(^ o ^)/",
                style: TextStyle(
                    color: Colors.black, // custom color text
                    fontWeight: FontWeight.w800,
                    fontSize: 16),
              ),
          messageText: 
              Text(
                "teste",
                style: TextStyle(
                    color: Colors.green,  // custom color message
                    fontWeight: FontWeight.w300,
                    fontSize: 14),
              ),

Get.snackbar has no problems with asynchronous functions, but it is certainly blocking SchredulerBinding.

It's similar https://github.com/jonataslaw/get/issues/47
Closing.

If you face any problem with Get, feel free to open another issue.

Was this page helpful?
0 / 5 - 0 ratings