Commit 2ef3870f authored by justin's avatar justin Committed by GitHub

Merge pull request #601 from Vadaski/master

remove useless code in boost_page_route
parents 969ea9fd 11869d5e
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -36,23 +37,14 @@ class BoostPageRoute<T> extends MaterialPageRoute<T> { ...@@ -36,23 +37,14 @@ class BoostPageRoute<T> extends MaterialPageRoute<T> {
final Set<VoidCallback> backPressedListeners = Set<VoidCallback>(); final Set<VoidCallback> backPressedListeners = Set<VoidCallback>();
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return super.buildTransitions(context, animation, secondaryAnimation, child);
}
BoostPageRoute( BoostPageRoute(
{Key stubKey, {this.pageName,
this.pageName,
this.params, this.params,
this.uniqueId, this.uniqueId,
this.animated, this.animated,
this.builder, this.builder,
this.settings}) this.settings})
: super( : super(builder: builder, settings: settings);
builder: (BuildContext context) => Stub(stubKey, builder(context)),
settings: settings);
static BoostPageRoute<T> of<T>(BuildContext context) { static BoostPageRoute<T> of<T>(BuildContext context) {
final Route<T> route = ModalRoute.of(context); final Route<T> route = ModalRoute.of(context);
...@@ -72,18 +64,3 @@ class BoostPageRoute<T> extends MaterialPageRoute<T> { ...@@ -72,18 +64,3 @@ class BoostPageRoute<T> extends MaterialPageRoute<T> {
} }
} }
} }
@immutable
class Stub extends StatefulWidget {
final Widget child;
const Stub(Key key, this.child) : super(key: key);
@override
_StubState createState() => _StubState();
}
class _StubState extends State<Stub> {
@override
Widget build(BuildContext context) => widget.child;
}
...@@ -44,4 +44,131 @@ void main() { ...@@ -44,4 +44,131 @@ void main() {
expect(find.text('Page 1'), findsNothing); expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), isOnstage); expect(find.text('Page 2'), isOnstage);
}); });
group('Try to get the BoostPageRoute in the ancestor node', () {
testWidgets(
'obtain BoostPageRoute through the `BoostPageRoute.of(context)` method',
(WidgetTester tester) async {
var boostPageRoute;
var boostPageRouteFindByOfMethod;
await tester.pumpWidget(
MaterialApp(
onGenerateRoute: (RouteSettings settings) {
boostPageRoute = BoostPageRoute<void>(
settings: settings,
builder: (BuildContext context) => Builder(
builder: (context) {
return FloatingActionButton(
onPressed: () {
boostPageRouteFindByOfMethod = BoostPageRoute.of(context);
},
);
},
),
);
return boostPageRoute;
},
),
);
await tester.tap(find.byType(FloatingActionButton));
// The route obtained from the ancestor node through the `of` method should be the same BoostPageRoute
// as the originally created BoostPageRoute
expect(boostPageRoute, boostPageRouteFindByOfMethod);
});
testWidgets(
'try to find BoostPageRoute through the `BoostPageRoute.of(context)` method, '
'but it doesn\'t exist, the method should throw an Exception',
(WidgetTester tester) async {
var contextCache;
await tester.pumpWidget(
MaterialApp(
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute(
settings: settings,
builder: (context) => Builder(
builder: (context) => FloatingActionButton(
onPressed: () {
contextCache = context;
},
),
),
);
},
),
);
await tester.tap(find.byType(FloatingActionButton));
expect(() => BoostPageRoute.of(contextCache), throwsException);
});
testWidgets(
'obtain BoostPageRoute through the `BoostPageRoute.tryOf(context)` method',
(WidgetTester tester) async {
var boostPageRoute;
var boostPageRouteFindByOfMethod;
await tester.pumpWidget(
MaterialApp(
onGenerateRoute: (RouteSettings settings) {
boostPageRoute = BoostPageRoute<void>(
settings: settings,
builder: (BuildContext context) => Builder(
builder: (context) {
return FloatingActionButton(
onPressed: () {
boostPageRouteFindByOfMethod =
BoostPageRoute.tryOf(context);
},
);
},
),
);
return boostPageRoute;
},
),
);
await tester.tap(find.byType(FloatingActionButton));
// The route obtained from the ancestor node through the `tryOf` method should be the same BoostPageRoute
// as the originally created BoostPageRoute
expect(boostPageRoute, boostPageRouteFindByOfMethod);
});
});
testWidgets(
'try to find BoostPageRoute through the `BoostPageRoute.tryOf(context)` method, '
'but it doesn\'t exist, the method should return null',
(WidgetTester tester) async {
var boostPageRouteFindByOfMethod;
await tester.pumpWidget(
MaterialApp(
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute(
settings: settings,
builder: (BuildContext context) => Builder(
builder: (context) {
return FloatingActionButton(
onPressed: () {
boostPageRouteFindByOfMethod =
BoostPageRoute.tryOf(context);
},
);
},
),
);
},
),
);
await tester.tap(find.byType(FloatingActionButton));
expect(boostPageRouteFindByOfMethod, null);
});
} }
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