Created
March 13, 2018 17:23
-
-
Save boldijar/69aa09cda37d17a09617d6113fd7441e 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'; | |
class SettingsWidget extends StatefulWidget { | |
SettingsWidget({Key key}) : super(key: key); | |
@override | |
_SettingsWidgetState createState() => new _SettingsWidgetState(); | |
} | |
class _SettingsWidgetState extends State<SettingsWidget> { | |
List _cities = | |
["Cluj-Napoca", "Bucuresti", "Timisoara", "Brasov", "Constanta"]; | |
List<DropdownMenuItem<String>> _dropDownMenuItems; | |
String _currentCity; | |
@override | |
void initState() { | |
_dropDownMenuItems = getDropDownMenuItems(); | |
_currentCity = _dropDownMenuItems[0].value; | |
super.initState(); | |
} | |
List<DropdownMenuItem<String>> getDropDownMenuItems() { | |
List<DropdownMenuItem<String>> items = new List(); | |
for (String city in _cities) { | |
items.add(new DropdownMenuItem( | |
value: city, | |
child: new Text(city) | |
)); | |
} | |
return items; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new Container( | |
color: Colors.white, | |
child: new Center( | |
child: new Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
new Text("Please choose your city: "), | |
new Container( | |
padding: new EdgeInsets.all(16.0), | |
), | |
new DropdownButton( | |
value: _currentCity, | |
items: _dropDownMenuItems, | |
onChanged: changedDropDownItem, | |
) | |
], | |
) | |
), | |
); | |
} | |
void changedDropDownItem(String selectedCity) { | |
setState(() { | |
_currentCity = selectedCity; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment