Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 804
pomoworko.com Avatar asked Jul 25 '26 00:07

pomoworko.com


1 Answers

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.

like image 50
Nas Shihab Avatar answered Jul 26 '26 17:07

Nas Shihab