@@ -91,7 +91,7 @@ abstract class Menu extends Object with HasStyles, Invokable {
91
91
floatingAlignment:
92
92
Utils .optionalString (item['floatingAlignment' ]) ?? 'center' ,
93
93
floatingMargin: Utils .optionalInt (item['floatingMargin' ]),
94
- switchScreen: Utils . getBool ( item['switchScreen' ], fallback : true ),
94
+ switchScreen: item['switchScreen' ],
95
95
isClickable: Utils .getBool (item['isClickable' ], fallback: true ),
96
96
onTap: item['onTap' ],
97
97
onTapHaptic: Utils .optionalString (item['onTapHaptic' ]),
@@ -174,6 +174,10 @@ abstract class Menu extends Object with HasStyles, Invokable {
174
174
static List <MenuItem > getVisibleMenuItems (DataContext context, List <MenuItem > items) {
175
175
return items.where ((item) => item.isVisible (context)).toList ();
176
176
}
177
+ static bool evalSwitchScreen (DataContext context, MenuItem item) {
178
+ print (item.shouldSwitchScreen (context));
179
+ return item.shouldSwitchScreen (context);
180
+ }
177
181
}
178
182
179
183
class BottomNavBarMenu extends Menu {
@@ -291,7 +295,7 @@ class MenuItem {
291
295
this .iconLibrary,
292
296
this .selected,
293
297
this .floating = false ,
294
- this .switchScreen = true ,
298
+ this .switchScreen,
295
299
this .isClickable = true ,
296
300
this .floatingAlignment = 'center' ,
297
301
this .floatingMargin,
@@ -310,7 +314,7 @@ class MenuItem {
310
314
final String ? iconLibrary;
311
315
final dynamic selected;
312
316
final bool floating;
313
- final bool switchScreen;
317
+ final dynamic switchScreen;
314
318
final bool isClickable;
315
319
final String floatingAlignment;
316
320
final int ? floatingMargin;
@@ -331,4 +335,17 @@ class MenuItem {
331
335
throw LanguageError ('Failed to eval $visible ' );
332
336
}
333
337
}
338
+
339
+ bool shouldSwitchScreen (DataContext context) {
340
+ if (switchScreen == null ) return true ; // Default to true if not specified
341
+ if (switchScreen is bool ) return switchScreen;
342
+
343
+ // Evaluate the dynamic condition
344
+ try {
345
+ var result = context.eval (switchScreen);
346
+ return result is bool ? result : true ;
347
+ } catch (e) {
348
+ throw LanguageError ('Failed to eval switchScreen: $switchScreen ' );
349
+ }
350
+ }
334
351
}
0 commit comments