DocumentationSelect Group
Select Group
A set of items that are treated as a single selection.
enum Sidebar { recents, home, applications }
FSelectGroup(
controller: FMultiSelectGroupController(values: {Sidebar.recents}),
label: const Text('Sidebar'),
description: const Text('These will be shown in the sidebar.'),
items: [
FSelectGroupItem.checkbox(
value: Sidebar.recents,
label: const Text('Recents'),
),
FSelectGroupItem.checkbox(
value: Sidebar.home,
label: const Text('Home'),
),
FSelectGroupItem.checkbox(
value: Sidebar.applications,
label: const Text('Applications'),
),
],
);
Usage
FSelectGroup(...)
FSelectGroup(
controller: FMultiSelectGroupController(), // or FRadioSelectGroupController()
label: const Text('Sidebar'),
description: const Text('Select the items you want to display in the sidebar.'),
items: [
FSelectGroupItem.checkbox(
value: Value.checkbox,
label: const Text('Checkbox'),
),
// or
FSelectGroupItem.radio(
value: Value.radio,
label: const Text('Radio'),
),
],
);
Examples
Checkbox Form
enum Language { dart, java, rust, python }
class CheckboxForm extends StatefulWidget {
const CheckboxForm({super.key});
@override
State<CheckboxForm> createState() => CheckboxFormState();
}
class CheckboxFormState extends State<CheckboxForm> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) => Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FSelectGroup(
controller: FMultiSelectGroupController(),
label: const Text('Favorite Languages'),
description: const Text('Your favorite language.'),
validator: (values) => values?.isEmpty ?? true ? 'Please select at least one language.' : null,
items: [
FSelectGroupItem.checkbox(
value: Language.dart,
label: const Text('Dart'),
),
FSelectGroupItem.checkbox(
value: Language.java,
label: const Text('Java'),
),
FSelectGroupItem.checkbox(
value: Language.rust,
label: const Text('Rust'),
),
FSelectGroupItem.checkbox(
value: Language.python,
label: const Text('Python'),
),
],
),
const SizedBox(height: 20),
FButton(
label: const Text('Submit'),
onPress: () {
if (!_formKey.currentState!.validate()) {
// Handle errors here.
return;
}
_formKey.currentState!.save();
// Do something.
},
),
],
),
);
}
Radio Form
enum Notification { all, direct, nothing }
class RadioForm extends StatefulWidget {
const RadioForm({super.key});
@override
State<RadioForm> createState() => RadioFormState();
}
class RadioFormState extends State<RadioForm> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) => Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FSelectGroup(
controller: FRadioSelectGroupController(),
label: const Text('Notifications'),
description: const Text('Select the notifications.'),
validator: (values) => values?.isEmpty ?? true ? 'Please select a value.' : null,
items: [
FSelectGroupItem.radio(
value: Notification.all,
label: const Text('All new messages'),
),
FSelectGroupItem.radio(
value: Notification.direct,
label: const Text('Direct messages and mentions'),
),
FSelectGroupItem.radio(
value: Notification.nothing,
label: const Text('Nothing'),
),
],
),
const SizedBox(height: 20),
FButton(
label: const Text('Save'),
onPress: () {
if (!_formKey.currentState!.validate()) {
// Handle errors here.
return;
}
_formKey.currentState!.save();
// Do something.
},
),
],
),
);
}