@tduncan / Cortana / commits / 3efa584

fix: replace Scaffold.of with Scaffold.maybeOf to prevent exceptions when opening drawers, fixes #74

abdulmominsakib committed Sep 1, 2026 at 10:32 UTC 3efa5846cb2bb06749efb16b4750ae75df73702a
10 files changed +13 -10
lib/app.dart
+4 -1
@@ -351,7 +351,10 @@ class AppShell extends ConsumerWidget {
351 // On the empty home screen, open the side drawer instead
352 // of exiting the app — matches the menu icon on the
353 // top-left. This context must be below the Scaffold.
354 - Scaffold.of(scaffoldContext).openDrawer();
354 + // Use maybeOf so we never throw if no Scaffold ancestor
355 + // is present (e.g. when this widget is embedded in a
356 + // route or surface that doesn't provide one).
357 + Scaffold.maybeOf(scaffoldContext)?.openDrawer();
358 return;
359 }
360 handleBack();
lib/features/chat/views/components/top_bar/screen_app_bar.dart
+1 -1
@@ -115,7 +115,7 @@ class ScreenAppBar extends ConsumerWidget {
115 if (isDesktop) return const SizedBox.shrink();
116 return IconButton(
117 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
118 - onPressed: () => Scaffold.of(context).openDrawer(),
118 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
119 );
120 },
121 ),
lib/features/conversations/views/chat_history_screen.dart
+1 -1
@@ -127,7 +127,7 @@ class ChatHistoryScreen extends ConsumerWidget {
127 icon: const HugeIcon(
128 icon: HugeIcons.strokeRoundedMenu01,
129 ),
130 - onPressed: () => Scaffold.of(context).openDrawer(),
130 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
131 ),
132 ),
133 const SizedBox(width: 8),
lib/features/mcp/views/mcp_tools_screen.dart
+1 -1
@@ -84,7 +84,7 @@ class _McpToolsScreenState extends ConsumerState<McpToolsScreen> {
84 Builder(
85 builder: (context) => IconButton(
86 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
87 - onPressed: () => Scaffold.of(context).openDrawer(),
87 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
88 ),
89 ),
90 const SizedBox(width: 8),
lib/features/on_device/views/model_manager_screen.dart
+1 -1
@@ -255,7 +255,7 @@ class _ManagerHeader extends StatelessWidget {
255 Builder(
256 builder: (context) => IconButton(
257 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
258 - onPressed: () => Scaffold.of(context).openDrawer(),
258 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
259 ),
260 ),
261 const SizedBox(width: 8),
lib/features/personas/views/persona_list_screen.dart
+1 -1
@@ -51,7 +51,7 @@ class PersonaListScreen extends ConsumerWidget {
51 Builder(
52 builder: (context) => IconButton(
53 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
54 - onPressed: () => Scaffold.of(context).openDrawer(),
54 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
55 ),
56 ),
57 const SizedBox(width: 8),
lib/features/saved_messages/views/saved_messages_screen.dart
+1 -1
@@ -90,7 +90,7 @@ class SavedMessagesScreen extends ConsumerWidget {
90 icon: const HugeIcon(
91 icon: HugeIcons.strokeRoundedMenu01,
92 ),
93 - onPressed: () => Scaffold.of(context).openDrawer(),
93 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
94 ),
95 ),
96 const SizedBox(width: 8),
lib/features/servers/views/server_list_screen.dart
+1 -1
@@ -69,7 +69,7 @@ class _ServerListScreenState extends ConsumerState<ServerListScreen> {
69 Builder(
70 builder: (context) => IconButton(
71 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
72 - onPressed: () => Scaffold.of(context).openDrawer(),
72 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
73 ),
74 ),
75 const SizedBox(width: 8),
lib/features/settings/views/settings_screen.dart
+1 -1
@@ -86,7 +86,7 @@ class SettingsViews extends ConsumerWidget {
86 Builder(
87 builder: (context) => IconButton(
88 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
89 - onPressed: () => Scaffold.of(context).openDrawer(),
89 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
90 ),
91 ),
92 const SizedBox(width: 8),
lib/features/tts/views/tts_model_manager_screen.dart
+1 -1
@@ -50,7 +50,7 @@ class TtsModelManagerScreen extends ConsumerWidget {
50 Builder(
51 builder: (context) => IconButton(
52 icon: const HugeIcon(icon: HugeIcons.strokeRoundedMenu01),
53 - onPressed: () => Scaffold.of(context).openDrawer(),
53 + onPressed: () => Scaffold.maybeOf(context)?.openDrawer(),
54 ),
55 ),
56 const SizedBox(width: 8),