Skip to content

Commit

Permalink
Fix country selector overflow issue (#950)
Browse files Browse the repository at this point in the history
* fix(country selector): preselect the most likely country

* fix(country selector): preselect the most likely country

* Fix country selector overflow issue

* ...

Co-authored-by: Jasmeet Singh <jasmeetsingh@google.com>
  • Loading branch information
jasmeet0817 and Jasmeet Singh authored Jan 14, 2022
1 parent 4eccfbe commit 4495613
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions packages/smooth_app/lib/pages/onboarding/country_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,37 @@ class _CountrySelectorState extends State<CountrySelector> {
if (snapshot.connectionState != ConnectionState.done) {
return const CircularProgressIndicator();
}
return Container(
padding: widget.padding,
child: DropdownButtonFormField<Country>(
value: _chosenValue,
decoration: widget.inputDecoration,
items: _countryList
.map<DropdownMenuItem<Country>>((Country country) {
return DropdownMenuItem<Country>(
value: country,
child: Text(country.name),
);
}).toList(),
onChanged: (Country? value) async {
if (value != null) {
_chosenValue = value;
await _setUserCountry(_chosenValue.countryCode);
setState(() {});
}
},
),
);
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final double parentWidth = constraints.maxWidth;
return Container(
padding: widget.padding,
child: DropdownButtonFormField<Country>(
value: _chosenValue,
decoration: widget.inputDecoration,
items: _countryList
.map<DropdownMenuItem<Country>>((Country country) {
return DropdownMenuItem<Country>(
value: country,
child: Container(
// Set the maxWidth so the dropdown arrow icon doesn't overflow.
// 48 dp is needed to account for dropdown arrow icon and padding.
constraints: BoxConstraints(maxWidth: parentWidth - 48)
.normalize(),
child: Text(country.name),
),
);
}).toList(),
onChanged: (Country? value) async {
if (value != null) {
_chosenValue = value;
await _setUserCountry(_chosenValue.countryCode);
setState(() {});
}
},
),
);
});
},
);

Expand Down

0 comments on commit 4495613

Please sign in to comment.