Tinyrack

ToggleGroup

Coordinate single or multiple pressed toggles by value.

Coordinate single or multiple pressed toggles by value.

Contract

AxisContract
SelectionOne value at most by default, and tapping the selected item clears the group. multiple lets every item toggle independently.
StatePass value to control the selection, or leave it null and start from defaultValue. Both are List<String>, and the default is empty.
Orientationorientation takes a Flutter Axis; the default is Axis.horizontal. It sets both the layout direction and the arrow-key axis.
KeyboardTab reaches the group once and then the arrow keys along the orientation axis, plus Home and End, move between items. Focus wraps at the ends unless loopFocus is false, and disabled items are skipped.
AvailabilityThe group disabled turns off every item, and a single TRToggle can be disabled on its own.

The group holds the selection and its children are public TRToggle widgets, so each item needs a stable, unique value. Like a single toggle the group submits no form value; use TRCheckboxGroup or TRRadioGroup when the selection has to travel with a form.

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 AlignmentBar extends StatefulWidget {
  const AlignmentBar({super.key});

  @override
  State<AlignmentBar> createState() => _AlignmentBarState();
}

class _AlignmentBarState extends State<AlignmentBar> {
  List<String> alignment = const ['start'];

  @override
  Widget build(BuildContext context) {
    return TRToggleGroup(
      value: alignment,
      onValueChange: (next) => setState(() => alignment = next),
      children: const [
        TRToggle(value: 'start', child: Text('Start')),
        TRToggle(value: 'center', child: Text('Center')),
        TRToggle(value: 'end', child: Text('End')),
      ],
    );
  }
}

Examples

Single selection permalink

By default only one value stays selected, and tapping the selected item clears the group. onValueChange reports the next list.

Multiple selection permalink

multiple lets each item toggle independently, so the value list can hold several values at once.

Vertical focus and disabled scopes permalink

A vertical group moves focus with Up and Down. loopFocus: false stops focus at the ends, disabled turns off every item, and a single item can be disabled on its own.

API

TRToggleGroup properties

PropType / defaultPurpose
childrenList<TRToggle> · requiredLists the items in visual and focus order. The type is TRToggle, so the group can read each item value and disabled.
valueList<String>? · nullControls the selected values. While it is non-null the group never changes the selection on its own.
defaultValueList<String> · const []Sets the initial selection of an uncontrolled group. It is ignored once value is provided.
onValueChangeValueChanged<List<String>>? · nullReports the next list after an item changes. There is no way to veto the change.
multiplebool · falseAllows each item to be toggled independently instead of keeping at most one value.
orientationAxis · Axis.horizontalLays the items out along this axis and selects the arrow keys that move focus.
loopFocusbool · trueWraps arrow-key focus at the first and last enabled item. Set it to false to stop at the ends.
disabledbool · falseDisables every item in the group, on top of any item that is disabled on its own.