Forms
Radio group
A set of mutually exclusive options in a <fieldset>, with a visible legend.
JxRadioGroup
import 'package:jx_cli/ui.dart'
Available since 0.0.2
Preview
When to use it
- Choosing one option among 2 to 5 that should all stay visible.
- Sizes, delivery speeds, plans.
States
Minimal example
JxRadioGroup(
name: 'size',
legend: 'Size',
options: [(value: 's', label: 'Small'), (value: 'l', label: 'Large')],
)
Complete example
A full Jaspr component you can paste into a project.
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';
class DeliveryChoice extends StatefulComponent {
const DeliveryChoice({super.key});
@override
State<DeliveryChoice> createState() => _DeliveryChoiceState();
}
class _DeliveryChoiceState extends State<DeliveryChoice> {
String speed = 'standard';
@override
Component build(BuildContext context) {
return JxRadioGroup(
name: 'delivery',
legend: 'Delivery',
value: speed,
options: const [
(value: 'standard', label: 'Standard, 3 to 5 days'),
(value: 'express', label: 'Express, next day'),
],
onChange: (value) => setState(() => speed = value),
);
}
}
Properties
| Property | Type | Default | Description |
|---|---|---|---|
name |
String |
required |
Shared
name
of the radios; also prefixes their ids.
|
legend |
String |
required |
Question or label of the group. |
options |
List<JxOption> |
required |
Records
(value: …, label: …)
.
|
value |
String? |
null |
Value of the checked option. |
hint |
String? |
null |
Help text under the options, linked to the fieldset. |
error |
String? |
null |
Replaces the hint and marks every radio invalid. |
required |
bool |
false |
Native
required
on the radios, with an asterisk after the legend.
|
disabled |
bool |
false |
Disables the whole group (
fieldset disabled
).
|
classes |
String? |
null |
Extra JX classes, appended after the component classes. |
Events
| Callback | Type | Fires when |
|---|---|---|
onChange |
ValueChanged<String>? |
Another option is chosen. |
Customizing
-
Pass
classesto add or override utilities: they come last, soclasses: 'w:full'wins over the default width. -
Lay options in a row with
classes: 'md:fd:row md:gap:6'.
Accessibility
-
A
<fieldset>and<legend>: screen readers announce the question with each option. - Native radios: arrow keys move between options, Tab leaves the group.
Limitations
- No per-option description.