DropdownButtonFormField 不顯示選擇顫振的值 (DropdownButtonFormField dosn't show the value that selected flutter)


問題描述

DropdownButtonFormField 不顯示選擇顫振的值 (DropdownButtonFormField dosn't show the value that selected flutter)

這是我的代碼,我嘗試在控制台中打印該值,以確定它是否有效並且打印正確,但它沒有顯示在 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: 'الجرعة',

),
),

參考解法

方法 1:

try this

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

方法 2:

i made a class for you, you can call it anywhere may be it will help you

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

} }

(by RubaHamza SiddiquiHamza Siddiqui)

參考文件

  1. DropdownButtonFormField dosn't show the value that selected flutter (CC BY‑SA 2.5/3.0/4.0)

#Flutter






相關問題

Flutter:構建 APK 時如何傳遞 Gradle 參數? (Flutter: how do I pass Gradle params when building an APK?)

自行更新的 Flutter 模型 (Flutter model that updates itself)

在 Flutter for Web 應用程序中嵌入網頁作為 Widget(類似於 iframe) (Embed a web page as a Widget inside Flutter for Web application (similar to iframe))

顫振無線電值在步進器中沒有改變 (Flutter Radio Value not Changing in Stepper)

Flutter - 使用收到的每條消息通知的實時消息應用程序的最佳方式? (Flutter - Best way to do real-time messaging app with notifications per received message?)

Flutter 在執行異步等待任務時顯示一個小部件 (Flutter show a widget while an async await task is being executed)

嘗試在 Flutter 中訪問 Hive 數據庫時,“聯繫人”框已打開且類型為 Box<Contact> (The box "contacts" is already open and of type Box<Contact> when trying to access Hive database in flutter)

如何在 Flutter MultiImagePicker 中指定照片的質量? (How can i specify the quality of the photo in Flutter MultiImagePicker?)

Swift pod 還不能集成為靜態庫 (Swift pods cannot yet be integrated as static libraries)

為什麼我可以通過 android 模擬器運行一個簡單的計數器應用程序,但不能通過 ios 模擬器運行? (Why can I run a simple counter application through an android simulator but not through an ios simulator?)

DropdownButtonFormField 不顯示選擇顫振的值 (DropdownButtonFormField dosn't show the value that selected flutter)

如何在 Flutter 中獲得手動相機對焦 (How to get manual camera focus in Flutter)







留言討論