'Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null

After updating Flutter 3.0 below compile error occured. This error has no ref to my code. It refers to framework.

Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.
../…/src/framework.dart:275
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../snap/flutter/common/flutter/packages/flutter/lib/src/scheduler/binding.dart').
package:flutter/…/scheduler/binding.dart:1
    if (SchedulerBinding.instance!.schedulerPhase ==


Solution 1:[1]

Note that it is a warning, and not an error: The app will compile and run just fine.

It basically means that in many places in the code (in 3rd party packages and I think also in some 1st party instances) there is a null check, which is now redundant. That is, before you'd use

SchedulerBinding.instance!.someField == ...

Because SchedulerBinding.instance had the type SchedulerBinding?, which may (technically) be null. Since in practice, the ! operator was used, it was already assumed to not be null, and with the new changes in the SDK, they changed the type so it actually can never be null. Now, you can simply say

SchedulerBinding.instance.someField == ...

If you still include the ! or ? operators, your IDE will warn you, that this is a redundant check, as the instance can never be null. Unfortunately, we'll be stuck with these warnings until the packages you use and Flutter itself solve this, but you can definitely ignore them, as a unnecessary null check will never break your code.

Solution 2:[2]

It's expected when you migrate to Flutter 3.0. The docs also mention about this:

Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.

These are caused by a simplification of the API (the instance property on bindings is now non-nullable), combined with an eager compiler that wants to report any case where redundant null-aware operators (such as ! and ?.) that are used when they’re not necessary.

Solutions:

  1. You can update your packages by running flutter pub upgrade.

  2. If the issue persist, (say, some of the packages are still giving you this error), you can either ignore it as this is just a warning or simply edit the source file and remove ? and/or !.

Solution 3:[3]

i am not sure if i am right.. I got this error after connecting firebase and making some changes to gradle. so next day, after uninstalling flutter, android studio (including sdk) and reinstalling.. i am not getting this error but i still havent reconnected firebase as of now.

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 fravolt
Solution 2 CopsOnRoad
Solution 3 Progressive Ways