Skip to content

Commit

Permalink
feat: add ability to customise search delegate app bar theme (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidlatau authored Feb 2, 2024
1 parent 3ba04e3 commit 823bd7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/src/widgets/country_selector/country_selector_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ abstract class CountrySelectorNavigator {
TextStyle? searchBoxTextStyle,
Color? searchBoxIconColor,
ScrollPhysics? scrollPhysics,
ThemeData? appBarTheme,
}) = SearchDelegateNavigator._;

const factory CountrySelectorNavigator.bottomSheet({
Expand Down Expand Up @@ -211,25 +212,30 @@ class SearchDelegateNavigator extends CountrySelectorNavigator {
super.searchBoxTextStyle,
super.searchBoxIconColor,
super.scrollPhysics,
this.appBarTheme,
});

final ThemeData? appBarTheme;

CountrySelectorSearchDelegate _getCountrySelectorSearchDelegate({
required ValueChanged<Country> onCountrySelected,
required FlagCache flagCache,
ScrollController? scrollController,
}) {
return CountrySelectorSearchDelegate(
onCountrySelected: onCountrySelected,
scrollController: scrollController,
addFavoritesSeparator: addSeparator,
countries: countries,
favoriteCountries: favorites ?? [],
noResultMessage: noResultMessage,
searchAutofocus: searchAutofocus,
showCountryCode: showCountryCode,
titleStyle: titleStyle,
subtitleStyle: subtitleStyle,
flagCache: flagCache);
onCountrySelected: onCountrySelected,
scrollController: scrollController,
addFavoritesSeparator: addSeparator,
countries: countries,
favoriteCountries: favorites ?? [],
noResultMessage: noResultMessage,
searchAutofocus: searchAutofocus,
showCountryCode: showCountryCode,
titleStyle: titleStyle,
subtitleStyle: subtitleStyle,
flagCache: flagCache,
customAppBarTheme: appBarTheme,
);
}

@override
Expand Down
9 changes: 9 additions & 0 deletions lib/src/widgets/country_selector/country_selector_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class CountrySelectorSearchDelegate extends SearchDelegate<Country> {

final FlagCache? flagCache;

/// Override default app bar theme
final ThemeData? customAppBarTheme;

CountrySelectorSearchDelegate({
Key? key,
required this.onCountrySelected,
Expand All @@ -73,6 +76,7 @@ class CountrySelectorSearchDelegate extends SearchDelegate<Country> {
this.flagSize = 40,
this.titleStyle,
this.subtitleStyle,
this.customAppBarTheme,
}) : countriesIso = countries ?? IsoCode.values,
favoriteCountriesIso = favoriteCountries;

Expand Down Expand Up @@ -140,4 +144,9 @@ class CountrySelectorSearchDelegate extends SearchDelegate<Country> {
Widget buildResults(BuildContext context) {
return buildSuggestions(context);
}

@override
ThemeData appBarTheme(BuildContext context) {
return customAppBarTheme ?? super.appBarTheme(context);
}
}

0 comments on commit 823bd7d

Please sign in to comment.