Flutter 3.0 shows error : WidgetsBinding.instance!.addPostFrameCallback((_) => widget.onReady.call());

1,123

'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.

Share:
1,123
amit.flutter
Author by

amit.flutter

Currently working as an iOS and Flutter developer at Karmaleen Technology.

Updated on December 02, 2022

Comments

  • amit.flutter
    amit.flutter over 1 year

    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.

    This Warning bug is resolved. see my comment in correct answer I have written ( if you are a mac user goto finder -> press goto button by swift+cmd+G -> past all 6 files I have mentioned or you find an error and replace [root-name] with your root directory name.

    • Hardik Mehta
      Hardik Mehta almost 2 years
      try to do flutter clean , flutter pub update and cd ios and pod install and try
  • amit.flutter
    amit.flutter almost 2 years
    I make changes as per your suggestion but it's not working. Error is still same
  • amit.flutter
    amit.flutter almost 2 years
    i am already Using: cached_network_image: ^3.2.1
  • Xuann Thucc
    Xuann Thucc almost 2 years
    these warnings are just warnings. Very annoying, but still compiling and running fine.
  • amit.flutter
    amit.flutter almost 2 years
    Okay, Thank you. Let me know if there is solution to remove this warning.
  • amit.flutter
    amit.flutter almost 2 years
    Yes, it's just warning i have removed the null operator from each file where the error is showing.
  • amit.flutter
    amit.flutter almost 2 years
    for mac user press : Swift + window/CMD key + G ( open goto file dialog) and past this files path
  • amit.flutter
    amit.flutter almost 2 years
    1) /Users/[root-name]/Developer/flutter/.pub-cache/hosted/pub.d‌​artlang.org/flutter_‌​login-3.2.0/lib/src/‌​widgets/animated_tex‌​t.dart
  • amit.flutter
    amit.flutter almost 2 years
    2) /Users/[root-name]/Developer/flutter/.pub-cache/hosted/pub.d‌​artlang.org/another_‌​transformer_page_vie‌​w-1.1.0/lib/src/anot‌​her_transformer_page‌​_view.dart
  • amit.flutter
    amit.flutter almost 2 years
    3) /Users/[root-name]/Developer/flutter/.pub-cache/hosted/pub.d‌​artlang.org/awesome_‌​select-5.2.0/lib/src‌​/widget.dart
  • amit.flutter
    amit.flutter almost 2 years
    4) /Users/[root-name]/Developer/flutter/.pub-cache/hosted/pub.d‌​artlang.org/awesome_‌​select-5.2.0/lib/src‌​/text_error.dart
  • amit.flutter
    amit.flutter almost 2 years
    5) /Users/[root-Name]/Developer/flutter/.pub-cache/hosted/pub.d‌​artlang.org/awesome_‌​select-5.2.0/lib/src‌​/modal.dart
  • amit.flutter
    amit.flutter almost 2 years
    6) /Users/[root-name]/Developer/flutter/packages/flutter/lib/sr‌​c/widgets/binding.da‌​rt