showCountryPickerSheet method
Future<Country?>
showCountryPickerSheet(
- BuildContext context, {
- Widget? title,
- Widget? cancelWidget,
- double cornerRadius = 25,
- bool focusSearchBox = false,
- double heightFactor = 0.9,
- List<
String> filteredCountries = const [], - TextStyle itemTextStyle = const TextStyle(fontSize: 16),
- TextStyle searchInputStyle = const TextStyle(fontSize: 16),
- InputDecoration? searchInputDecoration,
- double flagIconWidth = 32,
- double flagIconHeight = 22,
- bool showSeparator = false,
- String searchHintText = "Search country name, code",
Implementation
Future<Country?> showCountryPickerSheet(BuildContext context,{Widget? title, Widget? cancelWidget, double cornerRadius = 25, bool focusSearchBox = false, double heightFactor = 0.9, List<String> filteredCountries = const [], TextStyle itemTextStyle = const TextStyle(fontSize: 16), TextStyle searchInputStyle = const TextStyle(fontSize: 16), InputDecoration? searchInputDecoration, double flagIconWidth = 32, double flagIconHeight = 22, bool showSeparator = false, String searchHintText = "Search country name, code"})async {
assert(heightFactor <= 0.9 && heightFactor >= 0.4,
'heightFactor must be between 0.4 and 0.9');
return await showModalBottomSheet<Country?>(
context: context,
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(cornerRadius),
topRight: Radius.circular(cornerRadius))),
builder: (_) {
return SizedBox(
height: MediaQuery.of(context).size.height * heightFactor,
child: Column(
children: <Widget>[
const SizedBox(height: 12),
Stack(
children: <Widget>[
cancelWidget ??
Positioned(
right: 8,
top: 0,
bottom: 0,
child: TextButton(
style: const ButtonStyle(
padding: WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4))
),
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
Center(
child: title ??
const Text(
'Choose country',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w500,
),
),
),
],
),
const SizedBox(height: 10),
Expanded(
child: AdvanceCountryPickerWidget(
onSelected: (country) => Navigator.of(context).pop(country),
filteredCountries: filteredCountries,
itemTextStyle: itemTextStyle,
searchHintText: searchHintText,
searchInputDecoration: searchInputDecoration,
searchInputStyle: searchInputStyle,
showSeparator: showSeparator,
flagIconWidth: flagIconWidth,
flagIconHeight: flagIconHeight,
focusSearchBox: focusSearchBox,
),
),
],
),
);
});
}