SegmentedButton<T> constructor

const SegmentedButton<T>({
  1. Key? key,
  2. required List<ButtonSegment<T>> segments,
  3. required Set<T> selected,
  4. void onSelectionChanged(
    1. Set<T>
    )?,
  5. bool multiSelectionEnabled = false,
  6. bool emptySelectionAllowed = false,
  7. EdgeInsets? expandedInsets,
  8. ButtonStyle? style,
  9. bool showSelectedIcon = true,
  10. Widget? selectedIcon,
  11. Axis direction = Axis.horizontal,
})

Creates a const SegmentedButton.

segments must contain at least one segment, but it is recommended to have two to five segments. If you need only single segment, consider using a Checkbox or Radio widget instead. If you need more than five options, consider using FilterChip or ChoiceChip widgets.

If onSelectionChanged is null, then the entire segmented button will be disabled.

By default selected must only contain one entry. However, if multiSelectionEnabled is true, then selected can contain multiple entries. If emptySelectionAllowed is true, then selected can be empty.

Implementation

const SegmentedButton({
  super.key,
  required this.segments,
  required this.selected,
  this.onSelectionChanged,
  this.multiSelectionEnabled = false,
  this.emptySelectionAllowed = false,
  this.expandedInsets,
  this.style,
  this.showSelectedIcon = true,
  this.selectedIcon,
  this.direction = Axis.horizontal,
})  : assert(segments.length > 0),
      assert(selected.length > 0 || emptySelectionAllowed),
      assert(selected.length < 2 || multiSelectionEnabled);