fossui
Components

Toggle group

A row or column of toggles bound to one shared selection.

A toggle group binds a set of toggles to one selection. Each item's pressed state is its membership in the group value, and the variant and size set on the group propagate to every item. Use FossToggleGroup.single for a one-of-many choice or FossToggleGroup.multiple for independent toggles. In the outline variant the items join into one segmented bar with a shared border and rounded outer ends; in standard they sit as separate buttons with a small gap.

Toggle group
import 'package:fossui/fossui.dart';

FossToggleGroup.single(
  value: alignment,
  variant: FossToggleVariant.outline,
  onChanged: (v) => setState(() => alignment = v),
  children: const [
    FossToggleGroupItem(value: 'left', child: Text('Left')),
    FossToggleGroupItem(value: 'center', child: Text('Center')),
    FossToggleGroupItem(value: 'right', child: Text('Right')),
  ],
);

Single selection

One item is on at a time. Selecting another swaps it, and tapping the active item again clears the value to null, so the group can be empty.

FossToggleGroup.single(
  value: view,
  onChanged: (v) => setState(() => view = v),
  children: const [
    FossToggleGroupItem(value: 'list', child: Text('List')),
    FossToggleGroupItem(value: 'grid', child: Text('Grid')),
  ],
);

Multiple selection

Items toggle independently in and out of a set.

FossToggleGroup.multiple(
  value: marks,
  onChanged: (v) => setState(() => marks = v),
  children: const [
    FossToggleGroupItem(value: 'bold', child: Text('Bold')),
    FossToggleGroupItem(value: 'italic', child: Text('Italic')),
  ],
);

Orientation

Set orientation to Axis.vertical to stack the items into a column. The outline bar joins top to bottom, and a horizontal bar mirrors under RTL.

FossToggleGroup.single(
  value: view,
  orientation: Axis.vertical,
  variant: FossToggleVariant.outline,
  onChanged: (v) => setState(() => view = v),
  children: const [
    FossToggleGroupItem(value: 'day', child: Text('Day')),
    FossToggleGroupItem(value: 'week', child: Text('Week')),
    FossToggleGroupItem(value: 'month', child: Text('Month')),
  ],
);

Disabled

A null onChanged or enabled: false disables the whole group; an item's own enabled: false disables just that one.

FossToggleGroup.single(
  value: view,
  enabled: false,
  onChanged: (v) => setState(() => view = v),
  children: const [
    FossToggleGroupItem(value: 'list', child: Text('List')),
    FossToggleGroupItem(value: 'grid', child: Text('Grid')),
  ],
);

API

FossToggleGroup.single

PropTypeDefaultDescription
valueString?requiredThe selected item, or null when empty.
onChangedValueChanged<String?>requiredCalled with the new selection, null when cleared.
variantFossToggleVariantstandardPropagated to every item.
sizeFossToggleSizemdPropagated to every item.
orientationAxishorizontalThe layout axis.
enabledbooltrueWhen false, every item is disabled.
childrenList<FossToggleGroupItem>requiredThe entries.
styleFossToggleGroupStyle?nullPer-instance overrides on the theme.

FossToggleGroup.multiple

The same, with value typed Set<String> and onChanged typed ValueChanged<Set<String>>.

FossToggleGroupItem

PropTypeDefaultDescription
valueStringrequiredThe id, unique within the group.
leadingWidget?nullIcon before the label, or the sole content when icon-only.
childWidget?nullThe label. Null makes a square icon-only entry.
semanticLabelString?nullAccessibility name, required in spirit for icon-only.
enabledbooltrueWhen false, this entry is disabled.

Live demo

Open the interactive gallery to try both variants, orientations, and selection modes with live knobs.

On this page