diff --git a/modules/ensemble/lib/framework/menu.dart b/modules/ensemble/lib/framework/menu.dart index 6a09d1bde..c92d92940 100644 --- a/modules/ensemble/lib/framework/menu.dart +++ b/modules/ensemble/lib/framework/menu.dart @@ -91,7 +91,7 @@ abstract class Menu extends Object with HasStyles, Invokable { floatingAlignment: Utils.optionalString(item['floatingAlignment']) ?? 'center', floatingMargin: Utils.optionalInt(item['floatingMargin']), - switchScreen: Utils.getBool(item['switchScreen'], fallback: true), + switchScreen: item['switchScreen'], isClickable: Utils.getBool(item['isClickable'], fallback: true), onTap: item['onTap'], onTapHaptic: Utils.optionalString(item['onTapHaptic']), @@ -174,6 +174,10 @@ abstract class Menu extends Object with HasStyles, Invokable { static List getVisibleMenuItems(DataContext context, List items) { return items.where((item) => item.isVisible(context)).toList(); } + static bool evalSwitchScreen(DataContext context, MenuItem item) { + print(item.shouldSwitchScreen(context)); + return item.shouldSwitchScreen(context); + } } class BottomNavBarMenu extends Menu { @@ -291,7 +295,7 @@ class MenuItem { this.iconLibrary, this.selected, this.floating = false, - this.switchScreen = true, + this.switchScreen, this.isClickable = true, this.floatingAlignment = 'center', this.floatingMargin, @@ -310,7 +314,7 @@ class MenuItem { final String? iconLibrary; final dynamic selected; final bool floating; - final bool switchScreen; + final dynamic switchScreen; final bool isClickable; final String floatingAlignment; final int? floatingMargin; @@ -331,4 +335,17 @@ class MenuItem { throw LanguageError('Failed to eval $visible'); } } + + bool shouldSwitchScreen(DataContext context) { + if (switchScreen == null) return true; // Default to true if not specified + if (switchScreen is bool) return switchScreen; + + // Evaluate the dynamic condition + try { + var result = context.eval(switchScreen); + return result is bool ? result : true; + } catch (e) { + throw LanguageError('Failed to eval switchScreen: $switchScreen'); + } + } } diff --git a/modules/ensemble/lib/framework/view/bottom_nav_page_group.dart b/modules/ensemble/lib/framework/view/bottom_nav_page_group.dart index efe26c5da..70e59c8cf 100644 --- a/modules/ensemble/lib/framework/view/bottom_nav_page_group.dart +++ b/modules/ensemble/lib/framework/view/bottom_nav_page_group.dart @@ -302,7 +302,7 @@ class _BottomNavPageGroupState extends State activeIcon: activeIcon, isCustom: isCustom, text: label, - switchScreen: item.switchScreen, + switchScreen: Menu.evalSwitchScreen(widget.scopeManager.dataContext, item), onTap: EnsembleAction.from(item.onTap), onTapHaptic: item.onTapHaptic, ),