Commit 0c916a00 by Rizal Hermawan

custom UI and fix bugs

parent 2b579b79
...@@ -6,6 +6,7 @@ import '../util/multi_select_list_type.dart'; ...@@ -6,6 +6,7 @@ import '../util/multi_select_list_type.dart';
/// A bottom sheet widget containing either a classic checkbox style list, or a chip style list. /// A bottom sheet widget containing either a classic checkbox style list, or a chip style list.
class MultiSelectBottomSheet<V> extends StatefulWidget class MultiSelectBottomSheet<V> extends StatefulWidget
with MultiSelectActions<V> { with MultiSelectActions<V> {
final int validationSelectedLength;
/// List of items to select from. /// List of items to select from.
final List<MultiSelectItem<V>> items; final List<MultiSelectItem<V>> items;
...@@ -79,6 +80,7 @@ class MultiSelectBottomSheet<V> extends StatefulWidget ...@@ -79,6 +80,7 @@ class MultiSelectBottomSheet<V> extends StatefulWidget
MultiSelectBottomSheet({ MultiSelectBottomSheet({
required this.items, required this.items,
required this.initialValue, required this.initialValue,
this.validationSelectedLength = 5,
this.title, this.title,
this.onSelectionChanged, this.onSelectionChanged,
this.onConfirm, this.onConfirm,
...@@ -318,7 +320,7 @@ class _MultiSelectBottomSheetState<V> extends State<MultiSelectBottomSheet<V>> { ...@@ -318,7 +320,7 @@ class _MultiSelectBottomSheetState<V> extends State<MultiSelectBottomSheet<V>> {
child: TextButton( child: TextButton(
onPressed: () { onPressed: () {
widget.onConfirmTap( widget.onConfirmTap(
context, _selectedValues, widget.onConfirm); context, _selectedValues, widget.onConfirm, widget.validationSelectedLength);
}, },
child: widget.confirmText ?? child: widget.confirmText ??
Text( Text(
......
...@@ -132,11 +132,14 @@ class MultiSelectChipDisplay<V> extends StatelessWidget { ...@@ -132,11 +132,14 @@ class MultiSelectChipDisplay<V> extends StatelessWidget {
child: ChoiceChip( child: ChoiceChip(
shape: shape as OutlinedBorder?, shape: shape as OutlinedBorder?,
avatar: icon != null avatar: icon != null
? Icon( ? Padding(
padding: EdgeInsets.only(left: 4.0),
child: Icon(
icon!.icon, icon!.icon,
color: colorator != null && colorator!(item.value) != null color: colorator != null && colorator!(item.value) != null
? colorator!(item.value)!.withOpacity(1) ? colorator!(item.value)!.withOpacity(1)
: icon!.color ?? Theme.of(context).primaryColor, : icon!.color ?? Theme.of(context).primaryColor,
),
) )
: null, : null,
label: Container( label: Container(
...@@ -144,26 +147,11 @@ class MultiSelectChipDisplay<V> extends StatelessWidget { ...@@ -144,26 +147,11 @@ class MultiSelectChipDisplay<V> extends StatelessWidget {
child: Text( child: Text(
item.label, item.label,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: textStyle,
color: colorator != null && colorator!(item.value) != null
? textStyle != null
? textStyle!.color ?? colorator!(item.value)
: colorator!(item.value)
: textStyle != null && textStyle!.color != null
? textStyle!.color
: chipColor != null
? chipColor!.withOpacity(1)
: null,
fontSize: textStyle != null ? textStyle!.fontSize : null,
),
), ),
), ),
selected: items!.contains(item), selected: items!.contains(item),
selectedColor: colorator != null && colorator!(item.value) != null selectedColor: chipColor,
? colorator!(item.value)
: chipColor != null
? chipColor
: Theme.of(context).primaryColor.withOpacity(0.33),
onSelected: (_) { onSelected: (_) {
if (onTap != null) onTap!(item.value); if (onTap != null) onTap!(item.value);
}, },
......
...@@ -5,6 +5,7 @@ import '../util/multi_select_list_type.dart'; ...@@ -5,6 +5,7 @@ import '../util/multi_select_list_type.dart';
/// A dialog containing either a classic checkbox style list, or a chip style list. /// A dialog containing either a classic checkbox style list, or a chip style list.
class MultiSelectDialog<V> extends StatefulWidget with MultiSelectActions<V> { class MultiSelectDialog<V> extends StatefulWidget with MultiSelectActions<V> {
final int validationSelectedLength;
/// List of items to select from. /// List of items to select from.
final List<MultiSelectItem<V>> items; final List<MultiSelectItem<V>> items;
...@@ -75,6 +76,7 @@ class MultiSelectDialog<V> extends StatefulWidget with MultiSelectActions<V> { ...@@ -75,6 +76,7 @@ class MultiSelectDialog<V> extends StatefulWidget with MultiSelectActions<V> {
MultiSelectDialog({ MultiSelectDialog({
required this.items, required this.items,
required this.initialValue, required this.initialValue,
this.validationSelectedLength = 5,
this.title, this.title,
this.onSelectionChanged, this.onSelectionChanged,
this.onConfirm, this.onConfirm,
...@@ -163,25 +165,7 @@ class _MultiSelectDialogState<V> extends State<MultiSelectDialog<V>> { ...@@ -163,25 +165,7 @@ class _MultiSelectDialogState<V> extends State<MultiSelectDialog<V>> {
label: Text( label: Text(
item.label, item.label,
style: _selectedValues.contains(item.value) style: _selectedValues.contains(item.value)
? TextStyle( ? widget.selectedItemsTextStyle
color: widget.colorator != null &&
widget.colorator!(item.value) != null
? widget.selectedItemsTextStyle != null
? widget.selectedItemsTextStyle!.color ??
widget.colorator!(item.value)!.withOpacity(1)
: widget.colorator!(item.value)!.withOpacity(1)
: widget.selectedItemsTextStyle != null
? widget.selectedItemsTextStyle!.color ??
(widget.selectedColor != null
? widget.selectedColor!.withOpacity(1)
: Theme.of(context).primaryColor)
: widget.selectedColor != null
? widget.selectedColor!.withOpacity(1)
: null,
fontSize: widget.selectedItemsTextStyle != null
? widget.selectedItemsTextStyle!.fontSize
: null,
)
: widget.itemsTextStyle, : widget.itemsTextStyle,
), ),
selected: _selectedValues.contains(item.value), selected: _selectedValues.contains(item.value),
...@@ -297,7 +281,7 @@ class _MultiSelectDialogState<V> extends State<MultiSelectDialog<V>> { ...@@ -297,7 +281,7 @@ class _MultiSelectDialogState<V> extends State<MultiSelectDialog<V>> {
), ),
), ),
onPressed: () { onPressed: () {
widget.onConfirmTap(context, _selectedValues, widget.onConfirm); widget.onConfirmTap(context, _selectedValues, widget.onConfirm, widget.validationSelectedLength);
}, },
) )
], ],
......
...@@ -8,18 +8,11 @@ import 'mult_select_dialog.dart'; ...@@ -8,18 +8,11 @@ import 'mult_select_dialog.dart';
/// A customizable InkWell widget that opens the MultiSelectDialog /// A customizable InkWell widget that opens the MultiSelectDialog
// ignore: must_be_immutable // ignore: must_be_immutable
class MultiSelectDialogField<V> extends FormField<List<V>> { class MultiSelectDialogField<V> extends FormField<List<V>> {
final Widget titleForm;
final Widget showModalDialogWidget;
/// An enum that determines which type of list to render. /// An enum that determines which type of list to render.
final MultiSelectListType? listType; final MultiSelectListType? listType;
/// Style the Container that makes up the field.
final BoxDecoration? decoration;
/// Set text that is displayed on the button.
final Text? buttonText;
/// Specify the button icon.
final Icon? buttonIcon;
/// The text at the top of the dialog. /// The text at the top of the dialog.
final Widget? title; final Widget? title;
...@@ -98,13 +91,12 @@ class MultiSelectDialogField<V> extends FormField<List<V>> { ...@@ -98,13 +91,12 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
FormFieldState<List<V>>? state; FormFieldState<List<V>>? state;
MultiSelectDialogField({ MultiSelectDialogField({
required this.titleForm,
required this.showModalDialogWidget,
required this.items, required this.items,
required this.onConfirm, required this.onConfirm,
this.title, this.title,
this.buttonText,
this.buttonIcon,
this.listType, this.listType,
this.decoration,
this.onSelectionChanged, this.onSelectionChanged,
this.chipDisplay, this.chipDisplay,
this.searchable, this.searchable,
...@@ -139,11 +131,10 @@ class MultiSelectDialogField<V> extends FormField<List<V>> { ...@@ -139,11 +131,10 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
_MultiSelectDialogFieldView field = _MultiSelectDialogFieldView field =
_MultiSelectDialogFieldView<V>( _MultiSelectDialogFieldView<V>(
title: title, title: title,
titleForm: titleForm,
showModalDialogWidget: showModalDialogWidget,
items: items, items: items,
buttonText: buttonText,
buttonIcon: buttonIcon,
chipDisplay: chipDisplay, chipDisplay: chipDisplay,
decoration: decoration,
listType: listType, listType: listType,
onConfirm: onConfirm, onConfirm: onConfirm,
onSelectionChanged: onSelectionChanged, onSelectionChanged: onSelectionChanged,
...@@ -166,22 +157,21 @@ class MultiSelectDialogField<V> extends FormField<List<V>> { ...@@ -166,22 +157,21 @@ class MultiSelectDialogField<V> extends FormField<List<V>> {
selectedItemsTextStyle: selectedItemsTextStyle, selectedItemsTextStyle: selectedItemsTextStyle,
checkColor: checkColor, checkColor: checkColor,
); );
return _MultiSelectDialogFieldView<V?>._withState(field as _MultiSelectDialogFieldView<V?>, state); return _MultiSelectDialogFieldView<V>._withState(field as _MultiSelectDialogFieldView<V>, state);
}); });
} }
// ignore: must_be_immutable // ignore: must_be_immutable
class _MultiSelectDialogFieldView<V> extends StatefulWidget { class _MultiSelectDialogFieldView<V> extends StatefulWidget {
final Widget titleForm;
final Widget showModalDialogWidget;
final MultiSelectListType? listType; final MultiSelectListType? listType;
final BoxDecoration? decoration;
final Text? buttonText;
final Icon? buttonIcon;
final Widget? title; final Widget? title;
final List<MultiSelectItem<V>> items; final List<MultiSelectItem<V>> items;
final void Function(List<V>)? onSelectionChanged; final void Function(List<V>)? onSelectionChanged;
final MultiSelectChipDisplay<V>? chipDisplay; final MultiSelectChipDisplay<V>? chipDisplay;
final List<V>? initialValue; final List<V>? initialValue;
final void Function(List<V>)? onConfirm; final void Function(List<V>) onConfirm;
final bool? searchable; final bool? searchable;
final Text? confirmText; final Text? confirmText;
final Text? cancelText; final Text? cancelText;
...@@ -202,14 +192,13 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget { ...@@ -202,14 +192,13 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
FormFieldState<List<V>>? state; FormFieldState<List<V>>? state;
_MultiSelectDialogFieldView({ _MultiSelectDialogFieldView({
required this.titleForm,
required this.showModalDialogWidget,
required this.items, required this.items,
this.title, this.title,
this.buttonText,
this.buttonIcon,
this.listType, this.listType,
this.decoration,
this.onSelectionChanged, this.onSelectionChanged,
this.onConfirm, required this.onConfirm,
this.chipDisplay, this.chipDisplay,
this.initialValue, this.initialValue,
this.searchable, this.searchable,
...@@ -235,11 +224,10 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget { ...@@ -235,11 +224,10 @@ class _MultiSelectDialogFieldView<V> extends StatefulWidget {
_MultiSelectDialogFieldView._withState( _MultiSelectDialogFieldView._withState(
_MultiSelectDialogFieldView<V> field, FormFieldState<List<V>> state) _MultiSelectDialogFieldView<V> field, FormFieldState<List<V>> state)
: items = field.items, : items = field.items,
showModalDialogWidget = field.showModalDialogWidget,
titleForm = field.titleForm,
title = field.title, title = field.title,
buttonText = field.buttonText,
buttonIcon = field.buttonIcon,
listType = field.listType, listType = field.listType,
decoration = field.decoration,
onSelectionChanged = field.onSelectionChanged, onSelectionChanged = field.onSelectionChanged,
onConfirm = field.onConfirm, onConfirm = field.onConfirm,
chipDisplay = field.chipDisplay, chipDisplay = field.chipDisplay,
...@@ -369,7 +357,7 @@ class __MultiSelectDialogFieldViewState<V> ...@@ -369,7 +357,7 @@ class __MultiSelectDialogFieldViewState<V>
widget.state!.didChange(selected); widget.state!.didChange(selected);
} }
_selectedItems = selected; _selectedItems = selected;
if (widget.onConfirm != null) widget.onConfirm!(selected); widget.onConfirm(selected);
}, },
); );
}, },
...@@ -381,64 +369,28 @@ class __MultiSelectDialogFieldViewState<V> ...@@ -381,64 +369,28 @@ class __MultiSelectDialogFieldViewState<V>
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[ children: <Widget>[
InkWell( Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
widget.titleForm,
Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: () { onTap: () {
_showDialog(context); _showDialog(context);
}, },
child: Container( child: widget.showModalDialogWidget
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,
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
widget.buttonText ?? Text("Select"),
widget.buttonIcon ?? Icon(Icons.arrow_downward),
], ],
), ),
),
),
_buildInheritedChipDisplay(), _buildInheritedChipDisplay(),
widget.state != null && widget.state!.hasError
? SizedBox(height: 5)
: Container(),
widget.state != null && widget.state!.hasError
? Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 4),
child: Text(
widget.state!.errorText!,
style: TextStyle(
color: Colors.red[800],
fontSize: 12.5,
),
),
),
],
)
: Container(),
], ],
); );
} }
......
...@@ -21,8 +21,10 @@ class MultiSelectActions<V> { ...@@ -21,8 +21,10 @@ class MultiSelectActions<V> {
/// Pops the dialog from the navigation stack and returns the selected values. /// Pops the dialog from the navigation stack and returns the selected values.
/// Calls the onConfirm function if one was provided. /// Calls the onConfirm function if one was provided.
void onConfirmTap( void onConfirmTap(
BuildContext ctx, List<V> selectedValues, Function(List<V>)? onConfirm) { BuildContext ctx, List<V> selectedValues, Function(List<V>)? onConfirm, int validationSelectedLength) {
if (selectedValues.length <= validationSelectedLength) {
Navigator.pop(ctx, selectedValues); Navigator.pop(ctx, selectedValues);
}
if (onConfirm != null) { if (onConfirm != null) {
onConfirm(selectedValues); onConfirm(selectedValues);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment