Home > Software engineering >  Flutter 3.0 shows error : WidgetsBinding.instance!.addPostFrameCallback((_) => widget.onReady.cal
Flutter 3.0 shows error : WidgetsBinding.instance!.addPostFrameCallback((_) => widget.onReady.cal

Time:05-20

After the upgrade project in flutter 3.0 it shows the following error.

    Syncing files to device iPhone 13 Pro Max...
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/another_transformer_page_view-1.1.0/lib/src/another_transformer_page_view.dart:519:22: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
      WidgetsBinding.instance!.addPostFrameCallback(_onGetSize);
                     ^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/another_transformer_page_view-1.1.0/lib/src/another_transformer_page_view.dart:537:22: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
      WidgetsBinding.instance!.addPostFrameCallback(_onGetSize);
                     ^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_login-3.2.0/lib/src/widgets/animated_text.dart:57:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.addPostFrameCallback((_) {
                   ^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/awesome_select-5.2.0/lib/src/widget.dart:1547:58: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
                MediaQueryData.fromWindow(WidgetsBinding.instance!.window);
                                                         ^
../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/awesome_select-5.2.0/lib/src/text_error.dart:99:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.addPostFrameCallback((_) {

it's bug from flutter? Can anyone report this to flutter. i don't know to report this to flutter team.

CodePudding user response:

it's bug from lib you used in your project, Don't worry. It will fix in next version dependency of lib

Or you can fork code from lib, fix it, and create a pull request to main

example of this issue

use

cached_network_image:
    git:
      url: https://github.com/XuannThucc/flutter_cached_network_image.git
      path: cached_network_image
      ref: ff72f00f142f13d889d7549e013af91cb0b523ab

instead of

cached_network_image: ^3.2.0

or wait for update cached_network_image: ^3.2.1

CodePudding user response:

'WidgetsBinding.instance' getter used to be a nullable type. In the new update it is changed to a Non-nullable. So, now old packages show this after the update because they used null aware operator there. It will be fixed in the new versions. For now you can just remove the null aware operator from the lines that show up in the logs and after rebuild there will be no more warnings.

  • Related