我正在与这个 DropDownItem
框错误作斗争,一切似乎都正常,但在加载时弹出黄色越界。尝试了几件事,但无法解决。我的 Widget
有这段代码。
@override
Widget build(BuildContext context) {
var _children = <Widget>[
!_createNew ? _referrerPractice() : _referrerCreate(),
];
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Column(
mainAxisSize: MainAxisSize.max,
children: _children,
));
}
然后我将其用作函数之一。
Widget _referrerPractice() {
assert(!_createNew);
return new Form(
key: _formKey2,
child: new Expanded(
child: new ListView(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
children: <Widget>[
new InputDecorator(
decoration: const InputDecoration(
labelText: 'Referrer Practice',
hintText: 'Choose Referrer Practice or choose new',
),
isEmpty: _referPractice == null,
child: new DropdownButton<String>(
value: _referPractice,
isDense: true,
onChanged: (String newValue) {
setState(() {
_referPractice = newValue;
});
},
items: practicelist.map((Map value) {
return new DropdownMenuItem<String>(
value: value['id'].toString(),
child: new Text(value['name']),
);
}).toList(),
),
),
new RaisedButton(
child: new Text('Start'), onPressed: _startReferrer),
],
),
),
);
它似乎在另一个页面上工作,我没有使用函数来填充小部件,只是一个常规的小部件变量,但看起来它应该是相同的,因为结构是相同的。
知道我遗漏了什么吗?这是一个 DropDownButton
,但它发生在具有 DropDownButton
以及其他功能的结果页面上。
编辑************ 这是工作代码
final List<String> _allTypeAppt = <String>['Elective OP', 'Hospital Transfer', 'Phone Consult'];
new Form(
key: _formKey,
autovalidate: _autovalidate,
onWillPop: _warnUserAboutInvalidData,
child: new Expanded(
child: new ListView(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
children: <Widget>[
new TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.person),
hintText: 'First Name?',
labelText: 'First Name *',
),
controller: _fnameController,
onSaved: (String value) { referral.fname = value; },
validator: _validateName,
),
new TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.person),
hintText: 'Last Name?',
labelText: 'Last Name *',
),
controller: _lnameController,
onSaved: (String value) { referral.lname = value; },
validator: _validateName,
),
new _DateTimePicker(
labelText: 'DOB',
selectedDate: _fromDate,
selectDate: (DateTime date) {
setState(() {
_fromDate = date;
});
},
),
new TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.phone),
hintText: 'How to contact?',
labelText: 'Phone Number *',
),
controller: _phoneController,
keyboardType: TextInputType.phone,
onSaved: (String value) { referral.contact = value; },
validator: _validatePhoneNumber,
// TextInputFormatters are applied in sequence.
/*inputFormatters: <TextInputFormatter> [
WhitelistingTextInputFormatter.digitsOnly,
// Fit the validating format.
_phoneNumberFormatter,
],*/
),
new TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.phone),
hintText: 'Alt contact?',
labelText: 'Alt Phone Number *',
),
controller: _altPhoneController,
keyboardType: TextInputType.phone,
onSaved: (String value) { referral.altcontact = value; },
validator: _validatePhoneNumber,
// TextInputFormatters are applied in sequence.
/*inputFormatters: <TextInputFormatter> [
WhitelistingTextInputFormatter.digitsOnly,
// Fit the validating format.
_phoneNumberFormatter,
],*/
),
new TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.email),
hintText: 'Patien Email?',
labelText: 'Patient Email *',
),
controller: _emailController,
onSaved: (String value) { referral.altcontact = value; },
//validator: _validatePhoneNumber,
// TextInputFormatters are applied in sequence.
/*inputFormatters: <TextInputFormatter> [
WhitelistingTextInputFormatter.digitsOnly,
// Fit the validating format.
_phoneNumberFormatter,
],*/
),
new TextFormField(
decoration: const InputDecoration(
hintText: 'Tell us about patient',
helperText: 'It does not have to be detailed yet',
labelText: 'Referral Details',
),
controller: _detailsController,
maxLines: 5,
),
new InputDecorator(
decoration: const InputDecoration(
labelText: 'Type of Appointment',
hintText: 'Choose an Appointment Type',
),
isEmpty: _typeAppt == null,
child: new DropdownButton<String>(
value: _typeAppt,
isDense: true,
onChanged: (String newValue) {
setState(() {
_typeAppt = newValue;
});
},
items: _allTypeAppt.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
),
),
new RaisedButton(
child: new Text('Submit Referral'),
onPressed: _submitData,
),
],
)
)
),
最佳答案
我能够重现您的问题,我不确定您为什么要以这种方式构建布局。您正在将 DropDownButton
作为 InputDecorator
的 child
属性,这很好。但是,它会引发此错误,因为 DropDownMenuItem
溢出了您的 InputDecorator
。换句话说,您不仅在 InputDecorator
中包含 DopDownButton
,而且您的 items
也试图包含在与出色地。因此,Flutter 对如何将 items
列表放置在 InputDecorator
提供的空间内感到困惑。
我真的很困惑你正在尝试构建什么样的布局,为什么你需要一个 Form
和一个 InputDecorator
?
也许可以为您的设计选择提供一些背景信息,以便我们提供更好的帮助。
我已经使用 Row
和 TextField
小部件创建了一个更简单的布局,它可能会有帮助。
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _mySelection;
String _text = "Choose";
List<Map> _myJson = [
{"id": "ID 1310012", "name": "Newcommer"}, {"id": "ID 0000TEMP", "name": "Temp"}];
Widget _children() {
TextEditingController _controller = new TextEditingController(text: _text);
return new Expanded(child: new ListView(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
children: <Widget>[
new Container (
child: new Row(
children: <Widget>[
new Expanded(
child: new TextField(
controller: _controller,
),
),
new DropdownButton(
isDense: true,
value: _mySelection,
items: _myJson.map((Map map) {
return new DropdownMenuItem<String>(
value: map["id"],
child: new Text(
map["name"],
),
);
}).toList(),
onChanged: (String newValue) {
setState(() {
_mySelection = newValue;
_text = newValue;
});
})
],),),
new RaisedButton(
child: new Text('Start'), onPressed: null),
]
));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Test")),
body: new Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
_children(),
],
),
);
}
}
关于Flutter RenderIndexedStack 对象在布局期间被赋予无限大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46830812/