From e4860ef0eb8affbb72c397819fa3412689bd63d9 Mon Sep 17 00:00:00 2001 From: gspencergoog Date: Fri, 21 Jul 2017 11:12:21 -0700 Subject: [PATCH] Fix Navigator.pop for named routes. (#11289) * Prefix and Suffix support for TextFields * Adding Tests * Removing spurious newline. * Fixing a small problem with the test * Code review changes * Code Review Changes * Review Changes * Export the new StrokeJoin enum * Added example for line styles, and enabled line join styles. * Reverting inadvertent change to main.dart. * Updated due to code review of engine code * Removed example. * Added arguments to named routes, with test. * Fixing some formatting * Fixing Navigator.pop for named routes. * Fixing comment. * Simplifying test. * Fixing new -> const for Text object. * Tiny text change (also to kick a new Travis build) * Added a more realistic test case. * Reverting unintentional iml changes. * Fixing trailing newline * Removing some changes that snuck in. --- packages/flutter/lib/src/material/app.dart | 2 +- packages/flutter/test/material/app_test.dart | 45 +++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index 8b035d443e..2a73b71acb 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -307,7 +307,7 @@ class _MaterialAppState extends State { else builder = widget.routes[name]; if (builder != null) { - return new MaterialPageRoute( + return new MaterialPageRoute( builder: builder, settings: settings, ); diff --git a/packages/flutter/test/material/app_test.dart b/packages/flutter/test/material/app_test.dart index 470e4973c8..34f5c2d094 100644 --- a/packages/flutter/test/material/app_test.dart +++ b/packages/flutter/test/material/app_test.dart @@ -106,7 +106,7 @@ void main() { return new Builder( builder: (BuildContext context) { ++buildCounter; - return new Container(); + return const Text('Y'); }, ); }, @@ -129,6 +129,7 @@ void main() { expect(buildCounter, 1); await tester.pump(const Duration(seconds: 1)); expect(buildCounter, 2); + expect(find.text('Y'), findsOneWidget); }); testWidgets('Cannot pop the initial route', (WidgetTester tester) async { @@ -171,7 +172,47 @@ void main() { expect(find.text('route "/b"'), findsNothing); }); - testWidgets('Two-step initial route', (WidgetTester tester) async { + testWidgets('Return value from pop is correct', (WidgetTester tester) async { + Future result; + await tester.pumpWidget( + new MaterialApp( + home: new Builder( + builder: (BuildContext context) { + return new Material( + child: new RaisedButton( + child: const Text('X'), + onPressed: () async { + result = Navigator.of(context).pushNamed('/a'); + } + ), + ); + } + ), + routes: { + '/a': (BuildContext context) { + return new Material( + child: new RaisedButton( + child: const Text('Y'), + onPressed: () { + Navigator.of(context).pop('all done'); + }, + ), + ); + } + }, + ) + ); + await tester.tap(find.text('X')); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + expect(find.text('Y'), findsOneWidget); + await tester.tap(find.text('Y')); + await tester.pump(); + + expect(await result, equals('all done')); + }); + + testWidgets('Two-step initial route', (WidgetTester tester) async { final Map routes = { '/': (BuildContext context) => const Text('route "/"'), '/a': (BuildContext context) => const Text('route "/a"'),