flutter - 未处理的异常:NoSuchMethodError:在 null 上调用了方法“验证”
问题描述
[错误:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:NoSuchMethodError:在 null 上调用了方法“验证”。E/flutter (6538): 接收者: null E/flutter (6538): 尝试调用: validate() E/flutter (6538): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/颤振(6538):#1 _RegisterState.build。(包:firebasestarter/screens/authenticate/Register.dart:85:47)
import 'package:firebasestarter/screens/authenticate/sign_in.dart';
import 'package:firebasestarter/services/auth.dart';
import 'package:flutter/material.dart';
class Register extends StatefulWidget {
final Function toggleView;
Register({this.toggleView});
@override
_RegisterState createState() => _RegisterState();
}
class _RegisterState extends State<Register> {
final AuthService _auth = AuthService();
final _formKey = GlobalKey<FormState>();
// final formKey = new GlobalKey();
//text field state
String email = '';
String pass = '';
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.brown[100],
appBar: AppBar(
backgroundColor: Colors.brown[400],
elevation: 1,
title: Text("Sign up to Brew Crew"),
actions: <Widget>[
FlatButton.icon(
icon: Icon(Icons.person),
label: Text("Sign-In"),
onPressed: () {
widget.toggleView();
},
)
],
),
body: Container(
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 50),
child: Form(
child: Column(
key: _formKey,
children: <Widget>[
SizedBox(
height: 20,
),
TextFormField(
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
onChanged: (val) {
setState(() => pass = val);
},
),
SizedBox(
height: 20,
),
TextFormField(
validator: (value) {
if (value.length<6) {
return 'longer pass pls';
}
return null;
},
obscureText: true,
onChanged: (val) {
setState(() => email = val);
},
),
SizedBox(
height: 20,
),
RaisedButton(
color: Colors.pink[400],
child: Text(
"Sign up",
style: TextStyle(color: Colors.white),
),
onPressed: () async {
if (_formKey.currentState.validate()) {
// If the form is valid, display a Snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text('Processing Data')));
}
},
)
],
),
)
),
);
}
}
解决方案
推荐阅读
- python-3.x - 更新类中的列表
- php - 无法在 php codeigniter 中设置初始页面
- angular - 如果选中,则在 ion-textarea 中打印复选框的名称。关于离子
- graph - 如何在 Java 中的 DFS 图上搜索站点
- mongodb - MongoDB - 使用聚合更新
- angular - 自定义范围:将 angular-oauth2-oidc 与 Auth0 和 Github 一起使用
- c# - 如何转换任务
要在 BackgroundWorker 中使用 byte[]? - python - 为什么 open("file", "w") 不阻塞?
- c++ - 不期望向量的 C++ 输出元素
- sql - Excel VBA sql查询为一列返回错误值(将值增加1)