Android 颤振形式:方法&x27;验证';在null上调用了。[所有配置都已配置]
请帮帮我!我正在创建一个简单的登录页面,但出现了如下异常: ══╡ WIDGETS库捕获到异常╞════════════════ [+3s] I/flatter(11275):抛出以下NoSuchMethodError 构建登录筛选(脏,依赖项:[MediaQuery]):[] I/flatter(11275):对null调用了“validate”方法。[Android 颤振形式:方法&x27;验证';在null上调用了。[所有配置都已配置],android,flutter,dart,mobile,Android,Flutter,Dart,Mobile,请帮帮我!我正在创建一个简单的登录页面,但出现了如下异常: ══╡ WIDGETS库捕获到异常╞════════════════ [+3s] I/flatter(11275):抛出以下NoSuchMethodError 构建登录筛选(脏,依赖项:[MediaQuery]):[] I/flatter(11275):对null调用了“validate”方法。[ ]I/颤振(11275):接收器:空[]I/颤振(11275): 已尝试调用:validate()[]I/flatter(11275):[]
]I/颤振(11275):接收器:空[]I/颤振(11275): 已尝试调用:validate()[]I/flatter(11275):[] I/flatter(11275):导致错误的相关小部件是:[] I/颤振(11275):登录屏幕 虽然我认为,我已经配置了所有需要的配置。但不知何故,我的代码引发了异常。如何修复它 这是我的密码:
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:my_app/services/UserService.dart';
/*
* This is login screen view.
*
* If you want to edit form section for example email and password fields, just edit these below functions.
* - _formEmailWidget()
* - _formPasswordWidget()
* If you want to edit social login section, just edit _socialLoginWidget() function.
* If you want to edit or change logo, just edit _logoWidget() function.
*/
class LoginScreen extends StatelessWidget {
static final Pattern _pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
final GlobalKey<FormState> _key = GlobalKey<FormState>();
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final UserAuth _auth = UserAuth.instance();
final Status status;
LoginScreen({@required this.status});
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: SafeArea(child: this._bodyWidgets(context)));
}
_logoWidget() {
return Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 50.0),
child: Image(image: AssetImage('assets/images/logo.png')));
}
_formEmailWidget() {
return Container(
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: Colors.white, width: 1.0))),
child: TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
validator: (String value) {
RegExp regex = new RegExp(_pattern);
if (regex.hasMatch(value)) {
return null;
}
return "Please, Enter valid e-mail";
},
decoration: const InputDecoration(
icon: Icon(
FontAwesome.user,
color: Colors.white,
),
fillColor: Colors.white,
hintStyle: TextStyle(
color: Colors.white,
fontFamily: 'ProximaThin',
),
hintText: 'Your e-mail'),
));
}
_formPasswordWidget() {
return Container(
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: Colors.white, width: 1.0))),
child: TextFormField(
controller: _passwordController,
validator: (String value) {
if (value.isEmpty || value.length < 6) {
return "Password must be more than 6 characters";
}
return null;
},
decoration: const InputDecoration(
icon: Icon(
FontAwesome.key,
color: Colors.white,
),
fillColor: Colors.white,
hintStyle: TextStyle(
color: Colors.white,
fontFamily: 'ProximaThin',
),
hintText: 'Your password'),
obscureText: true,
));
}
_submitRowWidget() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: null,
child: Text(
'forget password?',
style: TextStyle(color: Colors.white),
),
),
OutlineButton(
textColor: Colors.white,
highlightedBorderColor: Colors.white,
borderSide: BorderSide(
color: Colors.white, width: 0.8, style: BorderStyle.solid),
shape: OutlineInputBorder(borderRadius: BorderRadius.circular(10.0)),
onPressed: _loginAction(),
child: Text(
'Login',
style: TextStyle(color: Colors.white),
),
)
],
);
}
_loginAction() {
if (_key.currentState.validate()) {
_auth.signIn(_emailController.text, _passwordController.text);
} else {
AlertDialog(
content: Text(
"Your e-mail or password doesn't match, Would you like create an account?"),
elevation: 24.0,
shape: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
actions: <Widget>[
FlatButton(
onPressed: null,
child: Text("Yes"),
)
],
);
}
}
_socialLoginWidget() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: FlatButton(
padding: const EdgeInsets.only(
left: 10.0, top: 0.0, bottom: 0.0, right: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(FontAwesome.facebook_f, color: Colors.black),
SizedBox(
width: 10,
),
Text('Facebook',
style: TextStyle(
fontFamily: 'Proxima',
fontSize: 11,
color: Colors.black))
],
),
onPressed: null,
),
),
Container(
width: 100,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: FlatButton(
padding: const EdgeInsets.only(
left: 10.0, top: 0.0, bottom: 0.0, right: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
FontAwesome.google,
color: Colors.black,
),
SizedBox(
width: 10,
),
Text(
'Google',
style: TextStyle(
fontFamily: 'Proxima', fontSize: 11, color: Colors.black),
)
],
),
onPressed: null,
),
)
],
);
}
_bodyWidgets(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_logoWidget(),
Expanded(
child: Center(
child: Container(
width: MediaQuery.of(context).size.width - 20,
decoration: BoxDecoration(
color: Colors.black,
boxShadow: [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.35),
blurRadius: 15.0,
offset: Offset(0, -5))
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: Padding(
padding:
const EdgeInsets.only(top: 45.0, left: 45.0, right: 45.0),
child: Column(children: <Widget>[
Form(
key: this._key,
child: Column(
children: <Widget>[
_formEmailWidget(),
_formPasswordWidget(),
SizedBox(
height: 15.0,
),
_submitRowWidget()
],
),
),
SizedBox(
height: 45,
),
Text('or connect using',
style: TextStyle(
fontFamily: 'ProximaThin', color: Colors.white)),
SizedBox(
height: 15,
),
_socialLoginWidget(),
SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Don\'t have an account?',
style: TextStyle(
fontFamily: 'ProximaThin', color: Colors.white),
),
SizedBox(
width: 5,
),
InkWell(
onTap: null,
child: Text('Sign up',
style: TextStyle(
fontFamily: 'Proxima', color: Colors.white)),
)
],
)
]),
),
),
))
]);
}
}
导入“包装:颤振/材料.省道”;
导入“包:颤振图标/颤振图标.dart”;
导入“package:my_app/services/UserService.dart”;
/*
*这是登录屏幕视图。
*
*如果您想编辑表单部分,例如电子邮件和密码字段,只需编辑以下功能。
*-(u formEmailWidget)
*-(u formPasswordWidget)
*如果您想编辑社交登录部分,只需编辑_socialwinwidget()函数即可。
*如果要编辑或更改徽标,只需编辑_logoWidget()函数即可。
*/
类LoginScreen扩展了无状态小部件{
静态最终模式=
r'^([^()[\]\\,;:\s@']+(\.[^()[\]\,;:\s@']+*))(\[[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[1,3}.[0-9]{1,3}.]124;([a-zA Z-0-9]{a-zA Z]++$){2};
最终全局键=全局键();
final TextEditingController_emailController=TextEditingController();
最终文本编辑控制器_passwordController=文本编辑控制器();
final UserAuth_auth=UserAuth.instance();
最后地位;
LoginScreen({@required this.status});
@凌驾
小部件构建(构建上下文){
返回脚手架(
resizeToAvoidBottomPadding:false,
body:SafeArea(子项:this._bodyWidgets(上下文));
}
_logoWidget(){
返回填充(
填充:仅限常量边集(顶部:15.0,底部:50.0),
子项:Image(Image:AssetImage('assets/images/logo.png'));
}
_formEmailWidget(){
返回容器(
装饰:盒子装饰(
边界:
边框(底部:边框边(颜色:Colors.white,宽度:1.0)),
子项:TextFormField(
控制器:\u电子邮件控制器,
键盘类型:TextInputType.emailAddress,
验证器:(字符串值){
RegExp regex=新的RegExp(_模式);
if(regex.hasMatch(值)){
返回null;
}
返回“请输入有效的电子邮件”;
},
装饰:常量输入装饰(
图标:图标(
Fontsome.user,
颜色:颜色,白色,
),
fillColor:Colors.white,
hintStyle:TextStyle(
颜色:颜色,白色,
fontFamily:“ProximaThin”,
),
hintText:“您的电子邮件”),
));
}
_formPasswordWidget(){
返回容器(
装饰:盒子装饰(
边界:
边框(底部:边框边(颜色:Colors.white,宽度:1.0)),
子项:TextFormField(
控制器:_passwordController,
验证器:(字符串值){
if(value.isEmpty | value.length<6){
return“密码必须大于6个字符”;
}
返回null;
},
装饰:常量输入装饰(
图标:图标(
Fontsome.key,
颜色:颜色,白色,
),
fillColor:Colors.white,
hintStyle:TextStyle(
颜色:颜色,白色,
fontFamily:“ProximaThin”,
),
hintText:“您的密码”),
蒙昧文字:对,
));
}
_submitRowWidget(){
返回行(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
墨水池(
onTap:null,
子:文本(
“忘记密码吗?”,
样式:TextStyle(颜色:Colors.white),
),
),
大纲按钮(
textColor:Colors.white,
highlightedBorderColor:Colors.white,
边界边(
颜色:Colors.white,宽度:0.8,样式:BorderStyle.solid),
形状:OutlineInputBorder(borderRadius:borderRadius.circular(10.0)),
onPressed:_loginAction(),
子:文本(
“登录”,
样式:TextStyle(颜色:Colors.white),
),
)
],
);
}
_登录(){
if(_key.currentState.validate()){
_身份验证登录(_emailController.text,_passwordController.text);
}否则{
警报对话框(
内容:文本(
“您的电子邮件或密码不匹配,是否要创建帐户?”),
标高:24.0,
形状:OutlineInputBorder(borderRadius:borderRadius.circular(10)),
行动:[
扁平按钮(
onPressed:null,
子项:文本(“是”),
)
],
);
}
}
_SocialWinWidget(){
返回行(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:borderRadius.all(半径圆形(10)),
),
孩子:扁平按钮(
填充:仅限常量边设置(
左侧:10.0,顶部:0.0,底部:0.0,右侧:10.0),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
图标(FontAwesome.facebook\u f,颜色:Colors.black),
大小盒子(
_submitRowWidget() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: null,
child: Text(
'forget password?',
style: TextStyle(color: Colors.white),
),
),
OutlineButton(
textColor: Colors.white,
highlightedBorderColor: Colors.white,
borderSide: BorderSide(
color: Colors.white, width: 0.8, style: BorderStyle.solid),
shape: OutlineInputBorder(borderRadius: BorderRadius.circular(10.0)),
onPressed: _loginAction,
child: Text(
'Login',
style: TextStyle(color: Colors.white),
),
)
],
);