Guest User

Untitled

a guest
Mar 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3.  
  4. class SettingsWidget extends StatefulWidget {
  5. SettingsWidget({Key key}) : super(key: key);
  6.  
  7. @override
  8. _SettingsWidgetState createState() => new _SettingsWidgetState();
  9. }
  10.  
  11. class _SettingsWidgetState extends State<SettingsWidget> {
  12.  
  13. List _cities =
  14. ["Cluj-Napoca", "Bucuresti", "Timisoara", "Brasov", "Constanta"];
  15.  
  16. List<DropdownMenuItem<String>> _dropDownMenuItems;
  17. String _currentCity;
  18.  
  19. @override
  20. void initState() {
  21. _dropDownMenuItems = getDropDownMenuItems();
  22. _currentCity = _dropDownMenuItems[0].value;
  23. super.initState();
  24. }
  25.  
  26. List<DropdownMenuItem<String>> getDropDownMenuItems() {
  27. List<DropdownMenuItem<String>> items = new List();
  28. for (String city in _cities) {
  29. items.add(new DropdownMenuItem(
  30. value: city,
  31. child: new Text(city)
  32. ));
  33. }
  34. return items;
  35. }
  36.  
  37. @override
  38. Widget build(BuildContext context) {
  39. return new Container(
  40. color: Colors.white,
  41. child: new Center(
  42. child: new Column(
  43. crossAxisAlignment: CrossAxisAlignment.center,
  44. mainAxisAlignment: MainAxisAlignment.center,
  45. children: <Widget>[
  46. new Text("Please choose your city: "),
  47. new Container(
  48. padding: new EdgeInsets.all(16.0),
  49. ),
  50. new DropdownButton(
  51. value: _currentCity,
  52. items: _dropDownMenuItems,
  53. onChanged: changedDropDownItem,
  54. )
  55. ],
  56. )
  57. ),
  58. );
  59. }
  60.  
  61. void changedDropDownItem(String selectedCity) {
  62. setState(() {
  63. _currentCity = selectedCity;
  64. });
  65. }
  66.  
  67. }
Add Comment
Please, Sign In to add comment