help me to remove this elevation in DropdownButton, I tried using elevation = 0, but nothing happened or if you have better widget to display item like DropdownButton please show me.
thank you
To remove the underline we should wrap the DropdownButton widget with the DropdownButtonHideUnderline widget.
The elevation property will make the drop-down layer elevated when it's in the open state.
Example
DropdownButtonHideUnderline(
child: DropdownButton(
style: TextStyle(color: Colors.black),
items: <String>[
'Android',
'IOS',
'Flutter',
'Python',
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
hint: Text(
"Please choose a langauage",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w600),
),
onChanged: (value) {
print(value);
},
),
),
Related
i have a dropdown which contain list of text, then i want have different color of select text and color the text from the dropdown item.
DropdownButton<String>(
hint: Text(
'Topic',
style: TextStyle(fontFamily: 'Cairo', fontSize: 20),
),
isExpanded: true,
value: dropdownValue,
dropdownColor: Colors.black,
elevation: 4,
//notices 1
style: const TextStyle(
color: Colors.deepPurple, fontFamily: 'Cairo'),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: tpoicList
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Container(
// alignment: Alignment.centerRight,
child: Text(
value,
style: const
//notices 2
TextStyle(color: Colors.black),
),
),
);
}).toList(),
)
i notices that in the notice 1 style is also affect the notice 2 style. All i want to is to have different color in the text dropdown and selected text
what i am trying to archive
In the image you will notices the background color is different from the text color also if i select a item from the select item, the text should be in another colors
The DropdownButton has a selectedItemBuilder parameter that should solve your problem. Add something like this to your code:
selectedItemBuilder: (context) {
final List<DropdownMenuItem<String>> list = [];
for (int i = 0; i < tpoicList.lenght; i++) {
list.add(DropdownMenuItem<String>(
value: tpoicList[i],
child: Container(
child: Text(
value,
style: i == dropdownValue?
[YourNewTextStyle],
const TextStyle(color: Colors.black),
),
),
));
}
return list;
},
[official] change dropdown text colour from selected text
selectedItemBuilder: (BuildContext context) {
return tpoicList.map((String value) {
return Align(
alignment: Alignment.centerLeft,
child: Text(
dropdownValue,
style: const TextStyle(color: Colors.white),
),
);
}).toList();
},
how to make the dropdown to the left, because what i get is the dropdown in the middle
DropdownButton<String>(
value: _chosenValue2,
//elevation: 5,
style: TextStyle(color: Colors.black),
items: <String>[
'Personal Type',
'Other',
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
hint: Text(
"Customer Model",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w600),
),
onChanged: (String value) {
setState(() {
_chosenValue2 = value;
});
},
),
Try below code hope its helpful to you. Add your dropdown widget inside Container and set Alignment.centerLeft
Container(
// padding: EdgeInsets.all(5), if you required some padding to dropdown to set padding
alignment:Alignment.centerLeft,
child: DropdownButton<String>(
value: _chosenValue2,
//elevation: 5,
style: TextStyle(color: Colors.black),
items: <String>[
'Personal Type',
'Other',
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
hint: Text(
"Customer Model",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w600),
),
onChanged: (String value) {
setState(() {
_chosenValue2 = value;
});
},
),
),
Your result screen->
You could use quite a few approaches. You could wrap your drop-down widget in a Container or Align widget and set their alignment property to Alignment.bottomLeft or Alignment.centerLeft or Alignment.topLeft. You could also wrap your dropdown widget inside just a Container and then use margin property to move your widget like margin: EdgeInsets.only(right: 20) or to any value of your desire. Lastly, you could also wrap your widget with a Padding widget and set the padding property to an extent you want your drop-down widget to move leftwards like padding: const EdgeInsets.only(right: 50)
I have made a drop-down list as in the following screen
enter image description here
Here:
I want the drop-down to be in a box like other TextFormFields and arrow to be bigger
my drop-down list background seems to be blurred and not visible
I want the selected value to be replaced on "Choose the id proof"
Following is my code:
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
color: Colors.white,
child: _hintDown(),
),
SizedBox(height: 10),
my dropdown code is:
DropdownButton _hintDown() => DropdownButton<String>(
items: [
DropdownMenuItem<String>(
value: "1",
child: Text(
"Aadhar Card",
),
),
DropdownMenuItem<String>(
value: "2",
child: Text(
"Pancard",
),
),
],
onChanged: (value) {
print("value: $value");
},
hint: Text(
"Choose the id proof!",
style: TextStyle(
color: Colors.black,
),
),
);
Is this code enough or do I need to go for some other?
There are certain changes in the code as per the requirements. You must visit the flutter documentation and read about using DropdownButton class to achieve what you want
See the code clearly, and implement the code in your code base
// look at the comments too to understand the functionality
String dropdownValue = 'Choose the id proof!';
// Return a widgt container to give the border
// and then wrap it around your DropdownButton
Widget _hintDown() => Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8.0)
),
child: Padding(
padding: EdgeInsets.all(5.0),
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
iconSize: 30, //this inicrease the size
elevation: 16,
style: TextStyle(color: Colors.black),
// this is for underline
// to give an underline us this in your underline inspite of Container
// Container(
// height: 2,
// color: Colors.grey,
// )
underline: Container(),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['Choose the id proof!', 'Adhaar Card', 'Pancard', 'Voter card', 'Passport']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
)
);
Result
I am trying to use dropdown, and want to have Colors.white for the selected text, and Colors.black54 for the text of drop down list. But when I tried to use color attribute and change it to White, it also change the color of drop down text.
DropdownButton<String>(
//this changed the color of both text, intial text as well dropdown text color
dropdownColor: Colors.white,
value: value,
style: TextStyle(color: Colors.white),
icon: CircleAvatar(
radius: 12,
backgroundColor: Colors.white,
child: Icon(Icons.arrow_drop_down),
),
items: places.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(
value,
//I tried giving text style here , but same result
style: TextStyle(color: Colors.white),
),
);
}).toList(),
onChanged: (_) {
setState(() {
value = _;
});
},
)
Here is the picture of it.
Okay I found the Solution using selectedItemBuilder attribute of dropdown
final List<String> places = ['Delhi', 'Mumbai', 'Kerela', 'Agra'];
DropdownButton<String>(
selectedItemBuilder: (_) {
return places
.map((e) => Container(
alignment: Alignment.center,
child: Text(
e,
style: TextStyle(color: Colors.white),
),
))
.toList();
},
value: value,
icon: CircleAvatar(
radius: 12,
backgroundColor: Colors.white,
child: Icon(Icons.arrow_drop_down),
),
items: places.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(
value,
style: TextStyle(color: Colors.black54),
),
);
}).toList(),
onChanged: (_) {
setState(() {
value = _;
});
},
)
Here is the result
I'm putting a DropdownButton in a TileList's trailing, settings up the parameters shown in the docs to make it active, but It stays disabled regardless.
The ListTile is part of a ListView not included in the code below.
I set up setState() like the docs stated but no avail.
I am not able to find the root cause of this issue, no idea what's causing it.
I've tried enum with int as a value but it also didn't work.
...
final Store<AppState> store;
Units unit;
#override
void initState() {
super.initState();
unit = store.state.weatherState?.temperature?.unit;
}
...
enum Units {Celsius, Fahrenheit, Kelvin}
Widget _displayUnitsSettings({Store<AppState> store}) {
return ListTile(
dense: true,
enabled: true,
selected: true,
title: Text(
"Temperature Unit",
style: TextStyle(
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.dotted,
fontSize: 14,
fontWeight: FontWeight.w700,
color: Colors.white),
),
subtitle: Text(
"Default: Celsius.\nAvailable units: Celsius, Fahrenheit, Kelvin.",
style: TextStyle(
fontSize: 9, fontWeight: FontWeight.w700, color: Colors.white54),
),
trailing: DropdownButton(
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w700, color: Colors.white54),
isDense: true,
value: unit,
onChanged: (value) {
store.dispatch(ChangeUnit(unit: value));
setState(() {
unit = value;
});
},
items: <DropdownMenuItem>[
DropdownMenuItem(
value: Units.Celsius,
child: Text("Celsius"),
),
DropdownMenuItem(
value: Units.Fahrenheit,
child: Text("Fahrenheit"),
),
DropdownMenuItem(
value: Units.Kelvin,
child: Text("Kelvin"),
),
],
),
);
}
...
EDIT: The DropdownButton seem to be enabled but I am unable to click it.
Here's the problem. You have an AppBar with no position after the ListView on a Stack. What this mean is that the AppBar is overlapping over your ListView and therefore intercepting the gestures on your DropdownButton.
Wrap your AppBar with a Positioned widget and it will work. Like this:
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
leading: _backButton(context),
backgroundColor: Colors.transparent,
elevation: 0,
),
),