Skip to content

Instantly share code, notes, and snippets.

@oravecz
Created February 2, 2023 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oravecz/62a9676a3d8f904c96f3ad7ae114a1c0 to your computer and use it in GitHub Desktop.
Save oravecz/62a9676a3d8f904c96f3ad7ae114a1c0 to your computer and use it in GitHub Desktop.
amber-tundra-1873
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return HomeScreen();
}
}
class HomeScreen extends StatefulWidget {
@override
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
String dropdownValue;
List<Product> products = [
Product(name: 'sep1', type: 'sep'),
Product(name: 'milk', type: 'data'),
Product(name: 'oil', type: 'data'),
Product(name: 'sep2', type: 'sep'),
Product(name: 'suger', type: 'data'),
Product(name: 'salt', type: 'data'),
Product(name: 'sep3', type: 'sep'),
Product(name: 'potatoe', type: 'data'),
Product(name: 'tomatoe', type: 'data'),
Product(name: 'apple', type: 'data'),
];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('text')),
body: Column(
children: [
Text('test'),
Expanded(
child: DropdownButton<String>(
value: dropdownValue,
items: products.map((value) {
return DropdownMenuItem(
value: value.name,
child: value.type == 'data'
? Text(value.name)
: Divider(
color: Colors.red,
thickness: 3,
),
);
}).toList(),
onChanged: (newValue) {
setState(() {
dropdownValue = newValue;
});
print('$newValue $dropdownValue');
},
),
),
],
),
);
}
}
class Product {
String name;
String type;
Product({this.name, this.type});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment