flutterflutter-3.0

Flutter: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null. when upgrading to flutter 3.0.0


When upgraded to flutter 3.0.0 , there is a problem started to appear when running the app,

(The app works but there are error/s (warning/s) in the terminal).

It seems like a Binding issue.

the error(warning) says: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.

: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
../…/src/keyboard_visibility.dart:21
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../fvm/versions/3.0.0/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
    WidgetsBinding.instance!.addObserver(this);

                   ^
: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
../…/src/keyboard_visibility.dart:37
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../fvm/versions/3.0.0/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
    WidgetsBinding.instance!.removeObserver(this);
                   ^
: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
../…/src/bot_toast_init.dart:15
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../fvm/versions/3.0.0/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
    WidgetsBinding.instance!.addObserver(this);
                   ^
: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.
../…/src/bot_toast_manager.dart:6
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../fvm/versions/3.0.0/packages/flutter/lib/src/scheduler/binding.dart').
package:flutter/…/scheduler/binding.dart:1
  SchedulerBinding.instance!.addPostFrameCallback((_) {
                   ^
: Warning: Operand of null-aware operation '!' has type 'SchedulerBinding' which excludes null.
../…/src/bot_toast_manager.dart:9
- 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../fvm/versions/3.0.0/packages/flutter/lib/src/scheduler/binding.dart').
package:flutter/…/scheduler/binding.dart:1
  SchedulerBinding.instance!.ensureVisualUpdate();

Edit: - The problem is related to the compatibility of some packages with the flutter 3.0.0

Flutter 3.0.0 release notes

f you see warnings about bindings When migrating to Flutter 3, you might see warnings like the following:

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

-for example like the package bot_toast There is an open issue on the GitHub repository of this package https://github.com/MMMzq/bot_toast/issues/133 so the problem should be fixed soon after releasing an update as they said.


Solution

  • We can now DISCARD THE WARNING and wait until the authors of these packages deal with the new changes in flutter 3 to solve the problem and update their packages. The developers of the packages are now catching up on these changes and there should be new versions of the affected packages soon.

    Example of a package with this issue:

    These warnings should not be breaking anything (just causing log spam, for which we apologize; we plan to fix that in the next release, we didn't realize how big of an issue it would be). If your app no longer works, that is unlikely to be related to this issue

    reference:

    https://github.com/flutter/flutter/issues/103561#issuecomment-1126416045