Skip to content

Instantly share code, notes, and snippets.

@boldijar
Created March 13, 2018 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boldijar/69aa09cda37d17a09617d6113fd7441e to your computer and use it in GitHub Desktop.
Save boldijar/69aa09cda37d17a09617d6113fd7441e to your computer and use it in GitHub Desktop.
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