Skip to content
Open
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
80 changes: 51 additions & 29 deletions lib/dialog/multi_select_dialog_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
final BoxDecoration? decoration;

/// Set text that is displayed on the button.
final Text? buttonText;
final Widget? buttonText;

/// Specify the button icon.
final Icon? buttonIcon;
Expand Down Expand Up @@ -100,6 +100,12 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
/// Whether the user can dismiss the widget by tapping outside
final bool isDismissible;

/// Whether the field is enabled
final bool enabled;

/// Style the Container when the field is disabled
final BoxDecoration? disabledDecoration;

final AutovalidateMode autovalidateMode;
final FormFieldValidator<List<V>>? validator;
final FormFieldSetter<List<V>>? onSaved;
Expand Down Expand Up @@ -136,6 +142,8 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
this.separateSelectedItems = false,
this.checkColor,
this.isDismissible = true,
this.enabled = true,
this.disabledDecoration,
this.onSaved,
this.validator,
this.initialValue = const [],
Expand Down Expand Up @@ -180,6 +188,8 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
separateSelectedItems: separateSelectedItems,
checkColor: checkColor,
isDismissible: isDismissible,
enabled: enabled,
disabledDecoration: disabledDecoration,
);
return _MultiSelectDialogFieldView<V>._withState(field, state);
});
Expand All @@ -189,7 +199,7 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
class _MultiSelectDialogFieldView<V> extends StatefulWidget {
final MultiSelectListType? listType;
final BoxDecoration? decoration;
final Text? buttonText;
final Widget? buttonText;
final Icon? buttonIcon;
final Widget? title;
final List<MultiSelectItem<V>> items;
Expand Down Expand Up @@ -217,6 +227,8 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
final bool separateSelectedItems;
final Color? checkColor;
final bool isDismissible;
final bool enabled;
final BoxDecoration? disabledDecoration;
FormFieldState<List<V>>? state;

_MultiSelectDialogFieldView({
Expand Down Expand Up @@ -250,6 +262,8 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
this.separateSelectedItems = false,
this.checkColor,
required this.isDismissible,
required this.enabled,
this.disabledDecoration,
});

/// This constructor allows a FormFieldState to be passed in. Called by MultiSelectDialogField.
Expand Down Expand Up @@ -285,6 +299,8 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
separateSelectedItems = field.separateSelectedItems,
checkColor = field.checkColor,
isDismissible = field.isDismissible,
enabled = field.enabled,
disabledDecoration = field.disabledDecoration,
state = state;

@override
Expand Down Expand Up @@ -422,33 +438,39 @@ class __MultiSelectDialogFieldViewState<V>
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
InkWell(
onTap: () {
_showDialog(context);
},
onTap: !widget.enabled
? null
: () {
_showDialog(context);
},
child: Container(
decoration: widget.state != null
? widget.decoration ??
BoxDecoration(
border: Border(
bottom: BorderSide(
color: widget.state != null && widget.state!.hasError
? Colors.red.shade800.withOpacity(0.6)
: _selectedItems.isNotEmpty
? (widget.selectedColor != null &&
widget.selectedColor !=
Colors.transparent)
? widget.selectedColor!
: Theme.of(context).primaryColor
: Colors.black45,
width: _selectedItems.isNotEmpty
? (widget.state != null && widget.state!.hasError)
? 1.4
: 1.8
: 1.2,
),
),
)
: widget.decoration,
decoration: !widget.enabled && widget.disabledDecoration != null
? widget.disabledDecoration
: widget.state != null
? widget.decoration ??
BoxDecoration(
border: Border(
bottom: BorderSide(
color:
widget.state != null && widget.state!.hasError
? Colors.red.shade800.withOpacity(0.6)
: _selectedItems.isNotEmpty
? (widget.selectedColor != null &&
widget.selectedColor !=
Colors.transparent)
? widget.selectedColor!
: Theme.of(context).primaryColor
: Colors.black45,
width: _selectedItems.isNotEmpty
? (widget.state != null &&
widget.state!.hasError)
? 1.4
: 1.8
: 1.2,
),
),
)
: widget.decoration,
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down Expand Up @@ -482,4 +504,4 @@ class __MultiSelectDialogFieldViewState<V>
],
);
}
}
}