'Flutter : Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null
I run my flutter app on (Flutter 3.0 and dart sdk 2.17.0.
But now I found a warning here, like this -
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/router_report.dart:53:22: Warning: Operand of null-aware
operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/widgets/bindi
ng.dart').
WidgetsBinding.instance!.addPostFrameCallback((_) {
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/snackbar/snackbar.dart:452:22: Warning: Operand of
null-aware operation '!' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance!.addPostFrameCallback(
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/extension_navigation.dart:357:24: Warning: Operand of
null-aware operation '!' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance!.addPostFrameCallback((_) {
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_navigation/src/extension_navigation.dart:468:24: Warning: Operand of
null-aware operation '!' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance!.addPostFrameCallback((_) {
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/simple/get_controllers.dart:90:20: Warning: Operand
of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/widgets/bindi
ng.dart').
WidgetsBinding.instance!.addObserver(this);
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/simple/get_controllers.dart:96:20: Warning: Operand
of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/widgets/bindi
ng.dart').
WidgetsBinding.instance!.removeObserver(this);
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/rx_flutter/rx_notifier.dart:130:22: Warning: Operand
of null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance?.addPostFrameCallback((_) => onReady());
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.
6.1/lib/get_state_manager/src/rx_flutter/rx_disposable.dart:20:22: Warning: Operand
of null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance?.addPostFrameCallback((_) => onReady());
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/overlay_entry.dart:35:26: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
if (SchedulerBinding.instance?.schedulerPhase ==
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/overlay_entry.dart:37:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance?.addPostFrameCallback((_) {
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/container.dart:64:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance?.schedulerPhase ==
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/container.dart:101:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance?.addPostFrameCallback((_) => completer
^
/usr/local/Caskroom/flutter/2.0.2/flutter/.pub-cache/hosted/pub.dartlang.org/flutte
r_easyloading-3.0.3/lib/src/widgets/container.dart:112:24: Warning: Operand of
null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart'
('/usr/local/Caskroom/flutter/2.0.2/flutter/packages/flutter/lib/src/scheduler/bin
ding.dart').
SchedulerBinding.instance?.addPostFrameCallback((_) => completer
^
Syncing files to device iPhone SE (3rd generation)... 805ms
What is the problem. It's not show in previous version of flutter.
Solution 1:[1]
In Flutter 3.0
SchedulerBinding.instance!.addPostFrameCallback(...);
became
SchedulerBinding.instance.addPostFrameCallback(...);
seems like the bindings package has some Schedulerbindings coded inside and needs to be updated.
You can copy the package locally and change the code inside that package.
Or change the dependencies.... or wait until that package is updated and revert to Flutter 2.10.5
You can read about the changes to Flutter 3.0 Here
I use a tool for changing versions Flutter Sidekick you can chose diffferent Flutter versions for different project.
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 | Eric |