PromptedChoice<T>.multiple constructor
- Key? key,
- String? title,
- bool clearable = false,
- bool confirmation = false,
- bool loading = false,
- bool error = false,
- List<
T> value = const [], - ValueChanged<
List< ? onChanged,T> > - required int itemCount,
- required IndexedChoiceStateBuilder<
T> itemBuilder, - ChoiceSkipResolver<
T> ? itemSkip, - ChoiceGroupResolver? itemGroup,
- ChoiceStateBuilder<
T> ? dividerBuilder, - ChoiceStateBuilder<
T> ? leadingBuilder, - ChoiceStateBuilder<
T> ? trailingBuilder, - ChoiceStateBuilder<
T> ? placeholderBuilder, - ChoiceStateBuilder<
T> ? errorBuilder, - ChoiceStateBuilder<
T> ? loaderBuilder, - ChoiceGroupSortResolver? groupSort,
- ChoiceGroupBuilder? groupBuilder,
- ChoiceGroupItemBuilder? groupItemBuilder,
- ChoiceGroupHeaderBuilder<
T> ? groupHeaderBuilder, - ChoiceListBuilder? listBuilder,
- ChoiceStateBuilder<
T> ? modalHeaderBuilder, - ChoiceStateBuilder<
T> ? modalSeparatorBuilder, - FlexFit modalFit = FlexFit.loose,
- ChoicePromptBuilder<
T> ? anchorBuilder, - ChoicePromptDelegate<
T> ? promptDelegate, - bool searchable = false,
- 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;