Flutter 下拉按钮formfield dosn';t显示选定颤振的值
这是我的代码,我试图在我的控制台中打印该值,以判断它是否有效,是否正确打印,但它没有显示在文本字段中。当我选择“提示文字消失但无任何显示”时,我也更改了图标(箭头)的大小,但当我单击图标的任何部分时,在单击角落之前没有响应Flutter 下拉按钮formfield dosn';t显示选定颤振的值,flutter,Flutter,这是我的代码,我试图在我的控制台中打印该值,以判断它是否有效,是否正确打印,但它没有显示在文本字段中。当我选择“提示文字消失但无任何显示”时,我也更改了图标(箭头)的大小,但当我单击图标的任何部分时,在单击角落之前没有响应 String _medicationDesc; List<DropdownMenuItem> getDropDownItem() { List<DropdownMenuItem> dropDownItems = []; for (String dose
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: 'الجرعة',
),
),
String\u medicationDesc;
列表getDropDownItem(){
列表下拉项=[];
用于(medcationDose中的字符串剂量){
var newItem=DropdownMenuItem(
子:文本(
剂量
样式:textStyle1,
),
数值:剂量,
);
添加(newItem);
}
返回下拉列表项;
}
列表medcationDose=[
'مرة واحدة في اليوم',
'مرتان في اليوم',
'ثلاث مرات في اليوم',
'اربعة مرات في اليوم',
'وقت الحاجة'
];
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(背景颜色:中堂),
正文:SingleChildScrollView(
子:容器(
边距:从LTRB(0.0,30,0,0)开始的边距集,
子:列(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
纵队(
儿童:[
大小盒子(
身高:50,
宽度:350,
子项:DropdownButtonFormField(
值:_药物剂量,
items:getDropDownItem(),
iconSize:50,
iconEnabledColor:白色,
一旦更改:(值){
设置状态(){
_药物剂量=数值;
});
},
装饰:输入装饰(
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);
},
),
)
List languageList=['EN','ES','FR'];
var选择值;
下拉按钮侧下划线(
子项:DropdownButtonFormField(
装饰:输入装饰(
enabledBorder:UnderlineInputBorder(
borderSide:borderSide(颜色:Colors.transparent)),
dropdownColor:CustomColors.black,
价值:
selectedValue==null?语言列表[0]:selectedValue,
风格:机器人风格(
颜色:CustomColors.white,
尺寸:10),,
图标:图标(
图标。键盘箭头向下,
颜色:CustomColors.white,
),
是的,
items:languageList.map((项){
返回下拉菜单项(
价值:项目,,
子项:新文本(项,
风格:机器人风格(
颜色:CustomColors.white,
尺寸:10),,
);
}).toList(),
一旦更改:(值){
selectedValue=值;
S.load(Locale(selectedValue));
打印(选择值);
},
),
)
我为您制作了一个课程,您可以在任何地方调用它,它可能会对您有所帮助
class DropDownClass extends StatelessWidget {
var values;
var hint;
List list = new List();
Color underLineColor;
Color dropDownColor;
Color textColor;
DropDownClass({this.values,
this.list,this.hint,this.underLineColor,this.dropDownColor,this.textColor});
@override
Widget build(BuildContext context) {
return DropdownButtonHideUnderline(
child: DropdownButtonFormField<String>(
value: values,
dropdownColor: dropDownColor??Colors.white,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: underLineColor??Colors.grey[800],
width: 1.0,
),
)
),
style: TextStyle(
color: textColor??Colors.black,
fontWeight: FontWeight.w400,
fontSize: 15),
isExpanded: true,
icon: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
),
hint: Text(hint,
style: TextStyle(
color:Colors.white,
fontWeight: FontWeight.w400,
fontSize:15)),
items: list.map((item) {
return DropdownMenuItem<String>(
value: item,
child: new Text(item,
style: TextStyle(
color:Colors.black,
fontWeight: FontWeight.w400,
fontSize:15)),
);
}).toList(),
onChanged: (value) {
values = value;
print(values);
},
),
);
class DropDownClass扩展了无状态小部件{
var值;
var提示;
列表=新列表();
颜色;颜色;
颜色下拉颜色;
颜色文本颜色;
DropDownClass({this.values,
this.list、this.hint、this.underLineColor、this.dropDownColor、this.textColor});
@凌驾
小部件构建(构建上下文){
返回DropdownButtonHideUnderline(
子项:DropdownButtonFormField(
价值:价值,
dropdownColor:dropdownColor??Colors.white,
装饰:输入装饰(
enabledBorder:UnderlineInputBorder(
边界边(
颜色:下划线颜色??颜色。灰色[800],
宽度:1.0,
),
)
),
样式:TextStyle(
颜色:textColor??Colors.black,
fontWeight:fontWeight.w400,
尺寸:15),,
是的,
图标:图标(
图标。键盘箭头向下,
颜色:颜色,白色,
),
提示:文本(提示,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.w400,
尺寸:15),,
项目:list.map((项目){
返回下拉菜单项(
价值:项目,,
子项:新文本(项,
样式:TextStyle(
颜色:颜色,黑色,
fontWeight:fontWeight.w400,
尺寸:15),,
);
}).toList(),
一旦更改:(值){
价值=价值;
打印(值);
},
),
);
}
}没有任何变化这是一个有效的代码,伙计,我正在我的项目中使用此代码。重新检查这可能是你遗漏了什么问题是我的文本文件大小比文本小。谢谢,这非常有用