enable static method

Future<void> enable({
  1. required List<CNTab> tabs,
  2. int selectedIndex = 0,
  3. CNTabMinimizeBehavior minimizeBehavior = CNTabMinimizeBehavior.onScrollDown,
  4. CNTabAccessory? bottomAccessory,
  5. Color? tintColor,
  6. Color? unselectedTintColor,
  7. bool? isDark,
  8. bool asRoot = false,
  9. bool nativeSearchFilter = true,
  10. bool sidebarOnWideScreens = false,
  11. bool showCloseButton = true,
  12. void onTabSelected(
    1. int index
    )?,
  13. void onListItemTap(
    1. int tabIndex,
    2. int itemIndex
    )?,
  14. void onSearchChanged(
    1. String query
    )?,
  15. VoidCallback? onAccessoryTap,
  16. VoidCallback? onDismissed,
})

Present the native tab bar configured from tabs.

showCloseButton false hides the close button in each tab's navigation bar, for a root-mode app whose tab bar is the whole app; it is then closed only by disable. On macOS the close button is at the trailing end of a native list's title.

isDark sets the bar's appearance. Null draws it light on iOS and follows the system on macOS.

Implementation

static Future<void> enable({
  required List<CNTab> tabs,
  int selectedIndex = 0,
  CNTabMinimizeBehavior minimizeBehavior = CNTabMinimizeBehavior.onScrollDown,
  CNTabAccessory? bottomAccessory,
  Color? tintColor,
  Color? unselectedTintColor,
  bool? isDark,
  bool asRoot = false,
  bool nativeSearchFilter = true,
  bool sidebarOnWideScreens = false,
  bool showCloseButton = true,
  void Function(int index)? onTabSelected,
  void Function(int tabIndex, int itemIndex)? onListItemTap,
  void Function(String query)? onSearchChanged,
  VoidCallback? onAccessoryTap,
  VoidCallback? onDismissed,
}) async {
  // iOS 26+ and macOS — no-op elsewhere.
  final mac =
      !kIsWeb &&
      defaultTargetPlatform == TargetPlatform.macOS &&
      PlatformVersion.shouldUseNativeControls;
  if (!mac &&
      (defaultTargetPlatform != TargetPlatform.iOS ||
          !PlatformVersion.shouldUseNativeGlass)) {
    return;
  }
  if (_enabled) return;

  _onTabSelected = onTabSelected;
  _onListItemTap = onListItemTap;
  _onSearchChanged = onSearchChanged;
  _onAccessoryTap = onAccessoryTap;
  _onDismissed = onDismissed;
  _channel.setMethodCallHandler(_handle);

  final args = {
    'tabs': [
      for (final t in tabs)
        {
          'title': t.title,
          'sfSymbol': t.sfSymbol?.name,
          if (t.activeSfSymbol != null)
            'activeSfSymbol': t.activeSfSymbol!.name,
          'isSearch': t.isSearchTab,
          if (t.isProminent) 'isProminent': true,
          'badgeCount': t.badgeCount,
          if (t.nativeList != null)
            'nativeList': {
              'items': [for (final i in t.nativeList!.items) _itemMap(i)],
            },
        },
    ],
    'selectedIndex': selectedIndex,
    'minimizeBehavior': minimizeBehavior.name,
    if (bottomAccessory != null)
      'bottomAccessory': _accessoryMap(bottomAccessory),
    if (tintColor != null) 'tint': tintColor.toARGB32(),
    if (unselectedTintColor != null)
      'unselectedTint': unselectedTintColor.toARGB32(),
    // Missing means light on iOS and the system's appearance on macOS.
    if (isDark != null) 'isDark': isDark,
    'asRoot': asRoot,
    'nativeSearchFilter': nativeSearchFilter,
    'sidebar': sidebarOnWideScreens,
    'showCloseButton': showCloseButton,
  };
  if (mac) {
    try {
      await _channel.invokeMethod('enable', args);
    } on PlatformException {
      // No window to put the sidebar in (a headless engine).
      _reset();
      return;
    }
  } else {
    await _channel.invokeMethod('enable', args);
  }

  _enabled = true;
}