Commit 73ff4198 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Let MaterialApp override the initial route (#6216)

Fixes #6215
parent aed056c6
...@@ -52,6 +52,7 @@ class MaterialApp extends StatefulWidget { ...@@ -52,6 +52,7 @@ class MaterialApp extends StatefulWidget {
this.theme, this.theme,
this.home, this.home,
this.routes: const <String, WidgetBuilder>{}, this.routes: const <String, WidgetBuilder>{},
this.initialRoute,
this.onGenerateRoute, this.onGenerateRoute,
this.onLocaleChanged, this.onLocaleChanged,
this.debugShowMaterialGrid: false, this.debugShowMaterialGrid: false,
...@@ -110,6 +111,11 @@ class MaterialApp extends StatefulWidget { ...@@ -110,6 +111,11 @@ class MaterialApp extends StatefulWidget {
/// build the page instead. /// build the page instead.
final Map<String, WidgetBuilder> routes; final Map<String, WidgetBuilder> routes;
/// The name of the first route to show.
///
/// Defaults to [Window.defaultRouteName].
final String initialRoute;
/// The route generator callback used when the app is navigated to a /// The route generator callback used when the app is navigated to a
/// named route. /// named route.
final RouteFactory onGenerateRoute; final RouteFactory onGenerateRoute;
...@@ -254,6 +260,7 @@ class _MaterialAppState extends State<MaterialApp> { ...@@ -254,6 +260,7 @@ class _MaterialAppState extends State<MaterialApp> {
// blue[500] is the primary color of the default theme // blue[500] is the primary color of the default theme
color: config.color ?? theme?.primaryColor ?? Colors.blue[500], color: config.color ?? theme?.primaryColor ?? Colors.blue[500],
navigatorObserver: _heroController, navigatorObserver: _heroController,
initialRoute: config.initialRoute,
onGenerateRoute: _onGenerateRoute, onGenerateRoute: _onGenerateRoute,
onLocaleChanged: config.onLocaleChanged, onLocaleChanged: config.onLocaleChanged,
showPerformanceOverlay: config.showPerformanceOverlay, showPerformanceOverlay: config.showPerformanceOverlay,
......
...@@ -43,6 +43,7 @@ class WidgetsApp extends StatefulWidget { ...@@ -43,6 +43,7 @@ class WidgetsApp extends StatefulWidget {
this.textStyle, this.textStyle,
this.color, this.color,
this.navigatorObserver, this.navigatorObserver,
this.initialRoute,
this.onLocaleChanged, this.onLocaleChanged,
this.showPerformanceOverlay: false, this.showPerformanceOverlay: false,
this.showSemanticsDebugger: false, this.showSemanticsDebugger: false,
...@@ -70,6 +71,11 @@ class WidgetsApp extends StatefulWidget { ...@@ -70,6 +71,11 @@ class WidgetsApp extends StatefulWidget {
/// named route. /// named route.
final RouteFactory onGenerateRoute; final RouteFactory onGenerateRoute;
/// The name of the first route to show.
///
/// Defaults to [Window.defaultRouteName].
final String initialRoute;
/// Callback that is called when the operating system changes the /// Callback that is called when the operating system changes the
/// current locale. /// current locale.
final LocaleChangedCallback onLocaleChanged; final LocaleChangedCallback onLocaleChanged;
...@@ -176,7 +182,7 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv ...@@ -176,7 +182,7 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
color: config.color, color: config.color,
child: new Navigator( child: new Navigator(
key: _navigator, key: _navigator,
initialRoute: ui.window.defaultRouteName, initialRoute: config.initialRoute ?? ui.window.defaultRouteName,
onGenerateRoute: config.onGenerateRoute, onGenerateRoute: config.onGenerateRoute,
observer: config.navigatorObserver observer: config.navigatorObserver
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment