Home > front end >  Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which e
Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which e

Time:05-14

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 ==

CodePudding user response:

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.

CodePudding user response:

this question is already answered Here. This error is a fatal error and can be ignored.

  • Related