how can I fix this error in flutter 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( ^^^^^^^^^^^^^^^^^^^^
CodePudding user response:
Error:
The error is saying the instance of SchedulerBinding
(i.e SchedulerBinding.instance
) can be null and so you should add a null check (?
) to ensure that the addPostFrameCallback
method is only called on a non-null instance.
Solution:
Update:
SchedulerBinding.instance.addPostFrameCallback
to:
SchedulerBinding.instance?.addPostFrameCallback // With '?' after instance
Checkout Understanding null safety | Dart for more on Dart's null safety.
CodePudding user response:
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