大家好,首先很抱歉我的英语不好。 在使用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'),
),
],
)),
),
);
}
}
这是我的memberAdd.dart代码文件。 这段代码的目标: - 有两个文本框,我将使用getx库从文本框中获取文本。当文本框的onChanged事件发生时,_controller1.memberName和_conroller1.memberPhoto也会更改。 - 当我按下Elevatedbutton时,我将把数据从文本框发送到web服务器。
但是我遇到了错误。
/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((_) {
有很多像这样的错误文本。
请帮帮我。 我正在使用Visual Studio。