Created
October 10, 2019 21:26
-
-
Save shihaohong/a746ba93bf4891322c1107df2a112dfb to your computer and use it in GitHub Desktop.
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(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Sample', | |
home: Scaffold( | |
appBar: AppBar(title: const Text('Sample')), | |
body: MyStatefulWidget(), | |
), | |
); | |
} | |
} | |
class MyStatefulWidget extends StatefulWidget { | |
MyStatefulWidget({Key key}) : super(key: key); | |
@override | |
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); | |
} | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> { | |
final List<String> items = <String>['1', '2', '3']; | |
String selectedItem = '1'; | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Text('Enabled DropdownButton:'), | |
DropdownButton<String>( | |
value: null, | |
hint: Text('Hint text here'), | |
items: items.map((item) { | |
return DropdownMenuItem( | |
value: item, | |
child: Text(item), | |
); | |
}).toList(), | |
onChanged: (String value) { | |
setState(() { selectedItem = value; }); | |
}, | |
), | |
Divider(), | |
Text('Disabled DropdownButton:'), | |
DropdownButton<String>( | |
value: selectedItem, | |
hint: Text('Hint text here'), | |
items: items.map((item) { | |
return DropdownMenuItem( | |
value: item, | |
child: Text(item), | |
); | |
}).toList(), | |
onChanged: null, | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment