diff --git a/lib/dialog/multi_select_dialog_field.dart b/lib/dialog/multi_select_dialog_field.dart index b229a4d..9a40423 100644 --- a/lib/dialog/multi_select_dialog_field.dart +++ b/lib/dialog/multi_select_dialog_field.dart @@ -15,7 +15,7 @@ class MultiSelectDialogField extends FormField> { final BoxDecoration? decoration; /// Set text that is displayed on the button. - final Text? buttonText; + final Widget? buttonText; /// Specify the button icon. final Icon? buttonIcon; @@ -100,6 +100,12 @@ class MultiSelectDialogField extends FormField> { /// 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>? validator; final FormFieldSetter>? onSaved; @@ -136,6 +142,8 @@ class MultiSelectDialogField extends FormField> { this.separateSelectedItems = false, this.checkColor, this.isDismissible = true, + this.enabled = true, + this.disabledDecoration, this.onSaved, this.validator, this.initialValue = const [], @@ -180,6 +188,8 @@ class MultiSelectDialogField extends FormField> { separateSelectedItems: separateSelectedItems, checkColor: checkColor, isDismissible: isDismissible, + enabled: enabled, + disabledDecoration: disabledDecoration, ); return _MultiSelectDialogFieldView._withState(field, state); }); @@ -189,7 +199,7 @@ class MultiSelectDialogField extends FormField> { class _MultiSelectDialogFieldView extends StatefulWidget { final MultiSelectListType? listType; final BoxDecoration? decoration; - final Text? buttonText; + final Widget? buttonText; final Icon? buttonIcon; final Widget? title; final List> items; @@ -217,6 +227,8 @@ class _MultiSelectDialogFieldView extends StatefulWidget { final bool separateSelectedItems; final Color? checkColor; final bool isDismissible; + final bool enabled; + final BoxDecoration? disabledDecoration; FormFieldState>? state; _MultiSelectDialogFieldView({ @@ -250,6 +262,8 @@ class _MultiSelectDialogFieldView 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. @@ -285,6 +299,8 @@ class _MultiSelectDialogFieldView extends StatefulWidget { separateSelectedItems = field.separateSelectedItems, checkColor = field.checkColor, isDismissible = field.isDismissible, + enabled = field.enabled, + disabledDecoration = field.disabledDecoration, state = state; @override @@ -422,33 +438,39 @@ class __MultiSelectDialogFieldViewState mainAxisAlignment: MainAxisAlignment.start, children: [ 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, @@ -482,4 +504,4 @@ class __MultiSelectDialogFieldViewState ], ); } -} +} \ No newline at end of file