I want to display a Row for each DropdownMenuItem of DropdownButton in Flutter. I want to display an icon and a text in the Row.
If anybody can please help me with it.
This is how I've tried. I've tried to add the Icon and Text in a Row for each item in the DropdownButton.
class _LoginPageState extends State<LoginPage> {
Widget dropdownValue = Row(
children: [Icon(Icons.star), Text("One")],
);
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
child: ListView(
padding: EdgeInsets.all(20.0),
children: [
Padding(padding: EdgeInsets.all(displayHeight(context) * 0.02)),
Center(
child: Image(
image: AssetImage('assets/images/sendmelogo.png'),
height: displayHeight(context) * 0.07,
),
),
Padding(padding: EdgeInsets.all(displayHeight(context) * 0.02)),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.grey[200],
),
// padding: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Sending to:", textAlign: TextAlign.start),
DropdownButton<Widget>(
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (Widget newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <Widget>[
Row(
children: [Icon(Icons.star), Text("One")],
),
Row(
children: [Icon(Icons.plus_one), Text("Two")],
)
].map<DropdownMenuItem<Widget>>((Widget value) {
return DropdownMenuItem<Widget>(
value: value,
child: Container(
child: value,
),
);
}).toList(),
),
],
),
),
See Question&Answers more detail:
os