PromptedChoice<T>.multiple constructor

const PromptedChoice<T>.multiple({
  1. Key? key,
  2. String? title,
  3. bool clearable = false,
  4. bool confirmation = false,
  5. bool loading = false,
  6. bool error = false,
  7. List<T> value = const [],
  8. ValueChanged<List<T>>? onChanged,
  9. required int itemCount,
  10. required IndexedChoiceStateBuilder<T> itemBuilder,
  11. ChoiceSkipResolver<T>? itemSkip,
  12. ChoiceGroupResolver? itemGroup,
  13. ChoiceStateBuilder<T>? dividerBuilder,
  14. ChoiceStateBuilder<T>? leadingBuilder,
  15. ChoiceStateBuilder<T>? trailingBuilder,
  16. ChoiceStateBuilder<T>? placeholderBuilder,
  17. ChoiceStateBuilder<T>? errorBuilder,
  18. ChoiceStateBuilder<T>? loaderBuilder,
  19. ChoiceGroupSortResolver? groupSort,
  20. ChoiceGroupBuilder? groupBuilder,
  21. ChoiceGroupItemBuilder? groupItemBuilder,
  22. ChoiceGroupHeaderBuilder<T>? groupHeaderBuilder,
  23. ChoiceListBuilder? listBuilder,
  24. ChoiceStateBuilder<T>? modalHeaderBuilder,
  25. ChoiceStateBuilder<T>? modalFooterBuilder,
  26. ChoiceStateBuilder<T>? modalSeparatorBuilder,
  27. FlexFit modalFit = FlexFit.loose,
  28. ChoicePromptBuilder<T>? anchorBuilder,
  29. ChoicePromptDelegate<T>? promptDelegate,
  30. bool searchable = false,
  31. ValueSetter<String>? onSearch,
})

Create prompted choice widget with multiple selection

The value prop is the initial selection value

The onChanged prop called when the choice selection should change

The clearable prop determines whether the choice can be cleared

The confirmation prop specifies whether the choice selection needs to be confirmed

The searchable prop specifies whether the choice can be searched

The title prop is primary text of the modal and trigger widget

The itemCount prop is the total number of item, this choice list can provide

The itemSkip prop called to specify which indices to skip when building choice item

The itemBuilder prop called to build choice item

The dividerBuilder prop called to build divider item

The leadingBuilder prop called to build leading item of the item collection

The trailingBuilder prop called to build trailing item of the item collection

The placeholderBuilder prop called to build placeholder when there are no choice items

The listBuilder prop called to build the list of choice items

import 'package:flutter/material.dart';
import 'package:choice/choice.dart';

class PromptedBottomSheet extends StatefulWidget {
  const PromptedBottomSheet({super.key});

  @override
  State<PromptedBottomSheet> createState() => _PromptedBottomSheetState();
}

class _PromptedBottomSheetState extends State<PromptedBottomSheet> {
  List<String> choices = [
    'News',
    'Entertainment',
    'Politics',
    'Automotive',
    'Sports',
  ];
  List<String> selectedValue = [];

  void setSelectedValue(List<String> value) {
    setState(() => selectedValue = value);
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 300,
      child: Card(
        margin: const EdgeInsets.symmetric(vertical: 20),
        child: PromptedChoice<String>.multiple(
          title: 'Categories',
          confirmation: true,
          value: selectedValue,
          onChanged: setSelectedValue,
          itemCount: choices.length,
          itemBuilder: (state, i) {
            return CheckboxListTile(
              value: state.selected(choices[i]),
              onChanged: state.onSelected(choices[i]),
              title: ChoiceText(
                choices[i],
                highlight: state.search?.value,
              ),
            );
          },
          modalHeaderBuilder: ChoiceModalHeader.createBuilder(
            automaticallyImplyLeading: false,
            actionsBuilder: [
              ChoiceConfirmButton.createBuilder(),
              ChoiceModal.createBuilder(
                child: const SizedBox(width: 20),
              ),
            ],
          ),
          promptDelegate: ChoicePrompt.delegateBottomSheet(),
        ),
      ),
    );
  }
}

Implementation

const PromptedChoice.multiple({
  super.key,
  this.title,
  this.clearable = false,
  this.confirmation = false,
  this.loading = false,
  this.error = false,
  this.value = const [],
  this.onChanged,
  required this.itemCount,
  required this.itemBuilder,
  this.itemSkip,
  this.itemGroup,
  this.dividerBuilder,
  this.leadingBuilder,
  this.trailingBuilder,
  this.placeholderBuilder,
  this.errorBuilder,
  this.loaderBuilder,
  this.groupSort,
  this.groupBuilder,
  this.groupItemBuilder,
  this.groupHeaderBuilder,
  this.listBuilder,
  this.modalHeaderBuilder,
  this.modalFooterBuilder,
  this.modalSeparatorBuilder,
  this.modalFit = FlexFit.loose,
  this.anchorBuilder,
  this.promptDelegate,
  this.searchable = false,
  this.onSearch,
}) : multiple = true;