picker<T> method

  1. @override
T picker<T>(
  1. String name,
  2. Map<String, T> options,
  3. T defaultValue, {
  4. PickerStyle style = PickerStyle.dropdown,
})
override

A choice between named options, label to value.

Only the labels cross the wire — see KnobDescriptor.options — so the values behind them may be of any type at all, and the labels are whatever reads well rather than whatever an identifier happened to be called.

style is how the top bar draws it. A segmented control suits a switch you flip back and forth while looking — Light and Dark — because both options stay on the bar and a flip is one click rather than two.

Implementation

@override
T picker<T>(
  String name,
  Map<String, T> options,
  T defaultValue, {
  PickerStyle style = PickerStyle.dropdown,
}) {
  assert(
    options.containsValue(defaultValue),
    'The default for axis "$name" is not one of its options, so the top bar '
    'would open with nothing selected.',
  );
  var chosen = _selected[_shellId]?[name];
  var value = chosen is String && options.containsKey(chosen)
      ? options[chosen] as T
      : defaultValue;
  _declared[name] = KnobDescriptor(
    name: name,
    kind: KnobKind.picker,
    options: options.keys.toList(),
    value: _labelOf(options, value),
    defaultValue: _labelOf(options, defaultValue),
    style: style,
  );
  return value;
}