showMaterialCheckboxPicker function

void showMaterialCheckboxPicker({
  1. required BuildContext context,
  2. String? title,
  3. required List<String> items,
  4. List<String>? values,
  5. List<String>? selectedValues,
  6. Color? headerColor,
  7. Color? headerTextColor,
  8. Color? backgroundColor,
  9. Color? buttonTextColor,
  10. String? confirmText,
  11. String? cancelText,
  12. double? maxLongSide,
  13. double? maxShortSide,
  14. ValueChanged<List<String>>? onChanged,
  15. VoidCallback? onConfirmed,
  16. VoidCallback? onCancelled,
})

Allows selection of many values from a checkbox list.

Implementation

void showMaterialCheckboxPicker({
  required BuildContext context,
  String? title,
  required List<String> items,
  List<String>? values,
  List<String>? selectedValues,
  Color? headerColor,
  Color? headerTextColor,
  Color? backgroundColor,
  Color? buttonTextColor,
  String? confirmText,
  String? cancelText,
  double? maxLongSide,
  double? maxShortSide,
  ValueChanged<List<String>>? onChanged,
  VoidCallback? onConfirmed,
  VoidCallback? onCancelled,
}) {
  assert(values == null || items.length == values.length);

  if (values == null) values = items;

  showDialog<List<String>>(
    context: context,
    builder: (BuildContext context) {
      return CheckboxPickerDialog(
        title: title,
        items: items,
        values: values!,
        initialValues: selectedValues,
        headerColor: headerColor,
        headerTextColor: headerTextColor,
        backgroundColor: backgroundColor,
        buttonTextColor: buttonTextColor,
        confirmText: confirmText,
        cancelText: cancelText,
        maxLongSide: maxLongSide,
        maxShortSide: maxLongSide,
      );
    },
  ).then((selection) {
    if (onChanged != null && selection != null) onChanged(selection);
    if (onCancelled != null && selection == null) onCancelled();
    if (onConfirmed != null && selection != null) onConfirmed();
  });
}