flutter - DropdownButtonFormField 不显示选择颤振的值
问题描述
这是我的代码,我试图在控制台中打印该值,以确定它是否有效并且打印正确,但它没有显示在 Filed 文本中。当我选择提示文本消失但没有任何显示时,我更改了图标(箭头)的大小,但是当我点击它的任何部分时,直到我点击角落没有响应
String _medicationDesc;
List<DropdownMenuItem> getDropDownItem() {
List<DropdownMenuItem> dropDownItems = [];
for (String dose in medcationDose) {
var newItem = DropdownMenuItem(
child: Text(
dose,
style: textStyle1,
),
value: dose,
);
dropDownItems.add(newItem);
}
return dropDownItems;
}
List<String> medcationDose = [
'مرة واحدة في اليوم',
'مرتان في اليوم',
'ثلاث مرات في اليوم',
'اربعة مرات في اليوم',
'وقت الحاجة'
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: nave),
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.fromLTRB(0.0, 30, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
SizedBox(
height: 50,
width: 350,
child: DropdownButtonFormField(
value: _medicationDose,
items: getDropDownItem(),
iconSize: 50,
iconEnabledColor: white,
onChanged: (value) {
setState(() {
_medicationDose = value;
});
},
decoration: InputDecoration(
hintText: 'الجرعة',
),
),
解决方案
试试这个
List<String> languageList = ['EN', 'ES', 'FR'];
var selectedValue;
DropdownButtonHideUnderline(
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.transparent))),
dropdownColor: CustomColors.black,
value:
selectedValue == null ? languageList[0] : selectedValue,
style: robotoStyle(
color: CustomColors.white,
fontSize: 10),
icon: Icon(
Icons.keyboard_arrow_down,
color: CustomColors.white,
),
isExpanded: true,
items: languageList.map((item) {
return DropdownMenuItem<String>(
value: item,
child: new Text(item,
style: robotoStyle(
color: CustomColors.white,
fontSize: 10)),
);
}).toList(),
onChanged: (value) {
selectedValue = value;
S.load(Locale(selectedValue));
print(selectedValue);
},
),
)
推荐阅读
- excel - 将当前搜索中的数据导出到 Laravel 中的 excel 中?
- csv - 如何使用 nifi 更新 csv 上特定字段的值?
- c++ - 如何从 sh 脚本中获取`wget`的返回值到`int`变量中
- eclipse - 由于 NoClassDefFoundError:TestEngine,Junit 5 测试无法在 Eclipse 中启动
- objective-c - 为什么在图标上实现的徽章不清晰可见。我想在图标上清楚地显示徽章并在图标上显示徽章计数
- xamarin.forms - 是什么导致选项卡式页面 XAML 文件的 Xamarin 表单中的 android 预览错误?
- karma-jasmine - 如何在 Angular 的茉莉花单元测试中模拟 translateservice
- python - 在键值迭代中从 json 中删除引号
- java - Docker 日志挂载文件夹未同步
- java - ClientAbortException:java.net.SocketException:jboss 服务器上间歇性地出现连接重置错误