Choice<T>.prompt constructor
- Key? key,
- List<
T> value = const [], - ValueChanged<
List< ? onChanged,T> > - String? title,
- bool multiple = false,
- bool clearable = false,
- bool confirmation = false,
- bool loading = false,
- bool error = false,
- required int itemCount,
- required IndexedChoiceStateBuilder<
T> itemBuilder, - ChoiceGroupResolver? itemGroup,
- ChoiceSkipResolver<
T> ? itemSkip, - 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 single or 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 multiple prop determines whether the choice is multiple or single selection
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
The modalBodyBuilder
prop called to build modal body widget
The modalHeaderBuilder
prop called to build modal header widget
The modalFooterBuilder
prop called to build modal footer widget
The modalSeparatorBuilder
prop called to build modal separator widget
The modalFit
prop is how a flexible modal body is inscribed into the available space.
The anchorBuilder
prop called to build trigger widget to invoke modal prompt
The promptDelegate
prop called to specify ways to invoke modal prompt
A StatefulWidget that illustrates use of an Choice.prompt usage.
import 'package:flutter/material.dart';
import 'package:choice/choice.dart';
class PromptedPopupDialog extends StatefulWidget {
const PromptedPopupDialog({super.key});
@override
State<PromptedPopupDialog> createState() => _PromptedPopupDialogState();
}
class _PromptedPopupDialogState extends State<PromptedPopupDialog> {
List<String> choices = [
'News',
'Entertainment',
'Politics',
'Automotive',
'Sports',
'Education',
];
String? selectedValue;
void setSelectedValue(String? value) {
setState(() => selectedValue = value);
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: 300,
child: Card(
clipBehavior: Clip.antiAlias,
child: Choice<String>.prompt(
title: 'Category',
value: selectedValue,
onChanged: setSelectedValue,
itemCount: choices.length,
itemBuilder: (state, i) {
return RadioListTile(
value: choices[i],
groupValue: state.single,
onChanged: (value) {
state.select(choices[i]);
},
title: ChoiceText(
choices[i],
highlight: state.search?.value,
),
);
},
promptDelegate: ChoicePrompt.delegatePopupDialog(
maxHeightFactor: .5,
constraints: const BoxConstraints(maxWidth: 300),
),
anchorBuilder: ChoiceAnchor.create(inline: true),
),
),
);
}
}
Implementation
Choice.prompt({
super.key,
this.value = const [],
this.onChanged,
this.title,
this.multiple = false,
this.clearable = false,
this.confirmation = false,
bool loading = false,
bool error = false,
required int itemCount,
required IndexedChoiceStateBuilder<T> itemBuilder,
ChoiceGroupResolver? itemGroup,
ChoiceSkipResolver<T>? itemSkip,
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>? modalFooterBuilder,
ChoiceStateBuilder<T>? modalSeparatorBuilder,
FlexFit modalFit = FlexFit.loose,
ChoicePromptBuilder<T>? anchorBuilder,
ChoicePromptDelegate<T>? promptDelegate,
bool searchable = false,
ValueSetter<String>? onSearch,
}) : child = PromptedChoice<T>(
value: value,
onChanged: onChanged,
title: title,
multiple: multiple,
clearable: clearable,
confirmation: confirmation,
loading: loading,
error: error,
itemCount: itemCount,
itemBuilder: itemBuilder,
itemGroup: itemGroup,
itemSkip: itemSkip,
dividerBuilder: dividerBuilder,
leadingBuilder: leadingBuilder,
trailingBuilder: trailingBuilder,
placeholderBuilder: placeholderBuilder,
errorBuilder: errorBuilder,
loaderBuilder: loaderBuilder,
groupSort: groupSort,
groupBuilder: groupBuilder,
groupItemBuilder: groupItemBuilder,
groupHeaderBuilder: groupHeaderBuilder,
listBuilder: listBuilder,
modalHeaderBuilder: modalHeaderBuilder,
modalFooterBuilder: modalFooterBuilder,
modalSeparatorBuilder: modalSeparatorBuilder,
modalFit: modalFit,
anchorBuilder: anchorBuilder,
promptDelegate: promptDelegate,
searchable: searchable,
onSearch: onSearch,
);