Skip to content

Commit

Permalink
Merge pull request #46 from MohammadKashaniJabbari/issue45
Browse files Browse the repository at this point in the history
Issue 45
  • Loading branch information
hifiaz authored Jul 16, 2021
2 parents fda5cc4 + fd875dc commit b835621
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _MyAppState extends State<MyApp> {
backgroundColor: Colors.amber,
title: Text('Pick your country'),
),
// if you need custome picker use this
// if you need custom picker use this
// pickerBuilder: (context, CountryCode countryCode) {
// return Row(
// children: [
Expand All @@ -49,6 +49,7 @@ class _MyAppState extends State<MyApp> {
isShowCode: true,
isDownIcon: true,
showEnglishName: false,
labelColor: Colors.blueAccent,
),
initialSelection: '+62',
// or
Expand Down
5 changes: 4 additions & 1 deletion lib/country_list_pick.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CountryListPick extends StatefulWidget {
this.theme,
this.useUiOverlay = true,
this.useSafeArea = false});

final String? initialSelection;
final ValueChanged<CountryCode?>? onChanged;
final PreferredSizeWidget? appBar;
Expand Down Expand Up @@ -52,14 +53,16 @@ class CountryListPick extends StatefulWidget {
class _CountryListPickState extends State<CountryListPick> {
CountryCode? selectedItem;
List elements = [];

_CountryListPickState(this.elements);

@override
void initState() {
if (widget.initialSelection != null) {
selectedItem = elements.firstWhere(
(e) =>
(e.code.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
(e.code.toUpperCase() ==
widget.initialSelection!.toUpperCase()) ||
(e.dialCode == widget.initialSelection),
orElse: () => elements[0] as CountryCode);
} else {
Expand Down
2 changes: 2 additions & 0 deletions lib/country_selection_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class CountryTheme {
final bool? isDownIcon;
final String? initialSelection;
final bool? showEnglishName;
final Color? labelColor;

CountryTheme({
this.labelColor,
this.searchText,
this.searchHintText,
this.lastPickText,
Expand Down
15 changes: 12 additions & 3 deletions lib/selection_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ class _SelectionListState extends State<SelectionList> {
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Text(widget.theme?.searchText ?? 'SEARCH'),
child: Text(
widget.theme?.searchText ?? 'SEARCH',
style: TextStyle(
color:
widget.theme?.labelColor ?? Colors.black),
),
),
Container(
color: Colors.white,
Expand All @@ -116,8 +121,12 @@ class _SelectionListState extends State<SelectionList> {
),
Padding(
padding: const EdgeInsets.all(15.0),
child:
Text(widget.theme?.lastPickText ?? 'LAST PICK'),
child: Text(
widget.theme?.lastPickText ?? 'LAST PICK',
style: TextStyle(
color:
widget.theme?.labelColor ?? Colors.black),
),
),
Container(
color: Colors.white,
Expand Down

0 comments on commit b835621

Please sign in to comment.