Ruba
Ruba

Reputation: 53

DropdownButtonFormField dosn't show the value that selected flutter

This is my code and I tried to print the value in my console to figure if it is work and it's correctly printed but it dose not show in the text Filed. When I chose the hint text disappear but no thing show also I changed the Icon (arrow) size but when I click on any part of it, no response until I click in the corner

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: 'الجرعة',

),
),

Upvotes: 0

Views: 141

Answers (2)

Hamza Siddiqui
Hamza Siddiqui

Reputation: 716

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

} }

Upvotes: 0

Hamza Siddiqui
Hamza Siddiqui

Reputation: 716

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

Upvotes: 1

Related Questions