Let MaterialApp override the initial route (#6216)

Fixes #6215
This commit is contained in:
Adam Barth
2016-10-05 11:13:28 -07:00
committed by GitHub
parent aed056c64b
commit 73ff419890
2 changed files with 14 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ class MaterialApp extends StatefulWidget {
this.theme,
this.home,
this.routes: const <String, WidgetBuilder>{},
this.initialRoute,
this.onGenerateRoute,
this.onLocaleChanged,
this.debugShowMaterialGrid: false,
@@ -110,6 +111,11 @@ class MaterialApp extends StatefulWidget {
/// build the page instead.
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
/// named route.
final RouteFactory onGenerateRoute;
@@ -254,6 +260,7 @@ class _MaterialAppState extends State<MaterialApp> {
// blue[500] is the primary color of the default theme
color: config.color ?? theme?.primaryColor ?? Colors.blue[500],
navigatorObserver: _heroController,
initialRoute: config.initialRoute,
onGenerateRoute: _onGenerateRoute,
onLocaleChanged: config.onLocaleChanged,
showPerformanceOverlay: config.showPerformanceOverlay,

View File

@@ -43,6 +43,7 @@ class WidgetsApp extends StatefulWidget {
this.textStyle,
this.color,
this.navigatorObserver,
this.initialRoute,
this.onLocaleChanged,
this.showPerformanceOverlay: false,
this.showSemanticsDebugger: false,
@@ -70,6 +71,11 @@ class WidgetsApp extends StatefulWidget {
/// named route.
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
/// current locale.
final LocaleChangedCallback onLocaleChanged;
@@ -176,7 +182,7 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
color: config.color,
child: new Navigator(
key: _navigator,
initialRoute: ui.window.defaultRouteName,
initialRoute: config.initialRoute ?? ui.window.defaultRouteName,
onGenerateRoute: config.onGenerateRoute,
observer: config.navigatorObserver
)