Created with <3 with dartpad.dev.
Created
February 2, 2023 13:39
-
-
Save oravecz/62a9676a3d8f904c96f3ad7ae114a1c0 to your computer and use it in GitHub Desktop.
amber-tundra-1873
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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