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

If it's a StatefulComponent, then it's ok to reuse it so long as it hasn't been initialised. If it's a regular Component or a TagNode, then it's always ok to reuse. If it's a RenderObjectWrapper, then it's ok to reuse so long as it doesn't have a renderObject. To put it another way, this changes how we prevent the following nonsensical situations from arising: - Sync two stateful StatefulComponents together - Sync two RenderObjectWrappers with RenderObjects together When either of those cases happen, we just drop the old one on the ground and use the new one unchanged.
82 lines
1.8 KiB
Dart
82 lines
1.8 KiB
Dart
import 'package:sky/animation.dart';
|
|
import 'package:sky/widgets.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'widget_tester.dart';
|
|
|
|
class SecondComponent extends StatefulComponent {
|
|
SecondComponent(this.navigator);
|
|
|
|
Navigator navigator;
|
|
|
|
void syncConstructorArguments(SecondComponent source) {
|
|
navigator = source.navigator;
|
|
}
|
|
|
|
Widget build() {
|
|
return new GestureDetector(
|
|
onTap: navigator.pop,
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFFFF00FF)
|
|
),
|
|
child: new Text('Y')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
class FirstComponent extends Component {
|
|
FirstComponent(this.navigator);
|
|
|
|
final Navigator navigator;
|
|
|
|
Widget build() {
|
|
return new GestureDetector(
|
|
onTap: () {
|
|
navigator.pushNamed('/second');
|
|
},
|
|
child: new Container(
|
|
decoration: new BoxDecoration(
|
|
backgroundColor: new Color(0xFFFFFF00)
|
|
),
|
|
child: new Text('X')
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
test('Can navigator to and from a stateful component', () {
|
|
WidgetTester tester = new WidgetTester();
|
|
|
|
final NavigationState routes = new NavigationState([
|
|
new Route(
|
|
name: '/',
|
|
builder: (navigator, route) => new FirstComponent(navigator)
|
|
),
|
|
new Route(
|
|
name: '/second',
|
|
builder: (navigator, route) => new SecondComponent(navigator)
|
|
)
|
|
]);
|
|
|
|
tester.pumpFrame(() {
|
|
return new Navigator(routes);
|
|
});
|
|
|
|
tester.tap(tester.findText('X'));
|
|
scheduler.beginFrame(10.0);
|
|
scheduler.beginFrame(20.0);
|
|
scheduler.beginFrame(30.0);
|
|
scheduler.beginFrame(1000.0);
|
|
|
|
tester.tap(tester.findText('Y'));
|
|
scheduler.beginFrame(1010.0);
|
|
scheduler.beginFrame(1020.0);
|
|
scheduler.beginFrame(1030.0);
|
|
scheduler.beginFrame(2000.0);
|
|
|
|
});
|
|
}
|