toAnchorChild method

Widget toAnchorChild()

Implementation

Widget toAnchorChild() {
  return switch (this) {
    AppActionDivider() => const Divider(),
    final AppActionBuilder builder => builder.builder(),
    final AppActionsGroup group => SubmenuButton(
        menuChildren: group.items.toAnchorChildren(),
        leadingIcon: group.iconCallback?.call() ?? group.icon,
        child: Text(group.label, style: group.style),
      ),
    final AppAction action => TooltipVisibility(
        visible: action.tooltip != null || action.disabledTooltip != null,
        child: FutureBuilder(
          future: Future.value(action.enabledCallback?.call() ?? true),
          builder: (context, snapshot) {
            final enabled = snapshot.data ?? false;

            return Tooltip(
              message: (enabled ? action.tooltip : action.disabledTooltip) ?? action.label,
              child: MenuItemButton(
                onPressed: enabled ? action.onPressed : null,
                leadingIcon: action.iconCallback?.call() ?? action.icon,
                closeOnActivate: action.submenuSettings?.closeOnActivate ?? true,
                child: Text(action.label, style: action.style),
              ),
            );
          },
        ),
      ),
  };
}