Merge pull request #44 from MrRoy121/main

Fixes for Flutter and Dart SDK Updates and Enhancements to Country Code Picker
This commit is contained in:
Chandra Abdul Fattah
2025-01-31 23:19:52 +07:00
committed by GitHub
8 changed files with 136 additions and 144 deletions

View File

@@ -10,6 +10,7 @@ class SelectionDialog extends StatefulWidget {
final InputDecoration searchDecoration;
final TextStyle? searchStyle;
final TextStyle? textStyle;
final TextStyle headerTextStyle;
final BoxDecoration? boxDecoration;
final WidgetBuilder? emptySearchBuilder;
final bool? showFlag;
@@ -19,6 +20,10 @@ class SelectionDialog extends StatefulWidget {
final bool hideSearch;
final bool hideCloseIcon;
final Icon? closeIcon;
final bool hideHeaderText;
final String? headerText;
final EdgeInsets topBarPadding;
final MainAxisAlignment headerAlignment;
/// Background color of SelectionDialog
final Color? backgroundColor;
@@ -38,10 +43,15 @@ class SelectionDialog extends StatefulWidget {
this.favoriteElements, {
Key? key,
this.showCountryOnly,
required this.hideHeaderText,
this.emptySearchBuilder,
required this.headerAlignment,
required this.headerTextStyle,
InputDecoration searchDecoration = const InputDecoration(),
this.searchStyle,
this.textStyle,
required this.topBarPadding,
this.headerText,
this.boxDecoration,
this.showFlag,
this.flagDecoration,
@@ -54,9 +64,7 @@ class SelectionDialog extends StatefulWidget {
this.closeIcon,
this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
}) : searchDecoration = searchDecoration.prefixIcon == null
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
: searchDecoration,
}) : searchDecoration = searchDecoration.prefixIcon == null ? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search)) : searchDecoration,
super(key: key);
@override
@@ -73,8 +81,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
child: Container(
clipBehavior: Clip.hardEdge,
width: widget.size?.width ?? MediaQuery.of(context).size.width,
height:
widget.size?.height ?? MediaQuery.of(context).size.height * 0.85,
height: widget.size?.height ?? MediaQuery.of(context).size.height * 0.85,
decoration: widget.boxDecoration ??
BoxDecoration(
color: widget.backgroundColor ?? Colors.white,
@@ -92,12 +99,27 @@ class _SelectionDialogState extends State<SelectionDialog> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (!widget.hideCloseIcon)
IconButton(
padding: const EdgeInsets.all(0),
iconSize: 20,
icon: widget.closeIcon!,
onPressed: () => Navigator.pop(context),
Padding(
padding:!widget.hideHeaderText? widget.topBarPadding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: widget.headerAlignment,
children: [
!widget.hideHeaderText && widget.headerText != null
? Text(
widget.headerText!,
overflow: TextOverflow.fade,
style: widget.headerTextStyle,
)
: const SizedBox.shrink(),
if (!widget.hideCloseIcon)
IconButton(
padding: const EdgeInsets.all(0),
iconSize: 20,
icon: widget.closeIcon!,
onPressed: () => Navigator.pop(context),
),
],
),
),
if (!widget.hideSearch)
Padding(
@@ -116,34 +138,28 @@ class _SelectionDialogState extends State<SelectionDialog> {
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
...widget.favoriteElements.map(
(f) => InkWell(
...widget.favoriteElements.map((f) => InkWell(
onTap: () {
_selectItem(f);
},
child: Padding(
padding: widget.dialogItemPadding,
child: _buildOption(f),
)
)
),
))),
const Divider(),
],
),
if (filteredElements.isEmpty)
_buildEmptySearchWidget(context)
else
...filteredElements.map(
(e) => InkWell(
...filteredElements.map((e) => InkWell(
onTap: () {
_selectItem(e);
},
child: Padding(
padding: widget.dialogItemPadding,
padding: widget.dialogItemPadding,
child: _buildOption(e),
)
)
),
))),
],
),
),
@@ -161,10 +177,11 @@ class _SelectionDialogState extends State<SelectionDialog> {
if (widget.showFlag!)
Flexible(
child: Container(
margin: const EdgeInsets.only(right: 16.0),
margin: Directionality.of(context) == TextDirection.ltr // Here Adding padding depending on the locale language direction
? const EdgeInsets.only(right: 16.0)
: const EdgeInsets.only(left: 16.0),
decoration: widget.flagDecoration,
clipBehavior:
widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
child: Image.asset(
e.flagUri!,
package: 'country_code_picker',
@@ -175,9 +192,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
Expanded(
flex: 4,
child: Text(
widget.showCountryOnly!
? e.toCountryStringOnly()
: e.toLongString(),
widget.showCountryOnly! ? e.toCountryStringOnly() : e.toLongString(),
overflow: TextOverflow.fade,
style: widget.textStyle,
),
@@ -193,8 +208,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
}
return Center(
child: Text(CountryLocalizations.of(context)?.translate('no_country') ??
'No country found'),
child: Text(CountryLocalizations.of(context)?.translate('no_country') ?? 'No country found'),
);
}
@@ -207,12 +221,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
void _filterElements(String s) {
s = s.toUpperCase();
setState(() {
filteredElements = widget.elements
.where((e) =>
e.code!.contains(s) ||
e.dialCode!.contains(s) ||
e.name!.toUpperCase().contains(s))
.toList();
filteredElements = widget.elements.where((e) => e.code!.contains(s) || e.dialCode!.contains(s) || e.name!.toUpperCase().contains(s)).toList();
});
}