diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index 318bb1b3a2..dcf74fa2f9 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -36,12 +36,12 @@ class MaterialApp extends WidgetsApp { bool showSemanticsDebugger: false, bool debugShowCheckedModeBanner: true }) : theme = theme, + routes = routes, super( key: key, title: title, textStyle: _errorTextStyle, color: theme?.primaryColor ?? Colors.blue[500], // blue[500] is the primary color of the default theme - routes: routes, onGenerateRoute: (RouteSettings settings) { WidgetBuilder builder = routes[settings.name]; if (builder != null) { @@ -65,6 +65,8 @@ class MaterialApp extends WidgetsApp { /// The colors to use for the application's widgets. final ThemeData theme; + final Map routes; + /// Turns on a [GridPaper] overlay that paints a baseline grid /// Material apps: /// https://www.google.com/design/spec/layout/metrics-keylines.html diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index f89e8e90f2..36dc4e538b 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -30,21 +30,28 @@ final AssetBundle _defaultBundle = _initDefaultBundle(); typedef Future LocaleChangedCallback(Locale locale); +/// A convenience class that wraps a number of widgets that are commonly +/// required for an application. +/// +/// See also: [CheckedModeBanner], [DefaultTextStyle], [MediaQuery], +/// [LocaleQuery], [AssetVendor], [Title], [Navigator], [Overlay], +/// [SemanticsDebugger] (the widgets wrapped by this one). +/// +/// The [onGenerateRoute] argument is required, and corresponds to +/// [Navigator.onGenerateRoute]. class WidgetsApp extends StatefulWidget { WidgetsApp({ Key key, this.title, this.textStyle, this.color, - this.routes: const {}, this.onGenerateRoute, this.onLocaleChanged, this.showPerformanceOverlay: false, this.showSemanticsDebugger: false, this.debugShowCheckedModeBanner: true }) : super(key: key) { - assert(routes != null); - assert(routes.containsKey(Navigator.defaultRouteName) || onGenerateRoute != null); + assert(onGenerateRoute != null); assert(showPerformanceOverlay != null); assert(showSemanticsDebugger != null); } @@ -62,14 +69,8 @@ class WidgetsApp extends StatefulWidget { /// application switcher. final Color color; - /// The default table of routes for the application. When the - /// [Navigator] is given a named route, the name will be looked up - /// in this table first. If the name is not available, then - /// [onGenerateRoute] will be called instead. - final Map routes; - /// The route generator callback used when the app is navigated to a - /// named route but the name is not in the [routes] table. + /// named route. final RouteFactory onGenerateRoute; /// Callback that is invoked when the operating system changes the @@ -179,25 +180,28 @@ class WidgetsAppState extends State implements BindingO ), child: new LocaleQuery( data: _localeData, - child: new DefaultTextStyle( - style: config.textStyle, - child: new AssetVendor( - bundle: _defaultBundle, - devicePixelRatio: ui.window.devicePixelRatio, - child: new Title( - title: config.title, - color: config.color, - child: new Navigator( - key: _navigator, - initialRoute: ui.window.defaultRouteName, - onGenerateRoute: config.onGenerateRoute, - observer: navigatorObserver - ) + child: new AssetVendor( + bundle: _defaultBundle, + devicePixelRatio: ui.window.devicePixelRatio, + child: new Title( + title: config.title, + color: config.color, + child: new Navigator( + key: _navigator, + initialRoute: ui.window.defaultRouteName, + onGenerateRoute: config.onGenerateRoute, + observer: navigatorObserver ) ) ) ) ); + if (config.textStyle != null) { + new DefaultTextStyle( + style: config.textStyle, + child: result + ); + } if (config.showPerformanceOverlay) { result = new Stack( children: [