Flutter Renderflex问题
Flutter Renderflexproblem
我的屏幕上有几个文本字段和按钮,但最后有很多未使用的 space。当我输入一个文本框来输入文本时,有一个 renderflexproblem...可能是因为键盘从底部升起。
我尝试对最后一个按钮使用“展开”,但这会将按钮展开到屏幕底部,并且仍然会出现 renderflex 问题。
我想使用屏幕的全尺寸,即使键盘从底部升起
这是我的代码:
body: Container(
margin: EdgeInsets.all(15.0),
alignment: Alignment.centerLeft,
child: Column(
children: <Widget>[
TextField(
controller: _todoNameController,
decoration: InputDecoration(labelText: 'Todoname'),
),
Padding(padding: new EdgeInsets.all(5.0)),
TextField(
controller: _jobController,
decoration: InputDecoration(labelText: 'Job'),
),
Padding(padding: new EdgeInsets.all(5.0)),
TextField(
controller: _priorityController,
decoration: InputDecoration(labelText: 'Priority'),
),
Padding(padding: new EdgeInsets.all(5.0)),
DropdownButton<String>(
items: teamList.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: Row(
children: <Widget>[
SizedBox(width: 10,),
Text(value),
]
)
);
}).toList(),
hint: Text("Choose team"),
value: selectedTeam,
onChanged: (value) {
setState(() {
_teamController.text = value;
selectedTeam = value;
});
},
),
Padding(padding: new EdgeInsets.all(5.0)),
TextField(
controller: _noteController,
decoration: InputDecoration(labelText: 'Note'),
),
Padding(padding: new EdgeInsets.all(5.0)),
Row(
children: <Widget>[
Expanded(
// child: Text(
// db.formatMsIntoString(int.parse(_startingDateController.text)).substring(0, 10)),
child: TextField(
controller: _startingDateController,
decoration: InputDecoration(labelText: 'Starting date'),
enabled: false,
),
),
Expanded(
child: RaisedButton(
onPressed: () => _selectStartingDate(context),
child: Text(
'Select starting date',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
color: Colors.teal,
),
),
],
),
Padding(padding: new EdgeInsets.all(5.0)),
Row(
children: <Widget>[
Expanded(
// child: Text(
// db.formatMsIntoString(int.parse(_startingDateController.text)).substring(0, 10)),
child: TextField(
controller: _endingDateController,
decoration: InputDecoration(labelText: 'Ending date'),
enabled: false,
),
),
Expanded(
child: RaisedButton(
onPressed: () => _selectEndingDate(context),
child: Text(
'Select ending date',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
color: Colors.teal,
),
),
],
),
Padding(padding: new EdgeInsets.all(5.0)),
RaisedButton(
child: (widget.todo.id != null) ? Text('Update') : Text('Add'),
onPressed: () {
if (widget.todo.id != null) {
db.updateTodo(Todo.fromMap({
'id': widget.todo.id,
'todoName': _todoNameController.text,
'job': _jobController.text,
'priority': _priorityController.text,
'team': _teamController.text,
'note': _noteController.text,
'startingDate': db.formatStringIntoMs(selectedStartingDate.toString()),
'endingDate': db.formatStringIntoMs(selectedEndingDate.toString()),
})).then((_) {
Navigator.pop(context, 'update');
});
}else {
db.saveTodo(Todo(_todoNameController.text,
_jobController.text,
_priorityController.text,
_teamController.text,
_noteController.text,
db.formatStringIntoMs(selectedStartingDate.toString()),
db.formatStringIntoMs(selectedEndingDate.toString()))).then((_) {
Navigator.pop(context, 'save');
});
}
},
),
],
),
),
您必须滚动,因为它不适合页面。如果滚动整个页面,它应该会修复。展开后,您不必将其包裹起来。在已经很常规的代码编写逻辑中使用 expanded on scroll pages 是对设计的一种呼喊。它可能会导致错误。模范:
SingleChildScrollView(
child:Column(
children:[
....
...
我的屏幕上有几个文本字段和按钮,但最后有很多未使用的 space。当我输入一个文本框来输入文本时,有一个 renderflexproblem...可能是因为键盘从底部升起。 我尝试对最后一个按钮使用“展开”,但这会将按钮展开到屏幕底部,并且仍然会出现 renderflex 问题。 我想使用屏幕的全尺寸,即使键盘从底部升起
这是我的代码:
body: Container(
margin: EdgeInsets.all(15.0),
alignment: Alignment.centerLeft,
child: Column(
children: <Widget>[
TextField(
controller: _todoNameController,
decoration: InputDecoration(labelText: 'Todoname'),
),
Padding(padding: new EdgeInsets.all(5.0)),
TextField(
controller: _jobController,
decoration: InputDecoration(labelText: 'Job'),
),
Padding(padding: new EdgeInsets.all(5.0)),
TextField(
controller: _priorityController,
decoration: InputDecoration(labelText: 'Priority'),
),
Padding(padding: new EdgeInsets.all(5.0)),
DropdownButton<String>(
items: teamList.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: Row(
children: <Widget>[
SizedBox(width: 10,),
Text(value),
]
)
);
}).toList(),
hint: Text("Choose team"),
value: selectedTeam,
onChanged: (value) {
setState(() {
_teamController.text = value;
selectedTeam = value;
});
},
),
Padding(padding: new EdgeInsets.all(5.0)),
TextField(
controller: _noteController,
decoration: InputDecoration(labelText: 'Note'),
),
Padding(padding: new EdgeInsets.all(5.0)),
Row(
children: <Widget>[
Expanded(
// child: Text(
// db.formatMsIntoString(int.parse(_startingDateController.text)).substring(0, 10)),
child: TextField(
controller: _startingDateController,
decoration: InputDecoration(labelText: 'Starting date'),
enabled: false,
),
),
Expanded(
child: RaisedButton(
onPressed: () => _selectStartingDate(context),
child: Text(
'Select starting date',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
color: Colors.teal,
),
),
],
),
Padding(padding: new EdgeInsets.all(5.0)),
Row(
children: <Widget>[
Expanded(
// child: Text(
// db.formatMsIntoString(int.parse(_startingDateController.text)).substring(0, 10)),
child: TextField(
controller: _endingDateController,
decoration: InputDecoration(labelText: 'Ending date'),
enabled: false,
),
),
Expanded(
child: RaisedButton(
onPressed: () => _selectEndingDate(context),
child: Text(
'Select ending date',
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
color: Colors.teal,
),
),
],
),
Padding(padding: new EdgeInsets.all(5.0)),
RaisedButton(
child: (widget.todo.id != null) ? Text('Update') : Text('Add'),
onPressed: () {
if (widget.todo.id != null) {
db.updateTodo(Todo.fromMap({
'id': widget.todo.id,
'todoName': _todoNameController.text,
'job': _jobController.text,
'priority': _priorityController.text,
'team': _teamController.text,
'note': _noteController.text,
'startingDate': db.formatStringIntoMs(selectedStartingDate.toString()),
'endingDate': db.formatStringIntoMs(selectedEndingDate.toString()),
})).then((_) {
Navigator.pop(context, 'update');
});
}else {
db.saveTodo(Todo(_todoNameController.text,
_jobController.text,
_priorityController.text,
_teamController.text,
_noteController.text,
db.formatStringIntoMs(selectedStartingDate.toString()),
db.formatStringIntoMs(selectedEndingDate.toString()))).then((_) {
Navigator.pop(context, 'save');
});
}
},
),
],
),
),
您必须滚动,因为它不适合页面。如果滚动整个页面,它应该会修复。展开后,您不必将其包裹起来。在已经很常规的代码编写逻辑中使用 expanded on scroll pages 是对设计的一种呼喊。它可能会导致错误。模范:
SingleChildScrollView(
child:Column(
children:[
....
...