- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我将我的应用程序打开到登录屏幕时,屏幕工作正常但没有发生任何事情,现在,当我单击注册按钮并尝试单击返回登录时,出现此错误
======== Exception caught by widgets library =======================================================
The following assertion was thrown building Form-[LabeledGlobalKey<FormState>#d062b](state: FormState#ba10e):
'package:flutter/src/widgets/will_pop_scope.dart': Failed assertion: line 61 pos 12: '_route == ModalRoute.of(context)': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
The relevant error-causing widget was:
Form-[LabeledGlobalKey<FormState>#d062b] file:///C:/Users/Dell%20Latitude/AndroidStudioProjects/handyman_client/lib/screens/home_page.dart:61:65
When the exception was thrown, this was the stack:
#2 _WillPopScopeState.didUpdateWidget (package:flutter/src/widgets/will_pop_scope.dart:61:12)
#3 StatefulElement.update (package:flutter/src/widgets/framework.dart:4815:58)
#4 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
#5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
#6 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
...
====================================================================================================
======== Exception caught by widgets library =======================================================
Duplicate GlobalKey detected in widget tree.
====================================================================================================
在查看它之后,我看到它来 self 的表单小部件这是我的代码:但请注意表单小部件
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:handyman_client/models/login_model.dart';
import 'package:provider/provider.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.only(top: 50),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset("assests/images/onboarding1.png", width: 80, height: 80,),
Container(
margin: EdgeInsets.only(top: 50),
child: AutoSizeText(
"HANDYMAN",
style: TextStyle(
color: Color(0xFF2AF219),
fontSize: 14,
fontFamily: 'Ramabhadra',
fontWeight: FontWeight.w900
),
)
)
],
),
SizedBox(height: 20,),
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Consumer<LoginModel>(
builder: (context, mLoginValue, child) => Form(
key: mLoginValue.formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AutoSizeText(
"Hire skilled handy workers that lives in you area",
maxLines: 3,
style: TextStyle(
color: Color(0xFF2AF219),
fontSize: 25,
fontFamily: 'Ramabhadra',
fontWeight: FontWeight.w900
),
),
SizedBox(height: 12,),
AutoSizeText(
"Sign In",
maxLines: 2,
style: TextStyle(
color: Color(0xFFC4C4C4),
fontFamily: 'Ramabhadra',
fontSize: 24
),
),
SizedBox(height: 10,),
AutoSizeText(
"Email",
style: TextStyle(
color: Color(0xFF2AF219),
fontFamily: 'Ramabhadra',
),
),
SizedBox(height: 10,),
Container(
padding: EdgeInsets.only(left: 16.0),
height: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.0),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(6, 2),
blurRadius: 6.0,
spreadRadius: 3.0
)
]
),
child: TextFormField(
validator: (v) => mLoginValue.validateEmail(v),
controller: mLoginValue.emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "email@mail.com",
hintStyle: TextStyle(
color: Color(0xFFC4C4C4),
fontFamily: 'Ramabhadra',
)
),
),
),
SizedBox(height: 12,),
AutoSizeText(
"Password",
style: TextStyle(
color: Color(0xFF2AF219),
fontFamily: 'Ramabhadra',
),
),
SizedBox(height: 10,),
Container(
padding: EdgeInsets.only(left: 16.0),
height: 50,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16.0),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(6, 2),
blurRadius: 6.0,
spreadRadius: 3.0
)
]
),
child: TextFormField(
controller: mLoginValue.passwordController,
validator: (v) => mLoginValue.validatePassword(v),
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "password",
hintStyle: TextStyle(
color: Color(0xFFC4C4C4),
fontFamily: 'Ramabhadra',
)
),
),
),
],
),
),
),
),
SizedBox(height: 15,),
Container(
margin: EdgeInsets.only(left: 180),
child: FlatButton(
onPressed: (){
Navigator.pushNamed(context, '/forgotPassword');
},
child: AutoSizeText(
"Forgot Password",
style: TextStyle(
color: Color(0xFFC4C4C4),
fontFamily: 'Ramabhadra',
),
),
),
),
SizedBox(height: 20,),
Container(
child: Consumer<LoginModel>(
builder: (context, mLoginValue, child) => InkWell(
onTap: () async {
mLoginValue.createLogin();
if(mLoginValue.isVerified){
Navigator.pushNamed(context, '/profileImageScreen');
}
},
child: CircleAvatar(
radius: 28.93,
backgroundColor: Colors.black,
foregroundColor: Colors.white,
child: Icon(Icons.arrow_forward),
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AutoSizeText(
"Don't have account?",
style: TextStyle(
color: Color(0xFF464444),
fontFamily: 'Ramabhadra',
fontSize: 11
),
),
FlatButton(
onPressed: (){
Navigator.pushNamed(context, '/clientSignUp');
},
child: AutoSizeText(
"Click Here",
style: TextStyle(
color: Color(0xFF2AF219),
fontFamily: 'Ramabhadra',
fontSize: 11,
fontWeight: FontWeight.bold
),
)
)
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AutoSizeText(
"For more information visit",
style: TextStyle(
color: Color(0xFF464444),
fontFamily: 'Ramabhadra',
fontSize: 11
),
),
SizedBox(height: 50,),
FlatButton(
onPressed: (){},
child: AutoSizeText(
"www.handyman.com",
style: TextStyle(
color: Color(0xFF2AF219),
fontFamily: 'Ramabhadra',
fontSize: 11,
fontWeight: FontWeight.bold
),
)
)
],
)
]
)
),
),
);
}
}
我还使用了供应商这是代码:
import 'package:flutter/cupertino.dart';
import 'package:handyman_client/signUp_Validation/validate.dart';
class LoginModel extends ChangeNotifier with ValidationMixin {
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
final formKey = GlobalKey<FormState>();
String _message = "";
bool _isVerified = false;
set message(msg) {
_message = msg;
notifyListeners();
}
get message {
return this._message;
}
set isVerified(bool verified) {
_isVerified = verified;
notifyListeners();
}
get isVerified {
return this._isVerified;
}
Future<void> createLogin() {
if (validateForm()) {
emailController.text;
passwordController.text;
isVerified = true;
}else {
message = "Please fill the form";
isVerified = false;
}
notifyListeners();
}
bool validateForm() {
return formKey.currentState.validate();
}
}
请问我该如何解决?
最佳答案
改变这个
final formKey = GlobalKey<FormState>();
到
GlobalKey<FormState> formKey = GlobalKey<FormState>();
关于flutter - '_route == ModalRoute.of(context)' : is not true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66510535/
为了在 flutter 中获得类似模态的效果(当页面被推到当前页面的顶部时,背景为黑色并且足够透明,以便您可以在背景中看到后面的页面)。 我正在使用 ModalRoute 类在我当前页面的顶部显示一个
每次我调用 modalroute 以从命名路由中检索参数时,我都会得到 null。 这是代码片段: Navigator.pushNamed( context,
我用 flutter 编写了一个应用程序。我想更改字符串变量的状态。在我设置字符串变量的状态后,ModalRoute PopUpMenu 不显示更改的变量。如果我关闭 ModalRoute PopUp
在下面实现的代码中,我可以在页面底部显示带有 Fade 动画的对话框,现在,我想将 SlideTransition 添加到 ModalRoute这个实现从底部滑动对话框,但我不能那样做 例如,我想要的
当我将我的应用程序打开到登录屏幕时,屏幕工作正常但没有发生任何事情,现在,当我单击注册按钮并尝试单击返回登录时,出现此错误 ======== Exception caught by widge
我对 flutter 感到困惑,当我想从 statefulwidget (initstate) 读取参数并将其访问到小部件构建中时,该变量仍然为空。如何正确阅读?我的代码如下: import 'pac
在任何给定情况下是否有任何理由使用一个而不是另一个?我试图弄清楚为什么有两种方法可以做到这一点。我指的是“带参数导航”食谱食谱: https://flutter.dev/docs/cookbook/n
最近我正在迁移到空安全。更新了 firebase_analytics:^8.0.2。 现在面临 this.observer.subscribe(this, ModalRoute.of(context)
在我的应用程序中单击一个按钮会打开一个弹出窗口。单击该按钮一次,然后它工作正常,但是每当我连续单击该按钮 2 3 次时,就会出现下面给出的错误。 我收到此错误。 flutter: ══════════
我正在使用 Getx 状态管理。我有一个登录屏幕及其 GetxController。在那个 GetxController 中,我定义了一个像这样的 FormKey final formKey = Gl
我是一名优秀的程序员,十分优秀!