mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

(These are changes cherry-picked from in-flight branches since they are more independent and could be helpful even without those changes.) - Change RouteBuilder's signature to take a single argument in which the other fields are placed, so that we can keep iterating on those arguments without having to break compatibility each time. Also, this makes defining route builders much simpler (only one argument to ignore rather than a variable number). - Expose the next performance to RouteBuilders, since sometimes the route itself might not be where it's used. - Allow BuildContext to be used to walk children, just like it can for ancestors - Allow BuildContext to be used to get the Widget of the current BuildContext - Allow StatefulComponentElement to be referenced with a type specialisation so that you don't have to cast when you know what the type you're dealing with actually is.
82 lines
2.2 KiB
Dart
82 lines
2.2 KiB
Dart
import 'package:sky/widgets.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'widget_tester.dart';
|
|
|
|
class FirstComponent extends StatelessComponent {
|
|
FirstComponent(this.navigator);
|
|
|
|
final NavigatorState navigator;
|
|
|
|
Widget build(BuildContext context) {
|
|
return new GestureDetector(
|
|
onTap: () {
|
|
navigator.pushNamed('/second');
|
|
},
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFFFFFF00)
|
|
),
|
|
child: new Text('X')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
class SecondComponent extends StatefulComponent {
|
|
SecondComponent(this.navigator);
|
|
|
|
final NavigatorState navigator;
|
|
|
|
SecondComponentState createState() => new SecondComponentState();
|
|
}
|
|
|
|
class SecondComponentState extends State<SecondComponent> {
|
|
Widget build(BuildContext context) {
|
|
return new GestureDetector(
|
|
onTap: config.navigator.pop,
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFFFF00FF)
|
|
),
|
|
child: new Text('Y')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
test('Can navigator navigate to and from a stateful component', () {
|
|
testWidgets((WidgetTester tester) {
|
|
final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
|
|
'/': (RouteArguments args) => new FirstComponent(args.navigator),
|
|
'/second': (RouteArguments args) => new SecondComponent(args.navigator),
|
|
};
|
|
|
|
tester.pumpWidget(new Navigator(routes: routes));
|
|
|
|
expect(tester.findText('X'), isNotNull);
|
|
expect(tester.findText('Y'), isNull);
|
|
|
|
tester.tap(tester.findText('X'));
|
|
tester.pump(const Duration(milliseconds: 10));
|
|
|
|
expect(tester.findText('X'), isNotNull);
|
|
expect(tester.findText('Y'), isNotNull);
|
|
|
|
tester.pump(const Duration(milliseconds: 10));
|
|
tester.pump(const Duration(milliseconds: 10));
|
|
tester.pump(const Duration(seconds: 1));
|
|
|
|
tester.tap(tester.findText('Y'));
|
|
tester.pump(const Duration(milliseconds: 10));
|
|
tester.pump(const Duration(milliseconds: 10));
|
|
tester.pump(const Duration(milliseconds: 10));
|
|
tester.pump(const Duration(seconds: 1));
|
|
|
|
expect(tester.findText('X'), isNotNull);
|
|
expect(tester.findText('Y'), isNull);
|
|
});
|
|
});
|
|
}
|