如果我访问“添加图书”窗口,而不是文本字段只是空白页,则元素的层次结构会出现问题,因为 atm 会出现白屏。 我确实收到了这些错误:
也许有人可以解释我在做什么错误以更好地理解它。提前致谢!
@override
Widget build(BuildContext context) {
return Scaffold(
//resizeToAvoidBottomPadding: false,
appBar: AppBar(title: Text("Add book")),
body: Container(
child: Form(
key: _formKey,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
// Book name
Padding(
padding: EdgeInsets.all(20.0),
child: Container(
//height: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
//alignment: Alignment.center,
child: Container(
padding: const EdgeInsets.only(
top: 10, bottom: 10, left: 20, right: 20),
decoration: new BoxDecoration(
color: Color(0x70487bea),
borderRadius:
new BorderRadius.all(Radius.circular(30))),
child: TextFormField(
controller: nameController,
decoration: InputDecoration(
border: InputBorder.none,
hintText: " Write name",
hintStyle: TextStyle(color: Colors.grey[900]),
),
),
),
),
),
// Author
Padding(
padding: EdgeInsets.all(20.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
//alignment: Alignment.center,
child: Container(
padding: const EdgeInsets.only(
top: 10, bottom: 10, left: 20, right: 20),
decoration: new BoxDecoration(
color: Color(0x70487bea),
borderRadius:
new BorderRadius.all(Radius.circular(30))),
child: TextFormField(
controller: authorController,
decoration: InputDecoration(
border: InputBorder.none,
hintText: " Write name",
hintStyle: TextStyle(color: Colors.grey[900]),
),
),
),
),
),
// Category
Padding(
padding: EdgeInsets.all(20.0),
child: DropdownButtonFormField(
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
decoration: InputDecoration(
labelText: "Choose category",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
//alignment: Alignment.center,
items: listOfCategories.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
),
),
//temp placement
// Submit
Flexible(
child: Padding(
padding: EdgeInsets.all(20.0),
child: isLoading
? CircularProgressIndicator()
: Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.symmetric(vertical: 10),
child: RaisedButton(
onPressed: () {
if (_formKey.currentState.validate()) {
setState(() {
isLoading = true;
});
//getUsername();
addToFb();
//dispose();
}
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
side: BorderSide(color: Colors.indigo[500])),
color: Colors.indigo[400],
child: Text(
"Save",
style: TextStyle(
fontSize: 16.0, color: Colors.white),
),
padding: EdgeInsets.fromLTRB(35, 15, 35, 15),
),
...
答案 0 :(得分:1)
试试这个:
(将您的小部件放在 Column
下的 Form
中)
Scaffold(
appBar: AppBar(title:
Text("Add book"),
),
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(...),
),
),
),