DropdownMenu

 import "package:flutter/material.dart";


List<String> list = <String>["One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"];
void main()
{
runApp(MyApp());
}
class MyApp extends StatelessWidget
{
MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "DropDownMenu",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: DropDownDemo(),
);
}
}
class DropDownDemo extends StatefulWidget
{
DropDownDemo({super.key});
@override
State<DropDownDemo> createState() {
return DropDownDemoState();
}
}
class DropDownDemoState extends State<DropDownDemo>
{
String dropdownValue = list.first;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("DropDownDemo"),
centerTitle: true,
),
body: Center(
child: DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_drop_down),
elevation: 16,
style: const TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String? value) {
setState(() {
dropdownValue = value!;
});
},
items: list.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter