Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null

Tags:

flutter

dart

Whenever I try to run my Flutter app I get this error, it was running and I don't know why now it's not. I've even reset to previous commit and it still won't run.

../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_navigation/src/extension_navigation.dart:357:33: Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
      SchedulerBinding.instance.addPostFrameCallback((_) {
                                ^^^^^^^^^^^^^^^^^^^^
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_navigation/src/extension_navigation.dart:468:33: Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
      SchedulerBinding.instance.addPostFrameCallback((_) {
                                ^^^^^^^^^^^^^^^^^^^^
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_navigation/src/snackbar/snackbar.dart:452:31: Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
    SchedulerBinding.instance.addPostFrameCallback(
                              ^^^^^^^^^^^^^^^^^^^^
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_state_manager/src/rx_flutter/rx_notifier.dart:130:31: Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
    SchedulerBinding.instance.addPostFrameCallback((_) => onReady());
                              ^^^^^^^^^^^^^^^^^^^^
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_state_manager/src/simple/get_controllers.dart:90:29: Error: Method 'addObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addObserver(this);
                            ^^^^^^^^^^^
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_state_manager/src/simple/get_controllers.dart:96:29: Error: Method 'removeObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.removeObserver(this);
                            ^^^^^^^^^^^^^^
../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_navigation/src/router_report.dart:53:31: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../development/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
      WidgetsBinding.instance.addPostFrameCallback((_) {
                              ^^^^^^^^^^^^^^^^^^^^

FAILURE: Build failed with an exception.

* Where:
Script '/home/ibrahimdev/development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1102

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/ibrahimdev/development/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 18s

like image 267
Ibrahim Houssem Avatar asked Jun 22 '26 08:06

Ibrahim Houssem


2 Answers

Some changes happened in null-safety properties at the last upgrade of Flutter 3.0.0. There are a few approaches to a solution.

1-) If you upgraded the latest Flutter version and if your error is in the Flutter Core codes you must try;

- dart fix --apply

(Ref: https://docs.flutter.dev/development/tools/sdk/release-notes/release-notes-3.0.0)

If this solution doesn't fix any error you can downgrade the Flutter version;

- flutter downgrade v2.10.5

2-) If you didn't upgrade or the error is in the third-party package;

  1. The developer of this package may have upgraded this package to the recent version of Flutter. You can upgrade packages with;

    flutter pub upgrade --major-versions
    
  2. If the developer hasn't upgraded yet, you must go to this package's Github repo and look at the issue tab. Maybe someone opened an issue and the dev answered the correct running version. For example, GetX's latest compatible version with Flutter 2.10.5 is 4.6.1. So for applying this version you can just use the version constraint (remove ˆ).

Update

get: ˆ4.6.1

to

get: 4.6.1

in your pubspec.

(Ref: https://github.com/jonataslaw/getx/issues/2356)

like image 79
Furkan Abbasioğlu Avatar answered Jun 25 '26 03:06

Furkan Abbasioğlu


ran into the same problem and solved it by updating my flutter version to version 3.0. Run flutter upgrade in your console and reopen vscode(or your editor). check the bottom right (on vscode) to ensure it has been updated to version 3.0.0

like image 39
Headquarters Avatar answered Jun 25 '26 01:06

Headquarters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!