Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter WidgetsBinding.instance.addPostFrameCallback((_) error

Tags:

flutter

dart

Hello friends first off all sorry for my bad English. I'm getting an error when I start debug my code in flutter-Dart.

          import 'package:flutter/foundation.dart';
          import 'package:flutter/material.dart';
          import 'package:get/get.dart';
          import 'package:http/http.dart' as http;

          // Bu alan benim soru değişkenlerimi Getx yardımı ile tuttuğum classdır.farkllı değişken classları yazılabilir.
          class memberController extends GetxController {
            //5 benim değikenimin ilk değeridir.
            var _memberName = "a".obs;
            var _memberPhoto = "a".obs;

            //get ile çeker, set ile veriyi atarım.
            get memberName => _memberName.value;
            set memberName(yeniDeger) => _memberName.value = yeniDeger;

            get memberPhoto => _memberPhoto.value;
            set memberPhoto(yeniDeger) => _memberPhoto.value = yeniDeger;
          }

          void main() => runApp(MyApp());

          class MyApp extends StatelessWidget {
            memberController _controller1 = Get.put(memberController());

            @override
            Widget build(BuildContext context) {
              return MaterialApp(
                title: 'Material App',
                home: Scaffold(
                  body: SafeArea(
                      child: Column(
                    children: [
                      TextField(
                        onChanged: (Value) {
                          _controller1.memberName = Value;
                        },
                        decoration:
                            InputDecoration(border: InputBorder.none, hintText: 'memberName'),
                      ),
                      TextField(
                        onChanged: (Value) {
                          _controller1.memberPhoto = Value;
                        },
                        decoration:
                            InputDecoration(border: InputBorder.none, hintText: 'memberPhoto'),
                      ),
                      ElevatedButton(
                        onPressed: () async {
                          final uriAAA = 'https://www.meshcurrent.online/myWebApp/add_user.php';
                          var map = new Map<String, dynamic>();
                          map['memberName'] = _controller1.memberName;
                          map['memberPhoto'] = _controller1.memberPhoto;

                          http.Response response = await http.post(
                            Uri.parse(uriAAA),
                            body: map,
                          );
                        },
                        child: Text('SORUYU EKLE'),
                      ),
                    ],
                  )),
                ),
              );
            }
          }

This is my code memberAdd.dart file. Target of this code. -There is two textfield and I will get text from textfields with getx library. When textfields onChanged getx _controller1.memberName and _conroller1.memberPhoto chancing. -I will send my datas from texfields to webserber when I pressed the Elevatedbutton.

But I'm getting this error

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

There is a lot of error text like this.

Please help me. I'm using visual Studio

like image 739
mesh Avatar asked Aug 07 '26 07:08

mesh


1 Answers

Solution

This is a known issue.

You can use this temporary solution

But in summary, just update your pubspec.yaml:

dependencies:
  # ...
  get: ^4.6.x # Remove this line
  get: 4.6.1 # And replace with this line
  # ...

This will force to use a version where the bug doesn't exists.

But where this error came from?

This error means nothing from your code but from GetX package which you are using in your project. So there's nothing you can do in your project to fix that.

You can notice it's not about your code by looking at the exception location:

C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-4.6.3/lib/get_navigation/src/extension_navigation.dart:357:33

The .pub-cache/hosted/pub.dartlang.org is a directory where Flutter hosts the libraries you depend on.

Sometimes we face with exceptions/errors that are not related our project itself but packages/libraries/plugins we depend on. This can have many causes but the most commons are when Flutter has significative breaking changes and the packages don't migrate correctly, then the users of the package fall in errors committed by the package maintainer's.

Solution approaches

To be quite straightforward: there's no absolute fix, but there's a right direction:

  • Find where are the bug (which package? which repository?)
  • Search for issues or PRs that mentions the same error as you (if you are luckly you'll find the solution in this step, which is your case right now)
  • If you didn't find anything related to, search for a solution yourself and open a issue or pull request (or you can also just open an issue if you don't know how to fix, try to give much details as you can)
  • Wait for merge and a new release with your bug fixes. You can either create a plugin fork which contains your fix and make your project dependant of it (a version which has the fix)
like image 155
lakscastro Avatar answered Aug 12 '26 12:08

lakscastro



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!