Tinyrack

Radio Group

Coordinate a mutually exclusive selection across radios.

Coordinate a mutually exclusive selection across radios.

Contract

AxisContract
State ownershipUse defaultValue when the group owns the selection, or pair value with onValueChange for controlled state. Both are String?, and no option starts selected when both are null.
LabelThe group renders no label of its own. Wrap it in TRField to name the choice and show an error message below it.
AvailabilityGroup disabled blocks every option and omits a named group from TRFormValues. Group readOnly keeps the selected value and focus while refusing changes.
FormsSet name to register the selected string with the nearest TRForm, which reports it from save(). The group is not a FormField, so TRForm.reset() leaves its value alone; restore the starting value from your own state.
KeyboardTab reaches the group once, landing on the selected option. The arrow keys on either axis, plus Home and End, then move focus and selection together, skip disabled options, and wrap at the ends. A read-only group moves focus without changing its value.

The group holds the selected value and its children are public TRRadio widgets, so each option needs a unique value. Unlike the web component it has no required prop, no form association, and no built-in validation: wrap it in TRField to add a visible label, and compute the error message from your own state.

Install

Add the package, then import its public library.

flutter pub add tinyrack_ui
import 'package:tinyrack_ui/tinyrack_ui.dart';

Playground

Usage

import 'package:material_ui/material_ui.dart';
import 'package:tinyrack_ui/tinyrack_ui.dart';

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

  @override
  State<DeploymentRack> createState() => _DeploymentRackState();
}

class _DeploymentRackState extends State<DeploymentRack> {
  String rack = 'alpha';

  @override
  Widget build(BuildContext context) {
    return TRField(
      label: 'Deployment rack',
      control: TRRadioGroup(
        name: 'rack',
        value: rack,
        onValueChange: (next) => setState(() => rack = next),
        children: const [
          TRRadio(
            value: 'alpha',
            label: TRText('Rack alpha', variant: TRTextVariant.bodySm),
          ),
          TRRadio(
            value: 'beta',
            label: TRText('Rack beta', variant: TRTextVariant.bodySm),
          ),
        ],
      ),
    );
  }
}

Examples

Editable, read only, and disabled groups permalink

A read-only group keeps its value and keyboard focus; a disabled group blocks both and drops out of TRFormValues.

Require one value permalink

The group has no required prop, so control the value and pass your own message to TRField.errorText.

Collect the value from a form permalink

name registers the selected string with the nearest TRForm, which reports it from save().

API

TRRadioGroup properties

PropType / defaultPurpose
childrenList<TRRadio> · requiredLists the options in visual and focus order. The type is TRRadio, so the group can read each option value and disabled.
valueString? · nullControls the selected option. While it is non-null the group never changes the selection on its own.
defaultValueString? · nullSets the initial selection of an uncontrolled group. It is read once, so a later change does not move the selection, and it is ignored when value is provided.
onValueChangeValueChanged<String>? · nullReports the next selected value after a tap or an arrow key. There is no way to veto the change.
disabledbool · falseDisables every option and omits a named group from TRFormValues.
readOnlybool · falseKeeps the selected value and keyboard focus while refusing every change.
nameString? · nullRegisters the selected value with the nearest TRForm.