Commit d8c74736 authored by Ian Hickson's avatar Ian Hickson

Fix WidgetsApp issues

- Make the textStyle optional
- Remove routes
- Make onGenerateRoute required
- Add some dartdocs
parent 571046a7
...@@ -36,12 +36,12 @@ class MaterialApp extends WidgetsApp { ...@@ -36,12 +36,12 @@ class MaterialApp extends WidgetsApp {
bool showSemanticsDebugger: false, bool showSemanticsDebugger: false,
bool debugShowCheckedModeBanner: true bool debugShowCheckedModeBanner: true
}) : theme = theme, }) : theme = theme,
routes = routes,
super( super(
key: key, key: key,
title: title, title: title,
textStyle: _errorTextStyle, textStyle: _errorTextStyle,
color: theme?.primaryColor ?? Colors.blue[500], // blue[500] is the primary color of the default theme color: theme?.primaryColor ?? Colors.blue[500], // blue[500] is the primary color of the default theme
routes: routes,
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
WidgetBuilder builder = routes[settings.name]; WidgetBuilder builder = routes[settings.name];
if (builder != null) { if (builder != null) {
...@@ -65,6 +65,8 @@ class MaterialApp extends WidgetsApp { ...@@ -65,6 +65,8 @@ class MaterialApp extends WidgetsApp {
/// The colors to use for the application's widgets. /// The colors to use for the application's widgets.
final ThemeData theme; final ThemeData theme;
final Map<String, WidgetBuilder> routes;
/// Turns on a [GridPaper] overlay that paints a baseline grid /// Turns on a [GridPaper] overlay that paints a baseline grid
/// Material apps: /// Material apps:
/// https://www.google.com/design/spec/layout/metrics-keylines.html /// https://www.google.com/design/spec/layout/metrics-keylines.html
......
...@@ -30,21 +30,28 @@ final AssetBundle _defaultBundle = _initDefaultBundle(); ...@@ -30,21 +30,28 @@ final AssetBundle _defaultBundle = _initDefaultBundle();
typedef Future<LocaleQueryData> LocaleChangedCallback(Locale locale); typedef Future<LocaleQueryData> 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 { class WidgetsApp extends StatefulWidget {
WidgetsApp({ WidgetsApp({
Key key, Key key,
this.title, this.title,
this.textStyle, this.textStyle,
this.color, this.color,
this.routes: const <String, WidgetBuilder>{},
this.onGenerateRoute, this.onGenerateRoute,
this.onLocaleChanged, this.onLocaleChanged,
this.showPerformanceOverlay: false, this.showPerformanceOverlay: false,
this.showSemanticsDebugger: false, this.showSemanticsDebugger: false,
this.debugShowCheckedModeBanner: true this.debugShowCheckedModeBanner: true
}) : super(key: key) { }) : super(key: key) {
assert(routes != null); assert(onGenerateRoute != null);
assert(routes.containsKey(Navigator.defaultRouteName) || onGenerateRoute != null);
assert(showPerformanceOverlay != null); assert(showPerformanceOverlay != null);
assert(showSemanticsDebugger != null); assert(showSemanticsDebugger != null);
} }
...@@ -62,14 +69,8 @@ class WidgetsApp extends StatefulWidget { ...@@ -62,14 +69,8 @@ class WidgetsApp extends StatefulWidget {
/// application switcher. /// application switcher.
final Color color; 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<String, WidgetBuilder> routes;
/// 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 but the name is not in the [routes] table. /// named route.
final RouteFactory onGenerateRoute; final RouteFactory onGenerateRoute;
/// Callback that is invoked when the operating system changes the /// Callback that is invoked when the operating system changes the
...@@ -179,25 +180,28 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements BindingO ...@@ -179,25 +180,28 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements BindingO
), ),
child: new LocaleQuery( child: new LocaleQuery(
data: _localeData, data: _localeData,
child: new DefaultTextStyle( child: new AssetVendor(
style: config.textStyle, bundle: _defaultBundle,
child: new AssetVendor( devicePixelRatio: ui.window.devicePixelRatio,
bundle: _defaultBundle, child: new Title(
devicePixelRatio: ui.window.devicePixelRatio, title: config.title,
child: new Title( color: config.color,
title: config.title, child: new Navigator(
color: config.color, key: _navigator,
child: new Navigator( initialRoute: ui.window.defaultRouteName,
key: _navigator, onGenerateRoute: config.onGenerateRoute,
initialRoute: ui.window.defaultRouteName, observer: navigatorObserver
onGenerateRoute: config.onGenerateRoute,
observer: navigatorObserver
)
) )
) )
) )
) )
); );
if (config.textStyle != null) {
new DefaultTextStyle(
style: config.textStyle,
child: result
);
}
if (config.showPerformanceOverlay) { if (config.showPerformanceOverlay) {
result = new Stack( result = new Stack(
children: <Widget>[ children: <Widget>[
......
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