Dropdown button not expanding - flutter

I'm trying to build a form with a DropdownButtonFormField with 4 items but i don't know why it doesn't want to expand.
Added isDense : true but it wasn't because of it being too small
Here's the button code
new Container(
child: DropdownButtonFormField(
isDense: false,
hint: Text('Ecole'),
onSaved: (value) {
this._data.ecole = value.toString();
},
items: ['HEI', 'ISEN', 'ISA', 'all'].map((String value) {
return DropdownMenuItem(
value: value,
child: Text(value),
);
}).toList()),
),
1

Try this
String dropdownValue = 'HEI';
DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>['HEI', 'ISEN', 'ISA', 'all']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),

Related

Flutter Dropdown with radio button

How to Design this type of Dropdown dropdown with radio button - sample
I will tryed more time of this design.. and if I select one option it sohwes only Text
My Code
child: DropdownButton<String>(
value: selectedVtypes,
items: ['New', 'Pre-Owned'].map((String value) {
return DropdownMenuItem(
child: Container(
width: 150,
child: ListTile(
title: Text(value),
trailing: Radio(
value: value,
groupValue: value,
onChanged: (val) {},
),
),
),
value: value,
);
}).toList(),
onChanged: (String? vtype) {
setState(() {
selectedVtypes = vtype;
});
},
),
),```

flutter remove DropdownButton left padding

I've struggled to remove flutter's DropdownButton left padding so it can match the TextField below. Anyone can help?
Here's my code:
DropdownButton<MenuModel>(
itemHeight: itemHeight,
isExpanded: true,
underline: null,
value: currentValue,
hint: Text(placeholder, style: hintStyle),
style: textStyle,
disabledHint: Text(currentValue?.label ?? placeholder, style: textStyle),
onChanged: widget.modalMode ? null : _onChanged,
items: widget.listMenu.map<DropdownMenuItem<MenuModel>>((MenuModel val) {
return DropdownMenuItem<MenuModel>(
child: Text(val.label),
value: val,
);
}).toList(),
)
finally I've found the problem. So it happen because I wrapped the DropdownButton with ButtonTheme(alignedDropdown: true)
ButtonTheme(
alignedDropdown: true, // it's the culprit
child: DropdownButton<MenuModel>(
itemHeight: itemHeight,
isExpanded: true,
underline: null,
value: currentValue,
hint: Text(placeholder, style: hintStyle),
style: textStyle,
disabledHint: Text(currentValue?.label ?? placeholder, style: textStyle),
onChanged: widget.modalMode ? null : _onChanged,
items: widget.listMenu.map<DropdownMenuItem<MenuModel>>((MenuModel val) {
return DropdownMenuItem<MenuModel>(
child: Text(val.label),
value: val,
);
}).toList(),
),
)
Thanks for the help.
Try below code hope its helpful to you. refer Dropdown here. just change my widget to your widgets
Create variable and List of dropdown:
var selectedCategory;
List categoryDropDownList = [
'One',
'Two',
'Three',
'Four',
];
Your Widget:
DropdownButton(
isDense: true,
isExpanded: true,
hint: Text(
'Select Category',
style: TextStyle(
color: Colors.black,
fontSize: 15,
),
textAlign: TextAlign.center,
),
value: selectedCategory,
items: categoryDropDownList.map<DropdownMenuItem<String>>(
(value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value.toString(),
style: TextStyle(
fontSize: 17,
),
),
);
},
).toList(),
onChanged: (var value) {
setState(
() {
selectedCategory = value;
},
);
},
),
Your result Screen->
I have tried to use the same style as you are using and managed to get that done with the following code. I hope that works for you. I am attaching the screenshot as well of the output.
Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
DropdownButton<String>(
itemHeight: 50,
isExpanded: true,
underline: null,
value: dropdownValue,
hint: const Text('Honorific', style: TextStyle(color: Colors.grey)),
icon: const Icon(Icons.arrow_drop_down),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>['Honorific']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
TextFormField(
controller: controller,
validator: (value) {
if (value!.isEmpty || !value.contains('#')) {
return 'Please enter a valid email address';
}
return null;
},
textInputAction: TextInputAction.next,
keyboardType: TextInputType.emailAddress,
),
],
),
),
output

Dropdown is not keeping the value selected

I am working on a dropdown and I have the values in a variable, but I can't get the selected value to be shown, instead is always a static value on.
So far I did this:
class DropDownWidget extends State {
String dropdownValue = 'Activities';
String holder = '';
List<String> postType = ['Activities', 'Sell/buy', 'New Friends', 'City Recommendations', 'Post'];
void getDropDownItem() {
setState(() {
holder = dropdownValue;
});
}
#override
Widget build(BuildContext context) {
return Container(
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/img/blue.png'),
fit: BoxFit.cover,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(
Icons.keyboard_arrow_down_outlined,
color: TheBaseColors.lightRed,
),
iconSize: 30,
elevation: 16,
style: TextStyle(color: TheBaseColors.lightRed, fontSize: 18),
onChanged: (String data) {
setState(() {
dropdownValue = data;
});
switch (data) {
case 'Activities':
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreateActivity()),
);
break;
case 'Sell/buy':
Navigator.push(
context,
}
},
items: postType.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
],
),
);
}
}
I have saved the dropdow value in a variable and then set it in the SetState, but how to show the selected item each time?
Try This
String dropdownValue = 'Activities';
DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>['Activities', 'Sell/buy', 'New Friends', 'City Recommendations', 'Post']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),

remove dropdown bottom line in flutter

How to remove dropdown bottom line?
My Code
Container(
padding: EdgeInsets.fromLTRB(15, 5, 10, 5),
child: Row(
children: <Widget>[
dropdownButton,
Expanded(child: phoneField),
],
),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey, width: 1),
borderRadius: BorderRadius.circular(32.0)),
)
And this is Dropdown
var dropdownButton = DropdownButton(
value: dropdownValue,
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['99451', '99450', '99455', '99470 ']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);
You have to wrap your DropdownButton inside 
DropdownButtonHideUnderline like this 
var dropdownButton = DropdownButtonHideUnderline(
child: DropdownButton(
value: dropdownValue,
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['99451', '99450', '99455', '99470 '].map<DropdownMenuItem<String>>
((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
);
you can use like that
underline: SizedBox()
Found a solution using
underline: Container(),
Full Changed Code
var dropdownButton = DropdownButton(
value: dropdownValue,
underline: Container(),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['99451', '99450', '99455', '99470 ']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);

Flutter DropdownButton show label when option is selected

Can a Dropdown Button:
return DropdownButton<String>(
items: <String>['Foo', 'Bar'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
);
have something similar to a decoration user in a TextFormField:
TextFormField(
controller: _titleController,
decoration: InputDecoration(labelText: 'Input'),
validator: (String value) {
if (value != null && value.isEmpty) {
return 'Please enter some text';
}
},
style: Theme.of(context).textTheme.title,
),
When something is written in the above TextFormField the word Input shows. Like this:
Replace DropdownButton with DropdownButtonFormField:
https://api.flutter.dev/flutter/material/DropdownButtonFormField-class.html
Change DropdownButton to DropdownButtonFormField and add this decoration....
decoration: InputDecoration(
filled: true,
fillColor: Hexcolor('#ecedec'),
labelText: 'Occupation',
border: new CustomBorderTextFieldSkin().getSkin(),
),
Copy Paste and see magic
I have done flutter dropdown with material design
Padding(
padding: const EdgeInsets.all(9.0),
child: InputDecorator(
decoration: InputDecoration(
labelText: 'Priority',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0)),
contentPadding: EdgeInsets.all(10),
),
child: ButtonTheme(
materialTapTargetSize: MaterialTapTargetSize.padded,
child: DropdownButton<String>(
hint: const Text("Priority"),
isExpanded: true,
value: dropdownValue,
elevation: 16,
underline: DropdownButtonHideUnderline(
child: Container(),
),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
),