Reputation: 184
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
Upvotes: 7
Views: 16339
Reputation: 13
I got the same error and the solution that worked for me is as follows
probleme:
velocity_x: ^3.5.1
doesn't work with flutter 2.10.
, because ^3.5.1
is for flutter 3
solution:
step: 1
in pubspec.yaml
change velocity_x: ^3.5.1
by velocity_x: ^3.4.0
step: 2
in pubspec.lock
change velocity_x version: "3.5.1"
by version: "3.4.0"
step: 3
flutter clean
step: 4
flutter run
i think it will work for you
Upvotes: 0
Reputation: 21
If you can't upgrade or downgrade the version of flutter, you can try this version of percent indicator (with double quotes). percent_indicator: "^2.1.9+1" . Then, clean and flutter pub get.
It's worked for me..
Upvotes: 1
Reputation: 133
The problem is that the package causing this issue has been updated to be compatible with the latest version of Flutter, 3.0.0. You can either:
If you choose the second option, as it might not be desirable to update your project to the latest version of Flutter right now, your best shot is to see the version history of the package and downgrade to the version before it was made compatible with the new Flutter SDK version.
If the version history is not clear, the other option you have is to go to the package issues page at GitHub (See at the right side of the package page at pub.dev, "View/report issues"), search if anyone has already reported the problem (you can use the search bar and look for "SchedulerBinding" or something like that), and see if anyone in the comments of the issue points out the version before the change.
If you still can't find the last compatible version, you can do trial and error for each version available in the version history of the package. Don't forget to remove the (^) symbol in the version of the package of your pubspec.yaml or it will still use the latest version.
Upvotes: 1
Reputation: 2414
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.
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.
To be quite straightforward: there's no absolute fix, but there's a right direction:
Upvotes: 3