我正在与这个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
。
EDIT ********** 这是工作代码
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,
),
],
)
)
),
答案 0 :(得分:0)
我能够重现你的问题,我不知道你为什么要用这种方式构建布局。您正在将DropDownButton
作为child
的{{1}}属性,这很好。但是,由于InputDecorator
溢出DropDownMenuItem
,因此会抛出此错误。换句话说,您不仅在InputDecorator
中包含DopDownButton
,而且您的InputDecorator
也试图包含在同一空间中。因此,Flutter对如何将items
列表放在items
提供的空间内感到困惑。
我真的很困惑你正在尝试构建什么样的布局,为什么需要InputDecorator
和Form
?
可能会为您的设计选择提供一些背景信息,以便我们能够提供更好的帮助。
我使用InputDecorator
和Row
小部件创建了一个更简单的布局,它可能会有所帮助。
TextField