@@ -152,6 +152,23 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
152
152
super .dispose ();
153
153
}
154
154
155
+ List <Route <dynamic >> _handleGenerateInitialRoutes (String initialRoute) {
156
+ // The `_ZulipAppState.context` lacks the required ancestors. Instead
157
+ // we use the Navigator which should be available when this callback is
158
+ // called and it's context should have the required ancestors.
159
+ final context = ZulipApp .navigatorKey.currentContext! ;
160
+ final globalStore = GlobalStoreWidget .of (context);
161
+
162
+ // TODO(#524) choose initial account as last one used
163
+ final initialAccountId = globalStore.accounts.firstOrNull? .id;
164
+ return [
165
+ if (initialAccountId == null )
166
+ MaterialWidgetRoute (page: const ChooseAccountPage ())
167
+ else
168
+ HomePage .buildRoute (accountId: initialAccountId),
169
+ ];
170
+ }
171
+
155
172
Future <void > _handleInitialRoute () async {
156
173
final initialRouteUrl = Uri .parse (WidgetsBinding .instance.platformDispatcher.defaultRouteName);
157
174
if (initialRouteUrl case Uri (scheme: 'zulip' , host: 'notification' )) {
@@ -176,47 +193,35 @@ class _ZulipAppState extends State<ZulipApp> with WidgetsBindingObserver {
176
193
Widget build (BuildContext context) {
177
194
final themeData = zulipThemeData (context);
178
195
return GlobalStoreWidget (
179
- child: Builder (builder: (context) {
180
- final globalStore = GlobalStoreWidget .of (context);
181
- return MaterialApp (
182
- onGenerateTitle: (BuildContext context) {
183
- return ZulipLocalizations .of (context).zulipAppTitle;
184
- },
185
- localizationsDelegates: ZulipLocalizations .localizationsDelegates,
186
- supportedLocales: ZulipLocalizations .supportedLocales,
187
- theme: themeData,
188
-
189
- navigatorKey: ZulipApp .navigatorKey,
190
- navigatorObservers: widget.navigatorObservers ?? const [],
191
- builder: (BuildContext context, Widget ? child) {
192
- if (! ZulipApp .ready.value) {
193
- SchedulerBinding .instance.addPostFrameCallback (
194
- (_) => widget._declareReady ());
195
- }
196
- GlobalLocalizations .zulipLocalizations = ZulipLocalizations .of (context);
197
- return child! ;
198
- },
199
-
200
- // We use onGenerateInitialRoutes for the real work of specifying the
201
- // initial nav state. To do that we need [MaterialApp] to decide to
202
- // build a [Navigator]... which means specifying either `home`, `routes`,
203
- // `onGenerateRoute`, or `onUnknownRoute`. Make it `onGenerateRoute`.
204
- // It never actually gets called, though: `onGenerateInitialRoutes`
205
- // handles startup, and then we always push whole routes with methods
206
- // like [Navigator.push], never mere names as with [Navigator.pushNamed].
207
- onGenerateRoute: (_) => null ,
208
-
209
- onGenerateInitialRoutes: (_) {
210
- // TODO(#524) choose initial account as last one used
211
- final initialAccountId = globalStore.accounts.firstOrNull? .id;
212
- return [
213
- if (initialAccountId == null )
214
- MaterialWidgetRoute (page: const ChooseAccountPage ())
215
- else
216
- HomePage .buildRoute (accountId: initialAccountId),
217
- ];
218
- });
219
- }));
196
+ child: MaterialApp (
197
+ onGenerateTitle: (BuildContext context) {
198
+ return ZulipLocalizations .of (context).zulipAppTitle;
199
+ },
200
+ localizationsDelegates: ZulipLocalizations .localizationsDelegates,
201
+ supportedLocales: ZulipLocalizations .supportedLocales,
202
+ theme: themeData,
203
+
204
+ navigatorKey: ZulipApp .navigatorKey,
205
+ navigatorObservers: widget.navigatorObservers ?? const [],
206
+ builder: (BuildContext context, Widget ? child) {
207
+ if (! ZulipApp .ready.value) {
208
+ SchedulerBinding .instance.addPostFrameCallback (
209
+ (_) => widget._declareReady ());
210
+ }
211
+ GlobalLocalizations .zulipLocalizations = ZulipLocalizations .of (context);
212
+ return child! ;
213
+ },
214
+
215
+ // We use onGenerateInitialRoutes for the real work of specifying the
216
+ // initial nav state. To do that we need [MaterialApp] to decide to
217
+ // build a [Navigator]... which means specifying either `home`, `routes`,
218
+ // `onGenerateRoute`, or `onUnknownRoute`. Make it `onGenerateRoute`.
219
+ // It never actually gets called, though: `onGenerateInitialRoutes`
220
+ // handles startup, and then we always push whole routes with methods
221
+ // like [Navigator.push], never mere names as with [Navigator.pushNamed].
222
+ onGenerateRoute: (_) => null ,
223
+
224
+ onGenerateInitialRoutes: _handleGenerateInitialRoutes));
220
225
}
221
226
}
222
227
0 commit comments