Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list header widget #164

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ class HomePage extends StatelessWidget {
fontSize: 18,
),
),
header: Padding(
padding: const EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20.0, right: 20.0),
child: const Text(
'Select your country',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
),
);
},
child: const Text('Show country picker'),
Expand Down
2 changes: 2 additions & 0 deletions lib/country_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void showCountryPicker({
bool useSafeArea = false,
bool useRootNavigator = false,
bool moveAlongWithKeyboard = false,
Widget header = const SizedBox.shrink(),
}) {
assert(
exclude == null || countryFilter == null,
Expand All @@ -87,5 +88,6 @@ void showCountryPicker({
useSafeArea: useSafeArea,
useRootNavigator: useRootNavigator,
moveAlongWithKeyboard: moveAlongWithKeyboard,
header: header,
);
}
50 changes: 25 additions & 25 deletions lib/src/country_list_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,16 @@ void showCountryListBottomSheet({
bool useSafeArea = false,
bool useRootNavigator = false,
bool moveAlongWithKeyboard = false,
Widget header = const SizedBox.shrink(),
}) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
useSafeArea: useSafeArea,
useRootNavigator: useRootNavigator,
builder: (context) => _builder(
context,
onSelect,
favorite,
exclude,
countryFilter,
showPhoneCode,
countryListTheme,
searchAutofocus,
showWorldWide,
showSearch,
moveAlongWithKeyboard,
customFlagBuilder,
),
builder: (context) => _builder(context, onSelect, favorite, exclude, countryFilter, showPhoneCode, countryListTheme,
searchAutofocus, showWorldWide, showSearch, moveAlongWithKeyboard, customFlagBuilder, header),
).whenComplete(() {
if (onClosed != null) onClosed();
});
Expand All @@ -59,6 +48,7 @@ Widget _builder(
bool showSearch,
bool moveAlongWithKeyboard,
CustomFlagBuilder? customFlagBuilder,
Widget header,
) {
final device = MediaQuery.of(context).size.height;
final statusBarHeight = MediaQuery.of(context).padding.top;
Expand Down Expand Up @@ -92,17 +82,27 @@ Widget _builder(
color: _backgroundColor,
borderRadius: _borderRadius,
),
child: CountryListView(
onSelect: onSelect,
exclude: exclude,
favorite: favorite,
countryFilter: countryFilter,
showPhoneCode: showPhoneCode,
countryListTheme: countryListTheme,
searchAutofocus: searchAutofocus,
showWorldWide: showWorldWide,
showSearch: showSearch,
customFlagBuilder: customFlagBuilder,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
child: Column(
children: [
header,
Flexible(
child: CountryListView(
onSelect: onSelect,
exclude: exclude,
favorite: favorite,
countryFilter: countryFilter,
showPhoneCode: showPhoneCode,
countryListTheme: countryListTheme,
searchAutofocus: searchAutofocus,
showWorldWide: showWorldWide,
showSearch: showSearch,
customFlagBuilder: customFlagBuilder,
),
),
],
),
),
),
);
Expand Down
33 changes: 15 additions & 18 deletions lib/src/country_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,23 @@ class _CountryListViewState extends State<CountryListView> {
children: <Widget>[
const SizedBox(height: 12),
if (widget.showSearch)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
child: TextField(
autofocus: _searchAutofocus,
controller: _searchController,
style:
widget.countryListTheme?.searchTextStyle ?? _defaultTextStyle,
decoration: widget.countryListTheme?.inputDecoration ??
InputDecoration(
labelText: searchLabel,
hintText: searchLabel,
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderSide: BorderSide(
color: const Color(0xFF8C98A8).withOpacity(0.2),
),
TextField(
autofocus: _searchAutofocus,
controller: _searchController,
style:
widget.countryListTheme?.searchTextStyle ?? _defaultTextStyle,
decoration: widget.countryListTheme?.inputDecoration ??
InputDecoration(
labelText: searchLabel,
hintText: searchLabel,
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderSide: BorderSide(
color: const Color(0xFF8C98A8).withOpacity(0.2),
),
),
onChanged: _filterSearchResults,
),
),
onChanged: _filterSearchResults,
),
Expanded(
child: ListView(
Expand Down