Track scroll position

- Change RouteArguments to pass the route's BuildContext rather than
  the Navigator. This caused the bulk of the examples/ and .../test/
  changes (those are mostly mechanical changes). It also meant I could
  simplify Navigator.of().

- Make initState() actually get called when the State's Element is in
  the tree, so you can use Foo.of() functions there. Added a test for
  this also.

- Provide a RouteWidget so that routes have a position in the Widget
  tree. The bulk of the route logic is still in a longer-lived Route
  object for now.

- Make Route.setState() only rebuild the actual route, not the whole
  navigator.

- Provided a Route.of().

- Provided a Route.writeState / Route.readState API that tries to
  identify the clients by their runtimeType, their key, and their
  ancestors keys, up to the nearest ancestor with a GlobalKey.

- Made scrollables hook into this API to track state. Added a test to
  make sure this works.

- Fix the debug output of GestureDetector and the hashCode of
  MixedViewport.

- Fixed ScrollableWidgetListState<T> to handle infinite lists.
This commit is contained in:
Ian Hickson
2015-10-26 22:20:30 -07:00
committed by Hixie
parent e77cad81c1
commit 8a900f9042
25 changed files with 385 additions and 133 deletions

View File

@@ -65,8 +65,7 @@ class Dot extends StatelessComponent {
}
class ExampleDragSource extends StatelessComponent {
ExampleDragSource({ Key key, this.navigator, this.name, this.color }) : super(key: key);
final NavigatorState navigator;
ExampleDragSource({ Key key, this.name, this.color }) : super(key: key);
final String name;
final Color color;
@@ -75,7 +74,6 @@ class ExampleDragSource extends StatelessComponent {
Widget build(BuildContext context) {
return new Draggable(
navigator: navigator,
data: new DragData(name),
child: new Dot(color: color, size: kDotSize),
feedback: new Transform(
@@ -91,13 +89,7 @@ class ExampleDragSource extends StatelessComponent {
}
}
class DragAndDropApp extends StatefulComponent {
DragAndDropApp({ this.navigator });
final NavigatorState navigator;
DragAndDropAppState createState() => new DragAndDropAppState();
}
class DragAndDropAppState extends State<DragAndDropApp> {
class DragAndDropApp extends StatelessComponent {
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
@@ -107,9 +99,9 @@ class DragAndDropAppState extends State<DragAndDropApp> {
style: Theme.of(context).text.body1.copyWith(textAlign: TextAlign.center),
child: new Column(<Widget>[
new Flexible(child: new Row(<Widget>[
new ExampleDragSource(navigator: config.navigator, name: 'Orange', color: const Color(0xFFFF9000)),
new ExampleDragSource(navigator: config.navigator, name: 'Teal', color: const Color(0xFF00FFFF)),
new ExampleDragSource(navigator: config.navigator, name: 'Yellow', color: const Color(0xFFFFF000)),
new ExampleDragSource(name: 'Orange', color: const Color(0xFFFF9000)),
new ExampleDragSource(name: 'Teal', color: const Color(0xFF00FFFF)),
new ExampleDragSource(name: 'Yellow', color: const Color(0xFFFFF000)),
],
alignItems: FlexAlignItems.center,
justifyContent: FlexJustifyContent.spaceAround
@@ -130,7 +122,7 @@ void main() {
runApp(new MaterialApp(
title: 'Drag and Drop Flutter Demo',
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new DragAndDropApp(navigator: args.navigator)
'/': (RouteArguments args) => new DragAndDropApp()
}
));
}

View File

@@ -12,11 +12,11 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
new Text("You are at home"),
new RaisedButton(
child: new Text('GO SHOPPING'),
onPressed: () => args.navigator.pushNamed('/shopping')
onPressed: () => Navigator.of(args.context).pushNamed('/shopping')
),
new RaisedButton(
child: new Text('START ADVENTURE'),
onPressed: () => args.navigator.pushNamed('/adventure')
onPressed: () => Navigator.of(args.context).pushNamed('/adventure')
)],
justifyContent: FlexJustifyContent.center
)
@@ -28,11 +28,11 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
new Text("Village Shop"),
new RaisedButton(
child: new Text('RETURN HOME'),
onPressed: () => args.navigator.pop()
onPressed: () => Navigator.of(args.context).pop()
),
new RaisedButton(
child: new Text('GO TO DUNGEON'),
onPressed: () => args.navigator.pushNamed('/adventure')
onPressed: () => Navigator.of(args.context).pushNamed('/adventure')
)],
justifyContent: FlexJustifyContent.center
)
@@ -44,7 +44,7 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
new Text("Monster's Lair"),
new RaisedButton(
child: new Text('RUN!!!'),
onPressed: () => args.navigator.pop()
onPressed: () => Navigator.of(args.context).pop()
)],
justifyContent: FlexJustifyContent.center
)