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

(Dark mode) Add ability to customize search input decoration scaffold color, search and list background colors #64

Open
wants to merge 6 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
7 changes: 7 additions & 0 deletions .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions lib/country_list_pick.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class CountryListPick extends StatefulWidget {
this.countryBuilder,
this.theme,
this.useUiOverlay = true,
this.useSafeArea = false});
this.useSafeArea = false,
this.rootNavigator = false});

final String? initialSelection;
final ValueChanged<CountryCode?>? onChanged;
Expand All @@ -32,6 +33,7 @@ class CountryListPick extends StatefulWidget {
countryBuilder;
final bool useUiOverlay;
final bool useSafeArea;
final bool rootNavigator;

@override
_CountryListPickState createState() {
Expand Down Expand Up @@ -74,23 +76,23 @@ class _CountryListPickState extends State<CountryListPick> {

void _awaitFromSelectScreen(BuildContext context, PreferredSizeWidget? appBar,
CountryTheme? theme) async {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SelectionList(
elements,
selectedItem,
appBar: widget.appBar ??
AppBar(
backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
title: Text("Select Country"),
),
theme: theme,
countryBuilder: widget.countryBuilder,
useUiOverlay: widget.useUiOverlay,
useSafeArea: widget.useSafeArea,
),
));
final result =
await Navigator.of(context, rootNavigator: widget.rootNavigator)
.push(MaterialPageRoute(
builder: (context) => SelectionList(
elements,
selectedItem,
appBar: widget.appBar ??
AppBar(
backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
title: Text("Select Country"),
),
theme: theme,
countryBuilder: widget.countryBuilder,
useUiOverlay: widget.useUiOverlay,
useSafeArea: widget.useSafeArea,
),
));

setState(() {
selectedItem = result ?? selectedItem;
Expand Down
47 changes: 32 additions & 15 deletions lib/country_selection_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CountryTheme {
final String? searchText;
final String? searchHintText;
final String? lastPickText;
final bool? isShowAlphabet;
final Color? alphabetSelectedBackgroundColor;
final Color? alphabetTextColor;
final Color? alphabetSelectedTextColor;
Expand All @@ -14,20 +15,36 @@ class CountryTheme {
final String? initialSelection;
final bool? showEnglishName;
final Color? labelColor;
final InputDecoration? searchInputDecoration;
final Color? scaffoldColor;
final Color? intialSelectionBackgroundColor;
final TextStyle? intialSelectionTextStyle;
final Color? searchInputBackground;
final TextStyle? searchInputStyle;
final Color? listBackgroundColor;
final TextStyle? listTextStyle;

CountryTheme({
this.labelColor,
this.searchText,
this.searchHintText,
this.lastPickText,
this.alphabetSelectedBackgroundColor,
this.alphabetTextColor,
this.alphabetSelectedTextColor,
this.isShowTitle,
this.isShowFlag,
this.isShowCode,
this.isDownIcon,
this.initialSelection,
this.showEnglishName,
});
CountryTheme(
{this.labelColor,
this.searchText,
this.searchHintText,
this.isShowAlphabet,
this.lastPickText,
this.alphabetSelectedBackgroundColor,
this.alphabetTextColor,
this.alphabetSelectedTextColor,
this.isShowTitle,
this.isShowFlag,
this.isShowCode,
this.isDownIcon,
this.initialSelection,
this.showEnglishName,
this.searchInputDecoration,
this.scaffoldColor,
this.intialSelectionBackgroundColor,
this.intialSelectionTextStyle,
this.searchInputBackground,
this.searchInputStyle,
this.listBackgroundColor,
this.listTextStyle});
}
45 changes: 25 additions & 20 deletions lib/selection_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class _SelectionListState extends State<SelectionList> {
var _itemsizeheight = 50.0;
double _offsetContainer = 0.0;

bool isShow = true;

@override
void initState() {
countries = widget.elements;
Expand Down Expand Up @@ -75,7 +73,7 @@ class _SelectionListState extends State<SelectionList> {
Widget scaffold = Scaffold(
appBar: widget.appBar,
body: Container(
color: Color(0xfff4f4f4),
color: widget.theme?.scaffoldColor ?? Color(0xfff4f4f4),
child: LayoutBuilder(builder: (context, contrainsts) {
diff = height - contrainsts.biggest.height;
_heightscroller = (contrainsts.biggest.height) / _alphabet.length;
Expand All @@ -100,21 +98,24 @@ class _SelectionListState extends State<SelectionList> {
),
),
Container(
color: Colors.white,
color: widget.theme?.searchInputBackground ??
Colors.white,
child: TextField(
controller: _controller,
decoration: InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 0, top: 0, right: 15),
hintText:
widget.theme?.searchHintText ?? "Search...",
),
decoration: widget.theme?.searchInputDecoration ??
InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 0, top: 0, right: 15),
hintText: widget.theme?.searchHintText ??
"Search...",
),
onChanged: _filterElements,
style: widget.theme?.searchInputStyle,
),
),
Padding(
Expand All @@ -127,7 +128,8 @@ class _SelectionListState extends State<SelectionList> {
),
),
Container(
color: Colors.white,
color: widget.theme?.intialSelectionBackgroundColor ??
Colors.white,
child: Material(
color: Colors.transparent,
child: ListTile(
Expand All @@ -136,7 +138,10 @@ class _SelectionListState extends State<SelectionList> {
package: 'country_list_pick',
width: 32.0,
),
title: Text(widget.initialSelection!.name!),
title: Text(
widget.initialSelection!.name!,
style: widget.theme?.intialSelectionTextStyle,
),
trailing: Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Icon(Icons.check, color: Colors.green),
Expand All @@ -158,7 +163,7 @@ class _SelectionListState extends State<SelectionList> {
)
],
),
if (isShow == true)
if (widget.theme?.isShowAlphabet ?? true == true)
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
Expand Down Expand Up @@ -188,7 +193,7 @@ class _SelectionListState extends State<SelectionList> {
Widget getListCountry(CountryCode e) {
return Container(
height: 50,
color: Colors.white,
color: widget.theme?.listBackgroundColor ?? Colors.white,
child: Material(
color: Colors.transparent,
child: ListTile(
Expand All @@ -197,7 +202,7 @@ class _SelectionListState extends State<SelectionList> {
package: 'country_list_pick',
width: 30.0,
),
title: Text(e.name!),
title: Text(e.name!, style: widget.theme?.listTextStyle),
onTap: () {
_sendDataBack(context, e);
},
Expand Down
1 change: 1 addition & 0 deletions lib/support/code_countries_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ List<Map> countriesEnglish = [
{"name": "Eritrea", "dial_code": "+291", "code": "ER"},
{"name": "Estonia", "dial_code": "+372", "code": "EE"},
{"name": "Ethiopia", "dial_code": "+251", "code": "ET"},
{"name": "Europe", "dial_code": "+49", "code": "EU"},
{"name": "Falkland Islands (Malvinas)", "dial_code": "+500", "code": "FK"},
{"name": "Faroe Islands", "dial_code": "+298", "code": "FO"},
{"name": "Fiji", "dial_code": "+679", "code": "FJ"},
Expand Down
5 changes: 5 additions & 0 deletions lib/support/code_countrys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ List<Map<String, String>> codes = [
"code": "ER",
"dial_code": "+291",
},
{
"name": "Europe",
"code": "EU",
"dial_code": "+49",
},
{
"name": "Eesti",
"code": "EE",
Expand Down