From 73ff4198907e934b0173ca9bed55ed7904dfb77d Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 5 Oct 2016 11:13:28 -0700 Subject: [PATCH] Let MaterialApp override the initial route (#6216) Fixes #6215 --- packages/flutter/lib/src/material/app.dart | 7 +++++++ packages/flutter/lib/src/widgets/app.dart | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index 813bae81cb..add369a404 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -52,6 +52,7 @@ class MaterialApp extends StatefulWidget { this.theme, this.home, this.routes: const {}, + this.initialRoute, this.onGenerateRoute, this.onLocaleChanged, this.debugShowMaterialGrid: false, @@ -110,6 +111,11 @@ class MaterialApp extends StatefulWidget { /// build the page instead. final Map 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 { // 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, diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index 84c9ccc18e..c3e4d907f8 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -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 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 )