Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ class _MyHomePageState extends State<MyHomePage> {
_multiSelectKey.currentState.validate();
},
),
errorDecoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.error,
width: 2,
),
),
),
SizedBox(height: 40),
//################################################################################################
Expand Down
57 changes: 34 additions & 23 deletions lib/bottom_sheet/multi_select_bottom_sheet_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class MultiSelectBottomSheetField<V> extends FormField<List<V>> {
/// Style the Container that makes up the field.
final BoxDecoration? decoration;

/// Style the Container with error state.
final BoxDecoration? errorDecoration;

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

Expand Down Expand Up @@ -120,6 +123,7 @@ class MultiSelectBottomSheetField<V> extends FormField<List<V>> {
this.buttonIcon,
this.listType,
this.decoration,
this.errorDecoration,
this.onSelectionChanged,
this.chipDisplay,
this.initialValue = const [],
Expand Down Expand Up @@ -160,6 +164,7 @@ class MultiSelectBottomSheetField<V> extends FormField<List<V>> {
_MultiSelectBottomSheetFieldView<V>(
items: items,
decoration: decoration,
errorDecoration: errorDecoration,
unselectedColor: unselectedColor,
colorator: colorator,
itemsTextStyle: itemsTextStyle,
Expand Down Expand Up @@ -199,6 +204,7 @@ class MultiSelectBottomSheetField<V> extends FormField<List<V>> {
// ignore: must_be_immutable
class _MultiSelectBottomSheetFieldView<V> extends StatefulWidget {
final BoxDecoration? decoration;
final BoxDecoration? errorDecoration;
final Text? buttonText;
final Icon? buttonIcon;
final List<MultiSelectItem<V>> items;
Expand Down Expand Up @@ -239,6 +245,7 @@ class _MultiSelectBottomSheetFieldView<V> extends StatefulWidget {
this.buttonIcon,
this.listType,
this.decoration,
this.errorDecoration,
this.onSelectionChanged,
this.onConfirm,
this.chipDisplay,
Expand Down Expand Up @@ -276,6 +283,7 @@ class _MultiSelectBottomSheetFieldView<V> extends StatefulWidget {
buttonIcon = field.buttonIcon,
listType = field.listType,
decoration = field.decoration,
errorDecoration = field.errorDecoration,
onSelectionChanged = field.onSelectionChanged,
onConfirm = field.onConfirm,
chipDisplay = field.chipDisplay,
Expand Down Expand Up @@ -439,6 +447,31 @@ class __MultiSelectBottomSheetFieldViewState<V>
_selectedItems = myVar!;
}

_buildContainerDecoration() {
final hasError = widget.state?.hasError ?? false;
final decoration = widget.decoration ??
BoxDecoration(
border: Border(
bottom: BorderSide(
color: 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
? hasError
? 1.4
: 1.8
: 1.2,
),
),
);
return hasError ? widget.errorDecoration ?? decoration : decoration;
}

@override
Widget build(BuildContext context) {
return Column(
Expand All @@ -449,29 +482,7 @@ class __MultiSelectBottomSheetFieldViewState<V>
_showBottomSheet(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: _buildContainerDecoration(),
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down
57 changes: 34 additions & 23 deletions lib/dialog/multi_select_dialog_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
/// Style the Container that makes up the field.
final BoxDecoration? decoration;

/// Style the Container with error state.
final BoxDecoration? errorDecoration;

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

Expand Down Expand Up @@ -114,6 +117,7 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
this.buttonIcon,
this.listType,
this.decoration,
this.errorDecoration,
this.onSelectionChanged,
this.chipDisplay,
this.searchable = false,
Expand Down Expand Up @@ -156,6 +160,7 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
buttonIcon: buttonIcon,
chipDisplay: chipDisplay,
decoration: decoration,
errorDecoration: errorDecoration,
listType: listType,
onConfirm: onConfirm,
onSelectionChanged: onSelectionChanged,
Expand Down Expand Up @@ -189,6 +194,7 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
class _MultiSelectDialogFieldView<V> extends StatefulWidget {
final MultiSelectListType? listType;
final BoxDecoration? decoration;
final BoxDecoration? errorDecoration;
final Text? buttonText;
final Icon? buttonIcon;
final Widget? title;
Expand Down Expand Up @@ -226,6 +232,7 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
this.buttonIcon,
this.listType,
this.decoration,
this.errorDecoration,
this.onSelectionChanged,
this.onConfirm,
this.chipDisplay,
Expand Down Expand Up @@ -261,6 +268,7 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
buttonIcon = field.buttonIcon,
listType = field.listType,
decoration = field.decoration,
errorDecoration = field.errorDecoration,
onSelectionChanged = field.onSelectionChanged,
onConfirm = field.onConfirm,
chipDisplay = field.chipDisplay,
Expand Down Expand Up @@ -416,6 +424,31 @@ class __MultiSelectDialogFieldViewState<V>
);
}

_buildContainerDecoration() {
final hasError = widget.state?.hasError ?? false;
final decoration = widget.decoration ??
BoxDecoration(
border: Border(
bottom: BorderSide(
color: 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
? hasError
? 1.4
: 1.8
: 1.2,
),
),
);
return hasError ? widget.errorDecoration ?? decoration : decoration;
}

@override
Widget build(BuildContext context) {
return Column(
Expand All @@ -426,29 +459,7 @@ class __MultiSelectDialogFieldViewState<V>
_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: _buildContainerDecoration(),
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
Expand Down