SelectableMenuItem<ItemType> constructor

SelectableMenuItem<ItemType>({
  1. required ItemType value,
  2. ItemRenderer<ItemType> itemRenderer = defaultItemRenderer,
  3. Icon? icon,
  4. MenuModel? subMenu,
  5. String? tooltip,
  6. String? secondaryLabel,
  7. String? labelAnnotation,
  8. Iterable<String>? cssClasses,
  9. MenuAction? action,
  10. ActionWithContext? actionWithContext,
  11. SelectableOption selectableState = SelectableOption.Selectable,
  12. bool? shouldSelectOnItemClick,
  13. MenuItemAffix? itemSuffix,
  14. ObservableList<MenuItemAffix>? itemSuffixes,
})

The constructor for a selectable MenuItem.

Selectable menu items can be managed with a SelectionModel from within MenuItemGroupWithSelection. Selected menu items are marked in the UI and can change the selection via user interactions.

itemSuffixes - the list of suffixes rendered after the item content.

itemSuffix - singular item suffix to be rendered after the item content; convenient way to pass a single item suffix in rather than constructing an ObservableList and using itemSuffixes. If itemSuffixes is also passed in, itemSuffixes takes precedence.

Implementation

SelectableMenuItem(
    {required this.value,
    this.itemRenderer = defaultItemRenderer,
    this.icon,
    this.subMenu,
    String? tooltip,
    this.secondaryLabel,
    String? labelAnnotation,
    Iterable<String>? cssClasses,
    MenuAction? action,
    ActionWithContext? actionWithContext,
    SelectableOption selectableState = SelectableOption.Selectable,
    bool? shouldSelectOnItemClick,
    MenuItemAffix? itemSuffix,
    ObservableList<MenuItemAffix>? itemSuffixes})
    : _selectableState = selectableState,
      tooltip = tooltip ?? '',
      labelAnnotation = labelAnnotation ?? '',
      shouldSelectOnItemClick = shouldSelectOnItemClick ?? subMenu == null,
      itemSuffixes = itemSuffixes ??
          ObservableList<MenuItemAffix>.from(
              itemSuffix != null ? [itemSuffix] : []),
      cssClasses = BuiltList<String>(cssClasses ?? <String>[]) {
  assert(itemSuffix == null || itemSuffixes == null,
      'Only one of itemSuffix or itemSuffixes should be provided');
  assert(action == null || actionWithContext == null,
      'Only one of action or actionWithContext should be provided');
  if (action != null) {
    _action = action;
    _actionWithContext = (_) => action();
  } else if (actionWithContext != null) {
    _action = () => actionWithContext(null);
    _actionWithContext = actionWithContext;
  } else {
    _action = _noOp;
    _actionWithContext = _noOp2;
  }
}