Merge pull request #18 from juanmartin8a/custom-dialog-padding

Custom search bar padding and dialog item padding
This commit is contained in:
Chandra Abdul Fattah
2023-10-20 10:08:19 +07:00
committed by GitHub
2 changed files with 29 additions and 9 deletions

View File

@@ -88,6 +88,10 @@ class CountryCodePicker extends StatefulWidget {
/// with customized codes. /// with customized codes.
final List<Map<String, String>> countryList; final List<Map<String, String>> countryList;
final EdgeInsetsGeometry dialogItemPadding;
final EdgeInsetsGeometry searchPadding;
const CountryCodePicker({ const CountryCodePicker({
this.onChanged, this.onChanged,
this.onInit, this.onInit,
@@ -123,6 +127,8 @@ class CountryCodePicker extends StatefulWidget {
this.dialogBackgroundColor, this.dialogBackgroundColor,
this.closeIcon = const Icon(Icons.close), this.closeIcon = const Icon(Icons.close),
this.countryList = codes, this.countryList = codes,
this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@@ -312,6 +318,8 @@ class CountryCodePickerState extends State<CountryCodePicker> {
hideCloseIcon: widget.hideCloseIcon, hideCloseIcon: widget.hideCloseIcon,
closeIcon: widget.closeIcon, closeIcon: widget.closeIcon,
flagDecoration: widget.flagDecoration, flagDecoration: widget.flagDecoration,
dialogItemPadding: widget.dialogItemPadding,
searchPadding: widget.searchPadding,
), ),
), ),
), ),

View File

@@ -29,6 +29,10 @@ class SelectionDialog extends StatefulWidget {
/// elements passed as favorite /// elements passed as favorite
final List<CountryCode> favoriteElements; final List<CountryCode> favoriteElements;
final EdgeInsetsGeometry dialogItemPadding;
final EdgeInsetsGeometry searchPadding;
SelectionDialog( SelectionDialog(
this.elements, this.elements,
this.favoriteElements, { this.favoriteElements, {
@@ -48,6 +52,8 @@ class SelectionDialog extends StatefulWidget {
this.hideSearch = false, this.hideSearch = false,
this.hideCloseIcon = false, this.hideCloseIcon = false,
this.closeIcon, this.closeIcon,
this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
}) : searchDecoration = searchDecoration.prefixIcon == null }) : searchDecoration = searchDecoration.prefixIcon == null
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search)) ? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
: searchDecoration, : searchDecoration,
@@ -95,7 +101,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
), ),
if (!widget.hideSearch) if (!widget.hideSearch)
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 24), padding: widget.searchPadding,
child: TextField( child: TextField(
style: widget.searchStyle, style: widget.searchStyle,
decoration: widget.searchDecoration, decoration: widget.searchDecoration,
@@ -111,12 +117,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
...widget.favoriteElements.map( ...widget.favoriteElements.map(
(f) => SimpleDialogOption( (f) => InkWell(
child: _buildOption(f), onTap: () {
onPressed: () {
_selectItem(f); _selectItem(f);
}, },
), child: Padding(
padding: widget.dialogItemPadding,
child: _buildOption(f),
)
)
), ),
const Divider(), const Divider(),
], ],
@@ -125,12 +134,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
_buildEmptySearchWidget(context) _buildEmptySearchWidget(context)
else else
...filteredElements.map( ...filteredElements.map(
(e) => SimpleDialogOption( (e) => InkWell(
child: _buildOption(e), onTap: () {
onPressed: () {
_selectItem(e); _selectItem(e);
}, },
), child: Padding(
padding: widget.dialogItemPadding,
child: _buildOption(e),
)
)
), ),
], ],
), ),