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,
    Icon? icon,
    MenuModel? subMenu,
    this.tooltip = '',
    this.secondaryLabel = '',
    this.labelAnnotation = '',
    Iterable<String>? cssClasses,
    MenuAction? action,
    ActionWithContext? actionWithContext,
    SelectableOption selectableState = SelectableOption.Selectable,
    bool? shouldSelectOnItemClick,
    MenuItemAffix? itemSuffix,
    ObservableList<MenuItemAffix>? itemSuffixes})
    : _selectableState = selectableState,
      this.subMenu = subMenu ?? MenuModel([]),
      this.icon = icon ?? Icon.blank(),
      shouldSelectOnItemClick = shouldSelectOnItemClick ?? subMenu == null,
      itemSuffixes = itemSuffixes ??
          ObservableList<MenuItemAffix>.from(
              Optional.fromNullable(itemSuffix)),
      cssClasses = BuiltList<String>((cssClasses ?? const <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;
  }
}