enable static method
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 onTabSelected(
- int index
- void onListItemTap()?,
- void onSearchChanged(
- String query
- VoidCallback? onAccessoryTap,
- 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;
}