大家好,您可以帮我解决这个问题吗?我只是四处走走而没有得到正确的答案,谢谢。
void _submit() {
final form = formKey.currentState;
if (form.validate()) {
form.save();
print(_username);
print(_password);
if (_username == "asdasd") {
if (_password == "123") {
Navigator.pushReplacement(
this.context, MaterialPageRoute(builder: (context) => App()));
} else {
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("login Failed, please re-type properly"),
backgroundColor: Colors.redAccent,
)); // SnackBar
}
} else {
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Login Failed, please re-type properly"),
backgroundColor: Colors.redAccent,
));
}
}
}
错误消息:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following ArgumentError was thrown building HomePageScreen(dirty, state: _HomePageScreenState#3ae53): Invalid argument(s) The relevant error-causing widget was: HomePageScreen file:///Users/andrehendrawan/Downloads/ican/lib/Screens/App.dart:20:5 When the exception was thrown, this was the stack: #0 _StringBase.+ (dart:core-patch/string_patch.dart:265:57) #1 _HomePageScreenState._greetings (package:ican/Screens/homePageScreen.dart:237:19) #2 _HomePageScreenState.build (package:ican/Screens/homePageScreen.dart:75:17) #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27) #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15) ...
答案 0 :(得分:0)
嗨,伙计们,我只是解决了这个问题,我只是重建了整个HomePageScreen并用相同的小部件填充了全状态屏幕,然后我重新运行了它,错误消失了,我不知道为什么要这样做了