Browse Source

Show state selection if country has states. Select city.

master
Robby Zambito 6 months ago
parent
commit
5d0f8d1197
1 changed files with 87 additions and 7 deletions
  1. +87
    -7
      lib/views/unauthenticated/instance_selector.dart

+ 87
- 7
lib/views/unauthenticated/instance_selector.dart View File

@ -38,6 +38,10 @@ class _InstanceSelectorState extends State {
city: "Syracuse",
state: "New York",
country: CountryCodes.detailsForLocale(Locale('en', 'US'))),
HamletInstance(
city: "Pittsburgh",
state: "Pennsylvania",
country: CountryCodes.detailsForLocale(Locale('en', 'US'))),
HamletInstance(
city: "Berlin",
country: CountryCodes.detailsForLocale(Locale('de', 'DE'))),
@ -61,22 +65,56 @@ class _InstanceSelectorState extends State {
int _selectedCountryIndex = 0;
List<Widget> _buildStateList() {
final res = _hamletInstanceList
.where((i) =>
i.country.localizedName ==
(_buildCountryList()[_selectedCountryIndex] as Text).data)
.map((i) => i.state)
.where((s) => s != null)
.toSet()
.toList();
print("res: ${res.toString()}");
return res.map((s) => Text(s)).toList();
}
int _selectedStateIndex = 0;
List<Widget> _buildCityList() {
final res = _hamletInstanceList
.where((i) =>
i.country.localizedName ==
(_buildCountryList()[_selectedCountryIndex] as Text).data)
.map((i) => i.city)
.toSet()
.toList();
res.sort();
return res.map((c) => Text(c)).toList();
}
int _selectedCityIndex = 0;
void _toggleIsCustomInstance() {
this.setState(() {
_isCustomInstance = !_isCustomInstance;
setState(() {
this._isCustomInstance = !this._isCustomInstance;
});
}
bool _selectedCountryHasStates() => _buildStateList().isNotEmpty;
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
_isCustomInstance
!_isCustomInstance
? Column(
children: [
Padding(
padding: const EdgeInsets.only(left: 10.0),
padding: const EdgeInsets.only(left: 0),
child: Text("Country"),
),
DirectSelect(
@ -86,10 +124,49 @@ class _InstanceSelectorState extends State {
onSelectedItemChanged: (index) {
setState(() {
_selectedCountryIndex = index;
_selectedStateIndex = 0;
_selectedCityIndex = 0;
});
},
items: _buildCountryList(),
),
_selectedCountryHasStates()
? Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10),
child: Text("State"),
),
DirectSelect(
itemExtent: 35,
selectedIndex: _selectedStateIndex,
child: _buildStateList()[_selectedStateIndex],
onSelectedItemChanged: (index) {
setState(() {
_selectedStateIndex = index;
_selectedCityIndex = 0;
});
},
items: _buildStateList(),
),
],
)
: SizedBox.shrink(),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Text("City"),
),
DirectSelect(
itemExtent: 35,
selectedIndex: _selectedCityIndex,
child: _buildCityList()[_selectedCityIndex],
onSelectedItemChanged: (index) {
setState(() {
_selectedCityIndex = index;
});
},
items: _buildCityList(),
),
],
)
: Column(
@ -97,9 +174,12 @@ class _InstanceSelectorState extends State {
),
GestureDetector(
onTap: this._toggleIsCustomInstance,
child: Text(_isCustomInstance
? "Login to a Hamlet instance instead"
: "Login to a custom instance instead"),
child: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(_isCustomInstance
? "Login to a Hamlet instance instead"
: "Login to a custom instance instead"),
),
),
],
),

Loading…
Cancel
Save