gpt4 book ai didi

flutter - 通过DropdownButton在正确的类别上显示文本字段

转载 作者:行者123 更新时间:2023-12-03 03:35:22 28 4
gpt4 key购买 nike

仅当在我的下拉按钮中选择选项之一时,如何显示我的窗口小部件?

我试试这个:

  showWidgetOnCategory() async {
if(_selectedCategory == 'FREE'){
_buildCountPerson();
}
}

Widget _dropdownCategory(){
return Padding(
padding: EdgeInsets.only(left:0),
child: DropdownButton(
isExpanded: true,
hint: Text('Type', style: TextStyle(color: Colors.grey.shade300),),
value: _selectedCategory,

onChanged: (newValue){
setState(() async {
_selectedCategory = newValue;
});
},
items: _categories.map((category){
return DropdownMenuItem(
child: new Text(category, style: TextStyle(color: Colors.black),),
value: category,
);
}).toList(),
)
);
}


_buildCountPerson(){
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Container(
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 15),
child: Text('Liczba miejsc:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
)),
SizedBox(
width: 120,
height: 50,
child: TextFormField(
keyboardType: TextInputType.number,
controller: _countPersonOnEventController,
decoration: InputDecoration(
hintText: '0',
border: new OutlineInputBorder(
borderSide: new BorderSide(color: Colors.teal)
),
),
validator: (String value) {
if(value.isEmpty){
return 'Pole wymagane';
}else return null;
},
onSaved: (String value) {
_count = int.parse(value);
print(_count);
},
)
)

],
));
}

但是不行
有谁知道如何帮助我吗?

//////////////////////////////////////////////////// //////////////////////////////////////////////////// //////////////////////////////////////////////////// ///////////////////////////////////////

最佳答案

您可以先使用boolean droDownSelected = false,然后在DropDown的onChanged方法中将其设置为true,以便可以显示其他小部件。您可以通过以下方式按条件显示小部件。

bool droDownSelected = false;

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
DropdownButton(), // in onChanged method setState droDownSelected to true so below widget is shown
droDownSelected ? WidgetYouWantToShow() : SizedBox(),
],
);
}

关于flutter - 通过DropdownButton在正确的类别上显示文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61367477/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com