Commit 1b9476c4 authored by Ian Hickson's avatar Ian Hickson

Hide routes from the API when they're not needed. (#3431)

The 'routes' table is a point of confusion with new developers. By
providing a 'home' argument that sets the '/' route, we can delay the
point at which we teach developers about 'routes' until the point where
they want to have a second route.
parent f7360126
...@@ -24,9 +24,7 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> { ...@@ -24,9 +24,7 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
return new MaterialApp( return new MaterialApp(
theme: lightTheme ? new ThemeData.light() : new ThemeData.dark(), theme: lightTheme ? new ThemeData.light() : new ThemeData.dark(),
title: 'Advanced Layout', title: 'Advanced Layout',
routes: <String, WidgetBuilder>{ home: new ComplexLayout()
'/': (BuildContext context) => new ComplexLayout(),
}
); );
} }
......
...@@ -465,8 +465,6 @@ class CardCollectionState extends State<CardCollection> { ...@@ -465,8 +465,6 @@ class CardCollectionState extends State<CardCollection> {
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
title: 'Cards', title: 'Cards',
routes: <String, WidgetBuilder>{ home: new CardCollection()
'/': (BuildContext context) => new CardCollection(),
}
)); ));
} }
...@@ -298,8 +298,6 @@ class DragAndDropAppState extends State<DragAndDropApp> { ...@@ -298,8 +298,6 @@ class DragAndDropAppState extends State<DragAndDropApp> {
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
title: 'Drag and Drop Flutter Demo', title: 'Drag and Drop Flutter Demo',
routes: <String, WidgetBuilder>{ home: new DragAndDropApp()
'/': (BuildContext context) => new DragAndDropApp()
}
)); ));
} }
...@@ -249,6 +249,6 @@ class _WindowManagerState extends State<WindowManager> { ...@@ -249,6 +249,6 @@ class _WindowManagerState extends State<WindowManager> {
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
title: 'Mozart', title: 'Mozart',
routes: <String, WidgetBuilder>{ '/': (_) => new WindowManager() } home: new WindowManager()
)); ));
} }
...@@ -201,8 +201,6 @@ void main() { ...@@ -201,8 +201,6 @@ void main() {
accentColor: Colors.redAccent[200] accentColor: Colors.redAccent[200]
), ),
title: 'Cards', title: 'Cards',
routes: <String, WidgetBuilder>{ home: new OverlayGeometryApp()
'/': (BuildContext context) => new OverlayGeometryApp()
}
)); ));
} }
...@@ -145,8 +145,6 @@ void main() { ...@@ -145,8 +145,6 @@ void main() {
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200] accentColor: Colors.redAccent[200]
), ),
routes: <String, WidgetBuilder>{ home: new PageableListApp()
'/': (BuildContext context) => new PageableListApp(),
}
)); ));
} }
...@@ -9,12 +9,9 @@ import 'package:sky_services/sky/input_event.mojom.dart' as mojom; ...@@ -9,12 +9,9 @@ import 'package:sky_services/sky/input_event.mojom.dart' as mojom;
GlobalKey _key = new GlobalKey(); GlobalKey _key = new GlobalKey();
void main() { void main() {
runApp( runApp(new MaterialApp(
new MaterialApp(
title: "Hardware Key Demo", title: "Hardware Key Demo",
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text("Hardware Key Demo") title: new Text("Hardware Key Demo")
), ),
...@@ -23,11 +20,8 @@ void main() { ...@@ -23,11 +20,8 @@ void main() {
key: _key key: _key
) )
) )
);
}
}
) )
); ));
} }
class RawKeyboardDemo extends StatefulWidget { class RawKeyboardDemo extends StatefulWidget {
......
...@@ -301,11 +301,5 @@ class IsolateExampleState extends State<StatefulWidget> { ...@@ -301,11 +301,5 @@ class IsolateExampleState extends State<StatefulWidget> {
} }
void main() { void main() {
runApp( runApp(new MaterialApp(home: new IsolateExampleWidget()));
new MaterialApp(
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => new IsolateExampleWidget()
}
)
);
} }
...@@ -218,14 +218,9 @@ class _GestureDemoState extends State<GestureDemo> { ...@@ -218,14 +218,9 @@ class _GestureDemoState extends State<GestureDemo> {
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
theme: new ThemeData.dark(), theme: new ThemeData.dark(),
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) { appBar: new AppBar(title: new Text('Gestures Demo')),
return new Scaffold(
appBar: new AppBar(
title: new Text('Gestures Demo')),
body: new GestureDemo() body: new GestureDemo()
); )
}
}
)); ));
} }
...@@ -100,15 +100,11 @@ final List<String> _kNames = _initNames(); ...@@ -100,15 +100,11 @@ final List<String> _kNames = _initNames();
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
title: 'Media Query Example', title: 'Media Query Example',
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('Media Query Example') title: new Text('Media Query Example')
), ),
body: new Material(child: new AdaptiveContainer(names: _kNames)) body: new Material(child: new AdaptiveContainer(names: _kNames))
); )
}
}
)); ));
} }
...@@ -153,16 +153,12 @@ class SectorAppState extends State<SectorApp> { ...@@ -153,16 +153,12 @@ class SectorAppState extends State<SectorApp> {
return new MaterialApp( return new MaterialApp(
theme: new ThemeData.light(), theme: new ThemeData.light(),
title: 'Sector Layout', title: 'Sector Layout',
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('Sector Layout in a Widget Tree') title: new Text('Sector Layout in a Widget Tree')
), ),
body: buildBody() body: buildBody()
); )
}
}
); );
} }
} }
......
...@@ -122,17 +122,14 @@ class _StyledTextDemoState extends State<StyledTextDemo> { ...@@ -122,17 +122,14 @@ class _StyledTextDemoState extends State<StyledTextDemo> {
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
theme: new ThemeData.light(), theme: new ThemeData.light(),
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: new Text('Hal and Dave')), title: new Text('Hal and Dave')
),
body: new Material( body: new Material(
color: Colors.grey[50], color: Colors.grey[50],
child: new StyledTextDemo() child: new StyledTextDemo()
) )
); )
}
}
)); ));
} }
...@@ -24,8 +24,7 @@ class GalleryAppState extends State<GalleryApp> { ...@@ -24,8 +24,7 @@ class GalleryAppState extends State<GalleryApp> {
title: 'Flutter Material Gallery', title: 'Flutter Material Gallery',
theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme, theme: _useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme,
showPerformanceOverlay: _showPerformanceOverlay, showPerformanceOverlay: _showPerformanceOverlay,
routes: { home: new GalleryHome(
'/': (BuildContext context) => new GalleryHome(
useLightTheme: _useLightTheme, useLightTheme: _useLightTheme,
onThemeChanged: (bool value) { setState(() { _useLightTheme = value; }); }, onThemeChanged: (bool value) { setState(() { _useLightTheme = value; }); },
showPerformanceOverlay: _showPerformanceOverlay, showPerformanceOverlay: _showPerformanceOverlay,
...@@ -33,7 +32,6 @@ class GalleryAppState extends State<GalleryApp> { ...@@ -33,7 +32,6 @@ class GalleryAppState extends State<GalleryApp> {
timeDilation: timeDilation, timeDilation: timeDilation,
onTimeDilationChanged: (double value) { setState(() { timeDilation = value; }); } onTimeDilationChanged: (double value) { setState(() { timeDilation = value; }); }
) )
}
); );
} }
} }
......
...@@ -36,10 +36,18 @@ const TextStyle _errorTextStyle = const TextStyle( ...@@ -36,10 +36,18 @@ const TextStyle _errorTextStyle = const TextStyle(
/// * [Scaffold] /// * [Scaffold]
/// * [MaterialPageRoute] /// * [MaterialPageRoute]
class MaterialApp extends WidgetsApp { class MaterialApp extends WidgetsApp {
/// Creates a MaterialApp.
///
/// At least one of [home], [routes], or [onGenerateRoute] must be
/// given. If only [routes] is given, it must include an entry for
/// the [Navigator.defaultRouteName] (`'/'`).
///
/// See also the [new WidgetsApp] constructor (which this extends).
MaterialApp({ MaterialApp({
Key key, Key key,
String title, String title,
ThemeData theme, ThemeData theme,
Widget home,
Map<String, WidgetBuilder> routes: const <String, WidgetBuilder>{}, Map<String, WidgetBuilder> routes: const <String, WidgetBuilder>{},
RouteFactory onGenerateRoute, RouteFactory onGenerateRoute,
LocaleChangedCallback onLocaleChanged, LocaleChangedCallback onLocaleChanged,
...@@ -48,6 +56,7 @@ class MaterialApp extends WidgetsApp { ...@@ -48,6 +56,7 @@ class MaterialApp extends WidgetsApp {
bool showSemanticsDebugger: false, bool showSemanticsDebugger: false,
bool debugShowCheckedModeBanner: true bool debugShowCheckedModeBanner: true
}) : theme = theme, }) : theme = theme,
home = home,
routes = routes, routes = routes,
super( super(
key: key, key: key,
...@@ -56,6 +65,8 @@ class MaterialApp extends WidgetsApp { ...@@ -56,6 +65,8 @@ class MaterialApp extends WidgetsApp {
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
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
WidgetBuilder builder = routes[settings.name]; WidgetBuilder builder = routes[settings.name];
if (builder == null && home != null && settings.name == Navigator.defaultRouteName)
builder = (BuildContext context) => home;
if (builder != null) { if (builder != null) {
return new MaterialPageRoute<Null>( return new MaterialPageRoute<Null>(
builder: builder, builder: builder,
...@@ -72,17 +83,45 @@ class MaterialApp extends WidgetsApp { ...@@ -72,17 +83,45 @@ class MaterialApp extends WidgetsApp {
debugShowCheckedModeBanner: debugShowCheckedModeBanner debugShowCheckedModeBanner: debugShowCheckedModeBanner
) { ) {
assert(debugShowMaterialGrid != null); assert(debugShowMaterialGrid != null);
assert(routes != null);
assert(!routes.containsKey(Navigator.defaultRouteName) || (home == null));
assert(routes.containsKey(Navigator.defaultRouteName) || (home != null) || (onGenerateRoute != null));
} }
/// The colors to use for the application's widgets. /// The colors to use for the application's widgets.
final ThemeData theme; final ThemeData theme;
/// The widget for the default route of the app
/// ([Navigator.defaultRouteName], which is `'/'`).
///
/// This is the page that is displayed first when the application is
/// started normally.
///
/// To be able to directly call [Theme.of], [MediaQuery.of],
/// [LocaleQuery.of], etc, in the code sets the [home] argument in
/// the constructor, you can use a [Builder] widget to get a
/// [BuildContext].
///
/// If this is not specified, then either the route with name `'/'`
/// must be given in [routes], or the [onGenerateRoute] callback
/// must be able to build a widget for that route.
final Widget home;
/// The application's top-level routing table. /// The application's top-level routing table.
/// ///
/// When a named route is pushed with [Navigator.pushNamed], the route name is /// When a named route is pushed with [Navigator.pushNamed], the route name is
/// looked up in this map. If the name is present, the associated /// looked up in this map. If the name is present, the associated
/// [WidgetBuilder] is used to construct a [MaterialPageRoute] that performs /// [WidgetBuilder] is used to construct a [MaterialPageRoute] that performs
/// an appropriate transition, including [Hero] animations, to the new route. /// an appropriate transition, including [Hero] animations, to the new route.
///
/// If the app only has one page, then you can specify it using [home] instead.
///
/// If [home] is specified, then it is an error to provide a route
/// in this map for the [Navigator.defaultRouteName] route (`'/'`).
///
/// If a route is requested that is not specified in this table (or
/// by [home]), then the [onGenerateRoute] callback is invoked to
/// build the page instead.
final Map<String, WidgetBuilder> routes; 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
......
...@@ -66,9 +66,12 @@ class MaterialPageRoute<T> extends PageRoute<T> { ...@@ -66,9 +66,12 @@ class MaterialPageRoute<T> extends PageRoute<T> {
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> forwardAnimation) { Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> forwardAnimation) {
Widget result = builder(context); Widget result = builder(context);
assert(() { assert(() {
if (result == null) if (result == null) {
debugPrint('The builder for route \'${settings.name}\' returned null. Route builders must never return null.'); throw new FlutterError(
assert(result != null && 'A route builder returned null. See the previous log message for details.' is String); 'The builder for route "${settings.name}" returned null.\n'
'Route builders must never return null.'
);
}
return true; return true;
}); });
return result; return result;
......
...@@ -12,9 +12,7 @@ void main() { ...@@ -12,9 +12,7 @@ void main() {
String helloSnackBar = 'Hello SnackBar'; String helloSnackBar = 'Hello SnackBar';
Key tapTarget = new Key('tap-target'); Key tapTarget = new Key('tap-target');
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
body: new Builder( body: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new GestureDetector( return new GestureDetector(
...@@ -33,9 +31,7 @@ void main() { ...@@ -33,9 +31,7 @@ void main() {
); );
} }
) )
); )
}
}
)); ));
expect(tester, doesNotHaveWidget(find.text(helloSnackBar))); expect(tester, doesNotHaveWidget(find.text(helloSnackBar)));
tester.tap(find.byKey(tapTarget)); tester.tap(find.byKey(tapTarget));
...@@ -63,9 +59,7 @@ void main() { ...@@ -63,9 +59,7 @@ void main() {
int snackBarCount = 0; int snackBarCount = 0;
Key tapTarget = new Key('tap-target'); Key tapTarget = new Key('tap-target');
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
body: new Builder( body: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new GestureDetector( return new GestureDetector(
...@@ -85,9 +79,7 @@ void main() { ...@@ -85,9 +79,7 @@ void main() {
); );
} }
) )
); )
}
}
)); ));
expect(tester, doesNotHaveWidget(find.text('bar1'))); expect(tester, doesNotHaveWidget(find.text('bar1')));
expect(tester, doesNotHaveWidget(find.text('bar2'))); expect(tester, doesNotHaveWidget(find.text('bar2')));
...@@ -146,9 +138,7 @@ void main() { ...@@ -146,9 +138,7 @@ void main() {
int time; int time;
ScaffoldFeatureController<SnackBar, Null> lastController; ScaffoldFeatureController<SnackBar, Null> lastController;
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
body: new Builder( body: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new GestureDetector( return new GestureDetector(
...@@ -168,9 +158,7 @@ void main() { ...@@ -168,9 +158,7 @@ void main() {
); );
} }
) )
); )
}
}
)); ));
expect(tester, doesNotHaveWidget(find.text('bar1'))); expect(tester, doesNotHaveWidget(find.text('bar1')));
expect(tester, doesNotHaveWidget(find.text('bar2'))); expect(tester, doesNotHaveWidget(find.text('bar2')));
...@@ -236,9 +224,7 @@ void main() { ...@@ -236,9 +224,7 @@ void main() {
int snackBarCount = 0; int snackBarCount = 0;
Key tapTarget = new Key('tap-target'); Key tapTarget = new Key('tap-target');
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
body: new Builder( body: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new GestureDetector( return new GestureDetector(
...@@ -258,9 +244,7 @@ void main() { ...@@ -258,9 +244,7 @@ void main() {
); );
} }
) )
); )
}
}
)); ));
expect(tester, doesNotHaveWidget(find.text('bar1'))); expect(tester, doesNotHaveWidget(find.text('bar1')));
expect(tester, doesNotHaveWidget(find.text('bar2'))); expect(tester, doesNotHaveWidget(find.text('bar2')));
...@@ -286,9 +270,7 @@ void main() { ...@@ -286,9 +270,7 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
int tapCount = 0; int tapCount = 0;
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
body: new Builder( body: new Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return new GestureDetector( return new GestureDetector(
...@@ -308,9 +290,7 @@ void main() { ...@@ -308,9 +290,7 @@ void main() {
); );
} }
) )
); )
}
}
)); ));
tester.tap(find.text('X')); tester.tap(find.text('X'));
tester.pump(); // start animation tester.pump(); // start animation
......
...@@ -14,19 +14,15 @@ void main() { ...@@ -14,19 +14,15 @@ void main() {
int buildCount = 0; int buildCount = 0;
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
key: scaffoldKey, key: scaffoldKey,
body: new Center(child: new Text('body')) body: new Center(child: new Text('body'))
); )
}
}
)); ));
bottomSheet = scaffoldKey.currentState.showBottomSheet/*<Null>*/((_) { bottomSheet = scaffoldKey.currentState.showBottomSheet/*<Null>*/((_) {
return new Builder( return new Builder(
builder: (_) { builder: (BuildContext context) {
buildCount += 1; buildCount += 1;
return new Container(height: 200.0); return new Container(height: 200.0);
} }
......
...@@ -10,23 +10,23 @@ import 'package:test/test.dart'; ...@@ -10,23 +10,23 @@ import 'package:test/test.dart';
void main() { void main() {
test('Verify that a tap dismisses a modal BottomSheet', () { test('Verify that a tap dismisses a modal BottomSheet', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
BuildContext context; BuildContext savedContext;
bool showBottomSheetThenCalled = false; bool showBottomSheetThenCalled = false;
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Builder(
'/': (BuildContext ctx) { builder: (BuildContext context) {
context = ctx; savedContext = context;
return new Container(); return new Container();
} }
} )
)); ));
tester.pump(); tester.pump();
expect(tester, doesNotHaveWidget(find.text('BottomSheet'))); expect(tester, doesNotHaveWidget(find.text('BottomSheet')));
showModalBottomSheet/*<Null>*/( showModalBottomSheet/*<Null>*/(
context: context, context: savedContext,
builder: (BuildContext context) => new Text('BottomSheet') builder: (BuildContext context) => new Text('BottomSheet')
).then((Null result) { ).then((Null result) {
expect(result, isNull); expect(result, isNull);
...@@ -46,7 +46,7 @@ void main() { ...@@ -46,7 +46,7 @@ void main() {
tester.pump(new Duration(seconds: 1)); // frame after the animation (sheet has been removed) tester.pump(new Duration(seconds: 1)); // frame after the animation (sheet has been removed)
expect(tester, doesNotHaveWidget(find.text('BottomSheet'))); expect(tester, doesNotHaveWidget(find.text('BottomSheet')));
showModalBottomSheet/*<Null>*/(context: context, builder: (BuildContext context) => new Text('BottomSheet')); showModalBottomSheet/*<Null>*/(context: savedContext, builder: (BuildContext context) => new Text('BottomSheet'));
tester.pump(); // bottom sheet show animation starts tester.pump(); // bottom sheet show animation starts
tester.pump(new Duration(seconds: 1)); // animation done tester.pump(new Duration(seconds: 1)); // animation done
expect(tester, hasWidget(find.text('BottomSheet'))); expect(tester, hasWidget(find.text('BottomSheet')));
...@@ -66,14 +66,10 @@ void main() { ...@@ -66,14 +66,10 @@ void main() {
bool showBottomSheetThenCalled = false; bool showBottomSheetThenCalled = false;
tester.pumpWidget(new MaterialApp( tester.pumpWidget(new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
key: scaffoldKey, key: scaffoldKey,
body: new Center(child: new Text('body')) body: new Center(child: new Text('body'))
); )
}
}
)); ));
expect(showBottomSheetThenCalled, isFalse); expect(showBottomSheetThenCalled, isFalse);
......
...@@ -12,19 +12,19 @@ void main() { ...@@ -12,19 +12,19 @@ void main() {
test('Drawer control test', () { test('Drawer control test', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(); GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
BuildContext context; BuildContext savedContext;
tester.pumpWidget( tester.pumpWidget(
new MaterialApp( new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Builder(
'/': (BuildContext ctx) { builder: (BuildContext context) {
context = ctx; savedContext = context;
return new Scaffold( return new Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: new Text('drawer'), drawer: new Text('drawer'),
body: new Container() body: new Container()
); );
} }
} )
) )
); );
tester.pump(); // no effect tester.pump(); // no effect
...@@ -34,7 +34,7 @@ void main() { ...@@ -34,7 +34,7 @@ void main() {
expect(tester, hasWidget(find.text('drawer'))); expect(tester, hasWidget(find.text('drawer')));
tester.pump(new Duration(seconds: 1)); // animation done tester.pump(new Duration(seconds: 1)); // animation done
expect(tester, hasWidget(find.text('drawer'))); expect(tester, hasWidget(find.text('drawer')));
Navigator.pop(context); Navigator.pop(savedContext);
tester.pump(); // drawer should be starting to animate away tester.pump(); // drawer should be starting to animate away
expect(tester, hasWidget(find.text('drawer'))); expect(tester, hasWidget(find.text('drawer')));
tester.pump(new Duration(seconds: 1)); // animation done tester.pump(new Duration(seconds: 1)); // animation done
...@@ -47,15 +47,11 @@ void main() { ...@@ -47,15 +47,11 @@ void main() {
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(); GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
tester.pumpWidget( tester.pumpWidget(
new MaterialApp( new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: new Text('drawer'), drawer: new Text('drawer'),
body: new Container() body: new Container()
); )
}
}
) )
); );
tester.pump(); // no effect tester.pump(); // no effect
...@@ -85,9 +81,7 @@ void main() { ...@@ -85,9 +81,7 @@ void main() {
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>(); GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
tester.pumpWidget( tester.pumpWidget(
new MaterialApp( new MaterialApp(
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) {
return new Scaffold(
key: scaffoldKey, key: scaffoldKey,
drawer: new Drawer( drawer: new Drawer(
child: new Block( child: new Block(
...@@ -103,9 +97,7 @@ void main() { ...@@ -103,9 +97,7 @@ void main() {
) )
), ),
body: new Container() body: new Container()
); )
}
}
) )
); );
expect(tester, doesNotHaveWidget(find.text('drawer'))); expect(tester, doesNotHaveWidget(find.text('drawer')));
......
...@@ -21,7 +21,7 @@ You can use [hyperlinks](hyperlink) in markdown ...@@ -21,7 +21,7 @@ You can use [hyperlinks](hyperlink) in markdown
## Code blocks ## Code blocks
Formatted Dart code looks really pretty too. This is an example of how to create your own Markdown widget: Formatted Dart code looks really pretty too. This is an example of how to create your own Markdown widget:
new Markdown(data: "Hello _world_!"); new Markdown(data: 'Hello _world_!');
Enjoy! Enjoy!
"""; """;
...@@ -29,11 +29,9 @@ Enjoy! ...@@ -29,11 +29,9 @@ Enjoy!
void main() { void main() {
runApp(new MaterialApp( runApp(new MaterialApp(
title: "Markdown Demo", title: "Markdown Demo",
routes: <String, WidgetBuilder>{ home: new Scaffold(
'/': (BuildContext context) => new Scaffold( appBar: new AppBar(title: new Text('Markdown Demo')),
appBar: new AppBar(title: new Text("Markdown Demo")),
body: new Markdown(data: _kMarkdownData) body: new Markdown(data: _kMarkdownData)
) )
}
)); ));
} }
...@@ -15,9 +15,7 @@ void main() { ...@@ -15,9 +15,7 @@ void main() {
theme: new ThemeData( theme: new ThemeData(
primarySwatch: Colors.blue primarySwatch: Colors.blue
), ),
routes: <String, WidgetBuilder>{ home: new FlutterDemo()
'/': (BuildContext context) => new FlutterDemo()
}
) )
); );
} }
......
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