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

Issue 45 #46

Merged
merged 2 commits into from
Jul 16, 2021
Merged
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
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