问题描述
我正在尝试将用于日期选择器的 TextField 和 IconButton 放在一起,并决定使用 SizedBox 来做到这一点。我希望他们肩并肩。
我使用了一个带有 SizedBox 的容器,并将添加 TextField 和 IconButton 作为子项。但是,当我这样做时,我在“children:”上遇到错误。我做错了什么?
Container(
alignment: Alignment.centerLeft,child:
SizedBox(
height: 50.0,width: 150,children: <Widget>[ <<<<<<< This is where the error is
TextField(
keyboardType: TextInputType.text,controller: contractDateController,textAlign: TextAlign.center,onChanged: (value) {
trxnProvider.changecontractDate(value); //,loggedInUid);
},decoration:
kTextFielddecoration.copyWith(
hintText: 'Contract Date',labelText: 'Contract Date'),),IconButton(onpressed: () {_selectDate(context);},icon: Icon(Icons.calendar_today)),],
解决方法
SizedBox() 没有“孩子”,它只能带一个“孩子”,并且将两个小部件并排放置,您可以将 SizedBox() 的孩子属性设为 Row() 并在该行内放置 TextField和图标按钮
Container(
alignment: Alignment.centerLeft,child: SizedBox(
height: 50.0,width: 150,child: Row(
children: [
TextField(
keyboardType: TextInputType.text,controller: contractDateController,textAlign: TextAlign.center,onChanged: (value) {
trxnProvider.changecontractDate(value); //,loggedInUid);
},decoration: kTextFieldDecoration.copyWith(
hintText: 'Contract Date',labelText: 'Contract Date'),),IconButton(
onPressed: () {
_selectDate(context);
},icon: Icon(Icons.calendar_today)),],