Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Switch screen evaluation for BottomNavbar #1868

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions modules/ensemble/lib/framework/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down Expand Up @@ -174,6 +174,10 @@ abstract class Menu extends Object with HasStyles, Invokable {
static List<MenuItem> getVisibleMenuItems(DataContext context, List<MenuItem> 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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup>
activeIcon: activeIcon,
isCustom: isCustom,
text: label,
switchScreen: item.switchScreen,
switchScreen: Menu.evalSwitchScreen(widget.scopeManager.dataContext, item),
onTap: EnsembleAction.from(item.onTap),
onTapHaptic: item.onTapHaptic,
),
Expand Down