|
// Flutter code sample for |
|
|
|
// This sample shows a `DropdownButton` with a customized icon, text style, |
|
// and underline and whose value is one of "One", "Two", "Free", or "Four". |
|
// |
|
//  |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
void main() => runApp(MyApp()); |
|
|
|
/// This Widget is the main application widget. |
|
class MyApp extends StatelessWidget { |
|
static const String _title = 'Flutter Code Sample'; |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return MaterialApp( |
|
title: _title, |
|
home: Scaffold( |
|
appBar: AppBar(title: const Text(_title)), |
|
body: MyStatefulWidget(), |
|
), |
|
); |
|
} |
|
} |
|
|
|
class MyStatefulWidget extends StatefulWidget { |
|
MyStatefulWidget({Key key}) : super(key: key); |
|
|
|
@override |
|
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); |
|
} |
|
|
|
class _MyStatefulWidgetState extends State<MyStatefulWidget> { |
|
String dropdownValue = 'One'; |
|
List<String> items = <String>['One', 'Two', 'A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. A repeating, long selection. ', 'Four']; |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
body: Column( |
|
children: <Widget>[ |
|
DropdownButton<String>( |
|
isExpanded: true, |
|
value: dropdownValue, |
|
icon: Icon(Icons.arrow_downward), |
|
iconSize: 24, |
|
elevation: 16, |
|
style: TextStyle(color: Colors.deepPurple), |
|
onChanged: (String newValue) { |
|
setState(() { |
|
dropdownValue = newValue; |
|
}); |
|
}, |
|
items: items.map<DropdownMenuItem<String>>((String value) { |
|
return DropdownMenuItem<String>( |
|
value: value, |
|
child: Text(value), |
|
); |
|
}).toList(), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
} |