@@ -445,28 +445,30 @@ class SessionRouteState extends State<SessionRoute> with SingleTickerProviderSta
445
445
await HotwordDetector ().stop ();
446
446
}
447
447
await WakelockPlus .disable ();
448
- // ignore: use_build_context_synchronously
449
- Navigator .push (
450
- context,
451
- CupertinoPageRoute (
452
- builder: (context) => const MenuRoute (),
453
- ),
454
- ).then ((val) async {
455
- inMenu = false ;
456
- // Make sure we rebuild main route when menu route is popped in navigation
457
- // stack. This ensures that the state of the hotword activation button is
458
- // updated to reflect potential changes in Settings, etc.
459
- if (text == '' ) {
460
- msg (introMsg ());
461
- }
462
- setState (() {});
463
- // Re-enable wakelock when returning to main route
464
- await WakelockPlus .enable ();
465
- // Resume hotword detection (if enabled)
466
- if (Prefs ().boolForKey ('hotword_activation' ) == true ) {
467
- await HotwordDetector ().start (hotwordHandler);
468
- }
469
- });
448
+
449
+ if (context.mounted) {
450
+ Navigator .push (
451
+ context,
452
+ CupertinoPageRoute (
453
+ builder: (context) => const MenuRoute (),
454
+ ),
455
+ ).then ((val) async {
456
+ inMenu = false ;
457
+ // Make sure we rebuild main route when menu route is popped in navigation
458
+ // stack. This ensures that the state of the hotword activation button is
459
+ // updated to reflect potential changes in Settings, etc.
460
+ if (text == '' ) {
461
+ msg (introMsg ());
462
+ }
463
+ setState (() {});
464
+ // Re-enable wakelock when returning to main route
465
+ await WakelockPlus .enable ();
466
+ // Resume hotword detection (if enabled)
467
+ if (Prefs ().boolForKey ('hotword_activation' ) == true ) {
468
+ await HotwordDetector ().start (hotwordHandler);
469
+ }
470
+ });
471
+ }
470
472
}
471
473
472
474
// Handle tap on microphone icon to toggle hotword activation
0 commit comments