Merge branch 'main' into main
This commit is contained in:
@@ -23,6 +23,7 @@ class CountryCodePicker extends StatefulWidget {
|
||||
final List<String> favorite;
|
||||
final TextStyle? textStyle;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final EdgeInsetsGeometry? margin;
|
||||
final bool showCountryOnly;
|
||||
final InputDecoration searchDecoration;
|
||||
final TextStyle? searchStyle;
|
||||
@@ -82,6 +83,9 @@ class CountryCodePicker extends StatefulWidget {
|
||||
/// Set to true if you want to hide the search part
|
||||
final bool hideSearch;
|
||||
|
||||
/// Set to true if you want to hide the close icon dialog
|
||||
final bool hideCloseIcon;
|
||||
|
||||
/// Set to true if you want to show drop down button
|
||||
final bool showDropDownButton;
|
||||
|
||||
@@ -92,6 +96,25 @@ class CountryCodePicker extends StatefulWidget {
|
||||
/// with customized codes.
|
||||
final List<Map<String, String>> countryList;
|
||||
|
||||
final EdgeInsetsGeometry dialogItemPadding;
|
||||
|
||||
final EdgeInsetsGeometry searchPadding;
|
||||
|
||||
///Use This To Hide The Header Text
|
||||
final bool hideHeaderText;
|
||||
|
||||
///Change The Header Text
|
||||
final String? headerText;
|
||||
|
||||
///Header Text Style
|
||||
final TextStyle headerTextStyle;
|
||||
|
||||
///Header Text Padding
|
||||
final EdgeInsets topBarPadding;
|
||||
|
||||
///Header Text Alignment
|
||||
final MainAxisAlignment headerAlignment;
|
||||
|
||||
const CountryCodePicker({
|
||||
this.onChanged,
|
||||
this.onInit,
|
||||
@@ -99,6 +122,7 @@ class CountryCodePicker extends StatefulWidget {
|
||||
this.favorite = const [],
|
||||
this.textStyle,
|
||||
this.padding = const EdgeInsets.all(8.0),
|
||||
this.margin,
|
||||
this.showCountryOnly = false,
|
||||
this.searchDecoration = const InputDecoration(),
|
||||
this.searchStyle,
|
||||
@@ -121,12 +145,20 @@ class CountryCodePicker extends StatefulWidget {
|
||||
this.comparator,
|
||||
this.countryFilter,
|
||||
this.hideSearch = false,
|
||||
this.hideCloseIcon = false,
|
||||
this.showDropDownButton = false,
|
||||
this.dialogSize,
|
||||
this.dialogBackgroundColor,
|
||||
this.closeIcon = const Icon(Icons.close),
|
||||
this.countryList = codes,
|
||||
this.pickerStyle = PickerStyle.dialog,
|
||||
this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
|
||||
this.headerAlignment = MainAxisAlignment.spaceBetween,
|
||||
this.headerText = "Select County",
|
||||
this.headerTextStyle = const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
this.hideHeaderText = false,
|
||||
this.topBarPadding = const EdgeInsets.symmetric(vertical: 5.0, horizontal: 20),
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@@ -135,22 +167,15 @@ class CountryCodePicker extends StatefulWidget {
|
||||
State<StatefulWidget> createState() {
|
||||
List<Map<String, String>> jsonList = countryList;
|
||||
|
||||
List<CountryCode> elements =
|
||||
jsonList.map((json) => CountryCode.fromJson(json)).toList();
|
||||
List<CountryCode> elements = jsonList.map((json) => CountryCode.fromJson(json)).toList();
|
||||
|
||||
if (comparator != null) {
|
||||
elements.sort(comparator);
|
||||
}
|
||||
|
||||
if (countryFilter != null && countryFilter!.isNotEmpty) {
|
||||
final uppercaseCustomList =
|
||||
countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
|
||||
elements = elements
|
||||
.where((criteria) =>
|
||||
uppercaseCustomList.contains(criteria.code) ||
|
||||
uppercaseCustomList.contains(criteria.name) ||
|
||||
uppercaseCustomList.contains(criteria.dialCode))
|
||||
.toList();
|
||||
final uppercaseCustomList = countryFilter!.map((criteria) => criteria.toUpperCase()).toList();
|
||||
elements = elements.where((criteria) => uppercaseCustomList.contains(criteria.code) || uppercaseCustomList.contains(criteria.name) || uppercaseCustomList.contains(criteria.dialCode)).toList();
|
||||
}
|
||||
|
||||
return CountryCodePickerState(elements, pickerStyle);
|
||||
@@ -172,7 +197,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
internalWidget = InkWell(
|
||||
onTap: pickerStyle == PickerStyle.dialog
|
||||
? showCountryCodePickerDialog
|
||||
: showCountryCodePickerBottomSheet,
|
||||
: showCountryCodePickerBottomSheet
|
||||
child: widget.builder!(selectedItem),
|
||||
);
|
||||
} else {
|
||||
@@ -188,20 +213,14 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
direction: Axis.horizontal,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
if (widget.showFlagMain != null
|
||||
? widget.showFlagMain!
|
||||
: widget.showFlag)
|
||||
if (widget.showFlagMain != null ? widget.showFlagMain! : widget.showFlag)
|
||||
Flexible(
|
||||
flex: widget.alignLeft ? 0 : 1,
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Container(
|
||||
clipBehavior: widget.flagDecoration == null
|
||||
? Clip.none
|
||||
: Clip.hardEdge,
|
||||
clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
|
||||
decoration: widget.flagDecoration,
|
||||
margin: widget.alignLeft
|
||||
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
||||
: const EdgeInsets.only(right: 16.0),
|
||||
margin: widget.margin ?? (widget.alignLeft ? const EdgeInsets.only(right: 16.0, left: 8.0) : const EdgeInsets.only(right: 16.0)),
|
||||
child: Image.asset(
|
||||
selectedItem!.flagUri!,
|
||||
package: 'country_code_picker',
|
||||
@@ -213,11 +232,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
Flexible(
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Text(
|
||||
widget.showOnlyCountryWhenClosed
|
||||
? selectedItem!.toCountryStringOnly()
|
||||
: selectedItem.toString(),
|
||||
style: widget.textStyle ??
|
||||
Theme.of(context).textTheme.labelLarge,
|
||||
widget.showOnlyCountryWhenClosed ? selectedItem!.toCountryStringOnly() : selectedItem.toString(),
|
||||
style: widget.textStyle ?? Theme.of(context).textTheme.labelLarge,
|
||||
overflow: widget.textOverflow,
|
||||
),
|
||||
),
|
||||
@@ -226,9 +242,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
flex: widget.alignLeft ? 0 : 1,
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Padding(
|
||||
padding: widget.alignLeft
|
||||
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
||||
: const EdgeInsets.only(right: 16.0),
|
||||
padding: (widget.alignLeft ? const EdgeInsets.only(right: 16.0, left: 8.0) : const EdgeInsets.only(right: 16.0)),
|
||||
child: Icon(
|
||||
Icons.arrow_drop_down,
|
||||
color: Colors.grey,
|
||||
@@ -259,11 +273,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
if (widget.initialSelection != null) {
|
||||
selectedItem = elements.firstWhere(
|
||||
(criteria) =>
|
||||
(criteria.code!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()) ||
|
||||
(criteria.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
|
||||
(criteria.dialCode == widget.initialSelection) ||
|
||||
(criteria.name!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()),
|
||||
(criteria.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
|
||||
orElse: () => elements[0]);
|
||||
} else {
|
||||
selectedItem = elements[0];
|
||||
@@ -279,11 +291,9 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
if (widget.initialSelection != null) {
|
||||
selectedItem = elements.firstWhere(
|
||||
(item) =>
|
||||
(item.code!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()) ||
|
||||
(item.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
|
||||
(item.dialCode == widget.initialSelection) ||
|
||||
(item.name!.toUpperCase() ==
|
||||
widget.initialSelection!.toUpperCase()),
|
||||
(item.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
|
||||
orElse: () => elements[0]);
|
||||
} else {
|
||||
selectedItem = elements[0];
|
||||
@@ -291,10 +301,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
|
||||
favoriteElements = elements
|
||||
.where((item) =>
|
||||
widget.favorite.firstWhereOrNull((criteria) =>
|
||||
item.code!.toUpperCase() == criteria.toUpperCase() ||
|
||||
item.dialCode == criteria ||
|
||||
item.name!.toUpperCase() == criteria.toUpperCase()) !=
|
||||
widget.favorite.firstWhereOrNull((criteria) => item.code!.toUpperCase() == criteria.toUpperCase() || item.dialCode == criteria || item.name!.toUpperCase() == criteria.toUpperCase()) !=
|
||||
null)
|
||||
.toList();
|
||||
}
|
||||
@@ -317,11 +324,19 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
showFlag: widget.showFlagDialog ?? widget.showFlag,
|
||||
flagWidth: widget.flagWidth,
|
||||
size: widget.dialogSize,
|
||||
headerAlignment: widget.headerAlignment,
|
||||
headerText: widget.headerText,
|
||||
headerTextStyle: widget.headerTextStyle,
|
||||
hideHeaderText: widget.hideHeaderText,
|
||||
topBarPadding: widget.topBarPadding,
|
||||
backgroundColor: widget.dialogBackgroundColor,
|
||||
barrierColor: widget.barrierColor,
|
||||
hideSearch: widget.hideSearch,
|
||||
hideCloseIcon: widget.hideCloseIcon,
|
||||
closeIcon: widget.closeIcon,
|
||||
flagDecoration: widget.flagDecoration,
|
||||
dialogItemPadding: widget.dialogItemPadding,
|
||||
searchPadding: widget.searchPadding,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user