'Flutter Error: WidgetsBinding.instance!.addPostFrameCallback((_) {

After upgrading to 3.0.0. i keep getting this error about WidgetsBinding.instance!.addPostFrameCallback((_) {

here is the image of the error. enter image description here



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1