尝试List
从一个屏幕传递到另一个屏幕时出现以下错误。数据正在从async
函数传递。我需要根据从数据库中获取的数据打开另一个屏幕。这里提到的答案对我不起作用。这是错误。
: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The
getter 'focusScopeNode' was called on null.
E/flutter (26425): Receiver: null
E/flutter (26425): Tried calling: focusScopeNode
E/flutter (26425): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (26425): #1 Route.didPush.<anonymous closure> (package:flutter/src/widgets/navigator.dart:139:17)
异步函数中的代码
Navigator.push(context, MaterialPageRoute(builder: (context) {
return ParentHome(childList);
家长主屏幕
class ParentHome extends StatefulWidget {
List childDataList;
ParentHome(this.childDataList);
@override
State<StatefulWidget> createState() {
return ParentHomeWidget();
}
}
class ParentHomeWidget extends State<ParentHome> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: Scaffold(
body: Container(
margin: EdgeInsets.all(5),
child: ListView.builder(
itemCount: widget.childDataList.length,
itemBuilder: (BuildContext context, int index) => ListTile(
title: Text(widget.childDataList[index]['title']),
)),
),
),
);
}
}
我没有找到任何帮助。请帮我解决这个问题。我还是 Flutter 的新手。谢谢
颤振医生输出
Flutter(Channel stable,v1.12.13+hotfix.5,在 Linux 上,语言环境 en_US.UTF-8)
• Flutter 版本 1.12.13+hotfix.5,位于 /home/jamshaid/Documents/flutter_linux_v1.9.1+hotfix.4-stable /flutter
• 框架修订 27321ebbad(6 周前),2019-12-10 18:15:01 -0800 • 引擎修订 2994f7e1e6
• Dart 版本 2.7.0
完成同步功能
Future<void> requestLogin(String userType) async {
/*
final response =
await http.get('http://10.0.2.2/php_to_flutter/login_validation.php');*/
String databaseAddress = "";
switch (userType) {
case "Student":
databaseAddress = AppUtils.studentLoginLink;
break;
case "Parent":
databaseAddress = AppUtils.parentLoginLink;
break;
case "Teacher":
databaseAddress = AppUtils.teacherLoginLink;
break;
}
final response = await http
.post(databaseAddress, body: {"email": email, "password": password});
String responseBody = response.body;
if (response.statusCode == 200) {
switch (userType) {
case "Student":
print("Registration # $responseBody");
break;
case "Parent":
List childList = responseBody.split(",");
//child list needs to be separated by :
/*Navigator.of(context).push(
MaterialPageRoute(builder: (context) => ParentHome(childList)));
*/
Navigator.push(context, MaterialPageRoute(builder: (context) {
return ParentHome(childList);
}));
//Navigator.pop(context);
print("Child List= $responseBody");
break;
case "Teacher":
print("Teacher id= $responseBody");
break;
}
form_key.currentState.reset();
//dismissing progress dialog
Navigator.pop(context);
Toast.show("Login Successful", context,
duration: Toast.LENGTH_SHORT, gravity: Toast.CENTER);
} else {
Navigator.pop(context);
print(databaseAddress);
Toast.show("Error: " + response.statusCode.toString(), context,
duration: Toast.LENGTH_SHORT, gravity: Toast.CENTER);
print('error' + response.body);
print(response.statusCode);
}
}
异步调用者代码
异步函数正在被onPressed
调用RaisedButton
。
Widget studentLoginButton() {
return RaisedButton(
onPressed: () {
if (form_key.currentState.validate()) {
form_key.currentState.save();
// pr.show();
AppUtils.showProgressDialog(context, "Loggin in...");
requestLogin("Student");
form_key.currentState.reset();
//pr.dismiss();
}
// form_key.currentState.reset();
},
child: Text('S Login'),
color: Colors.lightBlue,
);
}