After upgrading to 3.0.0. i keep getting this error about WidgetsBinding.instance!.addPostFrameCallback((_) {
2 Answers
change
WidgetsBinding.instance!.addPostFrameCallback((_) {});
to
WidgetsBinding.instance.addPostFrameCallback((_) {});
You can also run dart fix --apply from the command line which will make the above change for you automatically.
The return type of WidgetsBinding.instance was changed from static WidgetsBinding? get instance => ... to static WidgetsBinding get instance => ... so adding ! or ? is no longer required.
Also, note that this is just a warning, and you may get the warning from dependencies if they also have an unnecessary ? or !.
See also Flutter 3.0.0 release notes - If you see warnings about bindings.
6 Comments
pubspec.yaml file. In the meantime you can simply ignore the warnings, the app should compile and run even if these warnings are present.states_rebuilder when they fix this issue. Also, the most recent version appears to be 6.1.0, I would try upgrading to 6.1.0 first to see if the issue still exists in that version.states_rebuilder to the latest version in your pubspec.That will not work but you can move the '?' to read:
WidgetsBinding.instance?.addPostFrameCallback((_) {});
Instead of
WidgetsBinding?.instance.addPostFrameCallback((_) {});
