这是我的signup.dart文件代码:
什么都没有显示出像错误一样的东西。 但是,只是我希望看到在textfield下显示错误,但是它什么也没有显示。 谁能说我做错了吗?
import 'package:flutter/material.dart';
class SignupPage extends StatefulWidget {
@override
_SignupPageState createState() => _SignupPageState();
}
class _SignupPageState extends State<SignupPage> {
final formkey = new GlobalKey<FormState>();
registered() {
print("validation form...$formkey");
}
@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
Widget>[
Container(
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(15.0, 110.0, 0.0, 0.0),
child: Text(
'Qeydiyyat',
style:
TextStyle(fontSize: 60.0, fontWeight: FontWeight.bold),
),
),
],
),
),
SizedBox(height: 30.0),
Container(
padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
child: Form(
key: formkey,
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'E-Poçt',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
// hintText: 'EMAIL',
// hintStyle: ,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
validator: (val) {
return "sea";
},
),
SizedBox(height: 10.0),
TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: 'Şifrə ',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
obscureText: true,
validator: (val) {
return "sea";
},
),
SizedBox(height: 10.0),
TextFormField(
decoration: InputDecoration(
labelText: 'Ad Soyad',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green))),
validator: (val) {
return "sea";
},
),
SizedBox(height: 50.0),
Container(
height: 40.0,
child: RaisedButton(
color: Colors.blue,
onPressed: registered,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(50),
),
child: Center(
child: Text(
'Qeydiyyat',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
)),
SizedBox(height: 20.0),
Container(
height: 40.0,
child: RaisedButton(
color: Colors.red,
disabledColor: Colors.transparent,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(50),
),
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Center(
child: Text('Daxil ol',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat')),
),
),
),
),
],
),
)),
]));
}
}
什么都没有显示出像错误一样的东西。 但是,只是我希望看到在textfield下显示错误,但是它什么也没有显示。 谁能说我做错了吗?
答案 0 :(得分:2)
如果要进行验证工作,请自动将TextField的autoValidate属性设置为true。否则,如果您想在事件发生后进行验证(例如单击按钮),则可以调用validate()方法。您的register方法可以更改为以下形式:
registered() {
if (formKey.currentState.validate()) {
//do something
}
}