Choice<T> class

Represents a selectable choice item.

The key field serves dual purposes:

  1. Unique identification for validation and selection tracking
  2. Grouping: if key is null or empty, the choice acts as a group title

Example:

List<Choice<Car>> choices = [
  Choice(null, 'Sports Cars'),  // Group title
  Choice('1', 'Ferrari', metadata: Car(...)),
  Choice('2', 'Porsche', metadata: Car(...)),
  Choice(null, 'SUVs'),  // Another group title
  Choice('3', 'Range Rover', metadata: Car(...)),
];
Available extensions

Constructors

Choice(String? key, String value, {T? metadata})
const

Properties

hashCode int
The hash code for this object.
no setteroverride
isGroupingTitle bool

Available on Choice<T>, provided by the ChoiceMenuExtension extension

A choice acts as a grouping title when it has no key.
no setter
key String?
final
metadata → T?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String
final

Methods

isFirstSelectedIn(List<Choice<T>> selectedChoice) bool

Available on Choice<T>, provided by the ChoiceMenuExtension extension

Whether this choice occupies the first slot in selectedChoice.
isSelectedIn(List<Choice<T>> selectedChoice) bool

Available on Choice<T>, provided by the ChoiceMenuExtension extension

Whether this choice is currently selected within selectedChoice.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override