从TextinputType.text移到TextInputType.number数据会自动删除。
class _StudentDetailsState extends State<StudentDetails> {
TextEditingController adminNum,
rollNum,
nameOfstudent,
dob,
caste,
bloodGroup,
mobileNum,
eMailId;
var _formkey;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Student'),
),
body:
ListView(
padding: EdgeInsets.all(15.0),
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: adminNum = new TextEditingController(),
key: Key('Admn_Num'),
autofocus: true,
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'Admission Number',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: rollNum = new TextEditingController(),
key: Key('RollNo'),
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'RollNo',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: nameOfstudent = new TextEditingController(),
key: Key('Name_of_Student'),
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'Name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: dob = new TextEditingController(),
key: Key('DOB'),
keyboardType: TextInputType.datetime,
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'DOB',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: caste = new TextEditingController(),
key: Key('Caste'),
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'Caste (With FullName)',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: bloodGroup = new TextEditingController(),
key: Key('Blood_Group'),
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'Blood Group',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: mobileNum = new TextEditingController(),
key: Key('Mobile_Num'),
keyboardType: TextInputType.phone,
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'Mobile Number',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Padding(
padding: EdgeInsets.only(top: 15.0, bottom: 15.0),
child: TextField(
controller: eMailId = new TextEditingController(),
key: Key('Mail_Id'),
keyboardType: TextInputType.emailAddress,
// onChanged: (value){},
decoration: InputDecoration(
labelText: 'E-Mail Id',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
)),
),
),
Center(
child: ButtonTheme(
minWidth: 100.0,
child: OutlineButton(
padding: EdgeInsets.only(left: 25, right: 25),
child: Text('Submit'),
textTheme: ButtonTextTheme.primary,
onPressed: () {},
),
),
)
],
));
}
}
问题是,当我在“名称”文本字段中输入具有TextInputType.text的内容,然后点击另一个具有TextInputType.number的文本字段时,“名称”字段会被清除,没有明显的原因