首页 > 解决方案 > 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: 'الجرعة',

),
),

标签: flutter

解决方案


试试这个

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);
        },
      ),
    )

推荐阅读