How to fix "Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?'" in Flutter
Asked Answered
V

4

7

I'm facing the following error in my Flutter project while working with Android Studio:


/C:/src/flutterSDK/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' 
('/C:/src/flutterSDK/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
    SchedulerBinding.instance.addPostFrameCallback(
                              ^^^^^^^^^^^^^^^^^^^^

Can anyone help me understand the cause of this error and suggest a solution?

Verada answered 14/5, 2022 at 23:23 Comment(1)
same problem here, I tried also downgrading to 4.6.1 but nothingChe
W
6

This error happens because the package get 4.6.2 or 4.6.3 is for new flutter sdk version 3.0. So you got this error. you have to use get 4.6.1 for fluter SDK version 2.xx

I had the same problem.. on "dart.get" package. Then I did this..

First go to pubspec.yaml file then edit the get version not more than (get: ^4.6.1).. if you are using fluter sdk v2.xx.

if the version won't get lower then try this method

go to pubspec.lock file. edit the version not more than (4.6.1).. if you are using fluter sdk v2.xx.

you will find in pubspec.lock file

and last you have to do this

then "pub get" .. error will be gone.

Walden answered 17/5, 2022 at 16:33 Comment(2)
My flutter version is 2.10.5, and get : 4.6.1 , but still its not working. I tried invalidate cache and restart, tried flutter clean . Nothing helped.Ipsus
> First check in External Libraries that it has a folder get 4.6.x somthing. delete the GET dependencies from puspech.. > then in terminal : flutter pub cache repair > delete pubspec.lock file.. > then pub get then do fresh start on GET package try 4.6.0 thenWalden
D
3

This is because of recent flutter updates. All flutter SDKs >= V2.10.3 have this issue. There's no proper solution for this error yet.

Temporary Solution:

You can simply downgrade your flutter SDK to V2.10.2 or lower to get rid of this issue.

Note:

After downgrading, make sure you also change the dart version in pubspec.yaml of your flutter project according to the Flutter SDK.

Dowd answered 28/5, 2022 at 21:9 Comment(0)
C
1

This error is due to some changes happened in null-safety properties in Flutter 3.0.0. In your case you can try to import: get: 4.6.1 instead of get: ^4.6.3. Source: https://github.com/jonataslaw/getx/issues/2356

Che answered 16/5, 2022 at 18:32 Comment(0)
L
1

try this

flutter doctor --android-licenses
Luganda answered 31/7, 2022 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.