Commit 743be674 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Split ScrollableViewport2 from Scrolllable2 (#7707)

This structure makes it easier to customize the viewport used in a Scrollable.
Now Scrollable2 doesn't commit to using slivers.
parent 573e7c1b
...@@ -19,7 +19,6 @@ class ScrollView extends StatelessWidget { ...@@ -19,7 +19,6 @@ class ScrollView extends StatelessWidget {
this.scrollDirection: Axis.vertical, this.scrollDirection: Axis.vertical,
this.anchor: 0.0, this.anchor: 0.0,
this.initialScrollOffset: 0.0, this.initialScrollOffset: 0.0,
this.scrollBehavior,
this.center, this.center,
this.children, this.children,
}) : super(key: key); }) : super(key: key);
...@@ -32,8 +31,6 @@ class ScrollView extends StatelessWidget { ...@@ -32,8 +31,6 @@ class ScrollView extends StatelessWidget {
final double initialScrollOffset; final double initialScrollOffset;
final ScrollBehavior2 scrollBehavior;
final Key center; final Key center;
final List<Widget> children; final List<Widget> children;
...@@ -56,13 +53,12 @@ class ScrollView extends StatelessWidget { ...@@ -56,13 +53,12 @@ class ScrollView extends StatelessWidget {
if (padding != null) if (padding != null)
sliver = new SliverPadding(padding: padding, child: sliver); sliver = new SliverPadding(padding: padding, child: sliver);
return new Scrollable2( return new ScrollableViewport2(
axisDirection: _getDirection(context), axisDirection: _getDirection(context),
anchor: anchor, anchor: anchor,
initialScrollOffset: initialScrollOffset, initialScrollOffset: initialScrollOffset,
scrollBehavior: scrollBehavior,
center: center, center: center,
children: <Widget>[ sliver ], slivers: <Widget>[ sliver ],
); );
} }
} }
......
...@@ -78,25 +78,6 @@ class ViewportScrollBehavior extends ScrollBehavior2 { ...@@ -78,25 +78,6 @@ class ViewportScrollBehavior extends ScrollBehavior2 {
return null; return null;
} }
@override
Widget createViewport({
Key key,
AxisDirection axisDirection: AxisDirection.down,
double anchor: 0.0,
ViewportOffset offset,
Key center,
List<Widget> children: const <Widget>[],
}) {
return new Viewport2(
key: key,
axisDirection: axisDirection,
anchor: anchor,
offset: offset,
center: center,
children: children,
);
}
@override @override
ScrollPosition createScrollPosition(BuildContext context, Scrollable2State state, ScrollPosition oldPosition) { ScrollPosition createScrollPosition(BuildContext context, Scrollable2State state, ScrollPosition oldPosition) {
switch (getPlatform(context)) { switch (getPlatform(context)) {
......
...@@ -131,7 +131,7 @@ abstract class ScrollPosition extends ViewportOffset { ...@@ -131,7 +131,7 @@ abstract class ScrollPosition extends ViewportOffset {
@protected @protected
void dispatchNotification(Notification notification) { void dispatchNotification(Notification notification) {
assert(state.mounted); assert(state.mounted);
notification.dispatch(state._viewportKey.currentContext); notification.dispatch(state._gestureDetectorKey.currentContext);
} }
@override @override
...@@ -352,15 +352,6 @@ abstract class ScrollBehavior2 { ...@@ -352,15 +352,6 @@ abstract class ScrollBehavior2 {
Widget wrap(BuildContext context, Widget child, AxisDirection axisDirection); Widget wrap(BuildContext context, Widget child, AxisDirection axisDirection);
Widget createViewport({
Key key,
AxisDirection axisDirection: AxisDirection.down,
double anchor: 0.0,
ViewportOffset offset,
Key center,
List<Widget> children: const <Widget>[],
});
/// Returns a new instance of the ScrollPosition class that this /// Returns a new instance of the ScrollPosition class that this
/// ScrollBehavior2 subclass creates. /// ScrollBehavior2 subclass creates.
/// ///
...@@ -391,48 +382,6 @@ abstract class ScrollBehavior2 { ...@@ -391,48 +382,6 @@ abstract class ScrollBehavior2 {
String toString() => '$runtimeType'; String toString() => '$runtimeType';
} }
abstract class ScrollBehavior2Proxy extends ScrollBehavior2 {
ScrollBehavior2Proxy(this.parent) {
assert(parent != null);
}
final ScrollBehavior2 parent;
@override
Widget wrap(BuildContext context, Widget child, AxisDirection axisDirection) {
return parent.wrap(context, child, axisDirection);
}
@override
Widget createViewport({
Key key,
AxisDirection axisDirection: AxisDirection.down,
double anchor: 0.0,
ViewportOffset offset,
Key center,
List<Widget> children: const <Widget>[],
}) {
return parent.createViewport(
key: key,
axisDirection: axisDirection,
anchor: anchor,
offset: offset,
center: center,
children: children,
);
}
@override
ScrollPosition createScrollPosition(BuildContext context, Scrollable2State state, ScrollPosition oldPosition) {
return parent.createScrollPosition(context, state, oldPosition);
}
@override
bool shouldNotify(@checked ScrollBehavior2Proxy oldDelegate) {
return parent.shouldNotify(oldDelegate.parent);
}
}
class ScrollConfiguration2 extends InheritedWidget { class ScrollConfiguration2 extends InheritedWidget {
const ScrollConfiguration2({ const ScrollConfiguration2({
Key key, Key key,
...@@ -455,27 +404,83 @@ class ScrollConfiguration2 extends InheritedWidget { ...@@ -455,27 +404,83 @@ class ScrollConfiguration2 extends InheritedWidget {
} }
} }
class Scrollable2 extends StatefulWidget { class ScrollableViewport2 extends StatelessWidget {
Scrollable2({ ScrollableViewport2({
Key key, Key key,
this.initialScrollOffset: 0.0,
this.axisDirection: AxisDirection.down, this.axisDirection: AxisDirection.down,
this.anchor: 0.0, this.anchor: 0.0,
this.initialScrollOffset: 0.0,
this.scrollBehavior,
this.center, this.center,
this.children, this.scrollBehavior,
}) : super (key: key) { this.slivers: const <Widget>[],
assert(axisDirection != null); }) {
assert(anchor != null); assert(slivers != null);
assert(initialScrollOffset != null);
} }
final double initialScrollOffset;
final AxisDirection axisDirection; final AxisDirection axisDirection;
final double anchor; final double anchor;
final Key center;
final ScrollBehavior2 scrollBehavior;
final List<Widget> slivers;
Axis get axis => axisDirectionToAxis(axisDirection);
@override
Widget build(BuildContext context) {
return new Scrollable2(
initialScrollOffset: initialScrollOffset,
axisDirection: axisDirection,
scrollBehavior: scrollBehavior,
viewportBuilder: (BuildContext context, ViewportOffset offset) {
return new Viewport2(
axisDirection: axisDirection,
anchor: anchor,
offset: offset,
center: center,
slivers: slivers,
);
}
);
}
@override
void debugFillDescription(List<String> description) {
super.debugFillDescription(description);
description.add('$axisDirection');
if (anchor != 0.0)
description.add('anchor: ${anchor.toStringAsFixed(1)}');
if (initialScrollOffset != 0.0)
description.add('initialScrollOffset: ${initialScrollOffset.toStringAsFixed(1)}');
if (center != null)
description.add('center: $center');
}
}
typedef Widget ViewportBuilder(BuildContext context, ViewportOffset position);
class Scrollable2 extends StatefulWidget {
Scrollable2({
Key key,
this.initialScrollOffset: 0.0,
this.axisDirection: AxisDirection.down,
this.scrollBehavior,
@required this.viewportBuilder,
}) : super (key: key) {
assert(axisDirection != null);
assert(initialScrollOffset != null);
assert(viewportBuilder != null);
}
final double initialScrollOffset; final double initialScrollOffset;
final AxisDirection axisDirection;
/// The delegate that creates the [ScrollPosition] and wraps the viewport /// The delegate that creates the [ScrollPosition] and wraps the viewport
/// in extra widgets (e.g. for overscroll effects). /// in extra widgets (e.g. for overscroll effects).
/// ///
...@@ -484,9 +489,7 @@ class Scrollable2 extends StatefulWidget { ...@@ -484,9 +489,7 @@ class Scrollable2 extends StatefulWidget {
/// [ScrollConfiguration2] in scope, a new [ViewportScrollBehavior] is used. /// [ScrollConfiguration2] in scope, a new [ViewportScrollBehavior] is used.
final ScrollBehavior2 scrollBehavior; final ScrollBehavior2 scrollBehavior;
final Key center; final ViewportBuilder viewportBuilder;
final List<Widget> children;
Axis get axis => axisDirectionToAxis(axisDirection); Axis get axis => axisDirectionToAxis(axisDirection);
...@@ -509,8 +512,6 @@ class Scrollable2 extends StatefulWidget { ...@@ -509,8 +512,6 @@ class Scrollable2 extends StatefulWidget {
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
super.debugFillDescription(description); super.debugFillDescription(description);
description.add('$axisDirection'); description.add('$axisDirection');
if (anchor != 0.0)
description.add('anchor: ${anchor.toStringAsFixed(1)}');
if (initialScrollOffset != 0.0) if (initialScrollOffset != 0.0)
description.add('initialScrollOffset: ${initialScrollOffset.toStringAsFixed(1)}'); description.add('initialScrollOffset: ${initialScrollOffset.toStringAsFixed(1)}');
if (scrollBehavior != null) { if (scrollBehavior != null) {
...@@ -518,8 +519,6 @@ class Scrollable2 extends StatefulWidget { ...@@ -518,8 +519,6 @@ class Scrollable2 extends StatefulWidget {
} else { } else {
description.add('scrollBehavior: use inherited ScrollBehavior2'); description.add('scrollBehavior: use inherited ScrollBehavior2');
} }
if (center != null)
description.add('center: $center');
} }
} }
...@@ -552,9 +551,9 @@ class Scrollable2State extends State<Scrollable2> with TickerProviderStateMixin ...@@ -552,9 +551,9 @@ class Scrollable2State extends State<Scrollable2> with TickerProviderStateMixin
_position = _scrollBehavior.createScrollPosition(context, this, oldPosition); _position = _scrollBehavior.createScrollPosition(context, this, oldPosition);
assert(position != null); assert(position != null);
if (oldPosition != null) { if (oldPosition != null) {
// It's important that we not do this until after the RenderViewport2 // It's important that we not do this until after the viewport has had a
// object has had a chance to unregister its listeners from the old // chance to unregister its listeners from the old position. So, schedule
// position. So, schedule a microtask to do it. // a microtask to do it.
scheduleMicrotask(oldPosition.dispose); scheduleMicrotask(oldPosition.dispose);
} }
} }
...@@ -583,7 +582,6 @@ class Scrollable2State extends State<Scrollable2> with TickerProviderStateMixin ...@@ -583,7 +582,6 @@ class Scrollable2State extends State<Scrollable2> with TickerProviderStateMixin
final GlobalKey<RawGestureDetectorState> _gestureDetectorKey = new GlobalKey<RawGestureDetectorState>(); final GlobalKey<RawGestureDetectorState> _gestureDetectorKey = new GlobalKey<RawGestureDetectorState>();
final GlobalKey _ignorePointerKey = new GlobalKey(); final GlobalKey _ignorePointerKey = new GlobalKey();
final GlobalKey _viewportKey = new GlobalKey();
// This field is set during layout, and then reused until the next time it is set. // This field is set during layout, and then reused until the next time it is set.
Map<Type, GestureRecognizerFactory> _gestureRecognizers = const <Type, GestureRecognizerFactory>{}; Map<Type, GestureRecognizerFactory> _gestureRecognizers = const <Type, GestureRecognizerFactory>{};
...@@ -692,14 +690,7 @@ class Scrollable2State extends State<Scrollable2> with TickerProviderStateMixin ...@@ -692,14 +690,7 @@ class Scrollable2State extends State<Scrollable2> with TickerProviderStateMixin
child: new IgnorePointer( child: new IgnorePointer(
key: _ignorePointerKey, key: _ignorePointerKey,
ignoring: _shouldIgnorePointer, ignoring: _shouldIgnorePointer,
child: _scrollBehavior.createViewport( child: config.viewportBuilder(context, position),
key: _viewportKey,
axisDirection: config.axisDirection,
anchor: config.anchor,
offset: position,
center: config.center,
children: config.children,
),
), ),
); );
return _scrollBehavior.wrap(context, result, config.axisDirection); return _scrollBehavior.wrap(context, result, config.axisDirection);
......
...@@ -40,38 +40,18 @@ class SingleChildScrollView extends StatelessWidget { ...@@ -40,38 +40,18 @@ class SingleChildScrollView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ScrollBehavior2 scrollBehavior = new _SingleChildScrollViewBehavior( final AxisDirection axisDirection = _getDirection(context);
Scrollable2.getScrollBehavior(context)
);
return new Scrollable2( return new Scrollable2(
axisDirection: _getDirection(context), axisDirection: axisDirection,
initialScrollOffset: initialScrollOffset, initialScrollOffset: initialScrollOffset,
scrollBehavior: scrollBehavior, viewportBuilder: (BuildContext context, ViewportOffset offset) {
children: child == null ? const <Widget>[] : <Widget>[ child ],
);
}
}
class _SingleChildScrollViewBehavior extends ScrollBehavior2Proxy {
_SingleChildScrollViewBehavior(ScrollBehavior2 parent) : super(parent);
@override
Widget createViewport({
Key key,
AxisDirection axisDirection: AxisDirection.down,
double anchor: 0.0,
ViewportOffset offset,
Key center,
List<Widget> children: const <Widget>[],
}) {
assert(anchor == 0.0);
assert(center == null);
assert(children.length <= 1);
return new _SingleChildViewport( return new _SingleChildViewport(
key: key, key: key,
axisDirection: axisDirection, axisDirection: axisDirection,
offset: offset, offset: offset,
child: children.isEmpty ? null : children[0], child: child,
);
},
); );
} }
} }
......
...@@ -18,8 +18,8 @@ class Viewport2 extends MultiChildRenderObjectWidget { ...@@ -18,8 +18,8 @@ class Viewport2 extends MultiChildRenderObjectWidget {
this.anchor: 0.0, this.anchor: 0.0,
@required this.offset, @required this.offset,
this.center, this.center,
List<Widget> children: const <Widget>[], List<Widget> slivers: const <Widget>[],
}) : super(key: key, children: children) { }) : super(key: key, children: slivers) {
assert(offset != null); assert(offset != null);
assert(center == null || children.where((Widget child) => child.key == center).length == 1); assert(center == null || children.where((Widget child) => child.key == center).length == 1);
} }
......
...@@ -24,8 +24,8 @@ Future<Null> slowDrag(WidgetTester tester, Point start, Offset offset) async { ...@@ -24,8 +24,8 @@ Future<Null> slowDrag(WidgetTester tester, Point start, Offset offset) async {
void main() { void main() {
testWidgets('Overscroll indicator color', (WidgetTester tester) async { testWidgets('Overscroll indicator color', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)), new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)),
], ],
), ),
...@@ -57,8 +57,8 @@ void main() { ...@@ -57,8 +57,8 @@ void main() {
testWidgets('Overscroll indicator changes side when you drag on the other side', (WidgetTester tester) async { testWidgets('Overscroll indicator changes side when you drag on the other side', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)), new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)),
], ],
), ),
...@@ -92,8 +92,8 @@ void main() { ...@@ -92,8 +92,8 @@ void main() {
testWidgets('Overscroll indicator changes side when you shift sides', (WidgetTester tester) async { testWidgets('Overscroll indicator changes side when you shift sides', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)), new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)),
], ],
), ),
...@@ -125,9 +125,9 @@ void main() { ...@@ -125,9 +125,9 @@ void main() {
group('Flipping direction of scrollable doesn\'t change overscroll behavior', () { group('Flipping direction of scrollable doesn\'t change overscroll behavior', () {
testWidgets('down', (WidgetTester tester) async { testWidgets('down', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 20.0)), new SliverToBoxAdapter(child: new SizedBox(height: 20.0)),
], ],
), ),
...@@ -142,9 +142,9 @@ void main() { ...@@ -142,9 +142,9 @@ void main() {
testWidgets('up', (WidgetTester tester) async { testWidgets('up', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
axisDirection: AxisDirection.up, axisDirection: AxisDirection.up,
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 20.0)), new SliverToBoxAdapter(child: new SizedBox(height: 20.0)),
], ],
), ),
...@@ -160,9 +160,9 @@ void main() { ...@@ -160,9 +160,9 @@ void main() {
testWidgets('Overscroll in both directions', (WidgetTester tester) async { testWidgets('Overscroll in both directions', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 20.0)), new SliverToBoxAdapter(child: new SizedBox(height: 20.0)),
], ],
), ),
...@@ -180,9 +180,9 @@ void main() { ...@@ -180,9 +180,9 @@ void main() {
testWidgets('Overscroll horizontally', (WidgetTester tester) async { testWidgets('Overscroll horizontally', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 20.0)), new SliverToBoxAdapter(child: new SizedBox(height: 20.0)),
], ],
), ),
...@@ -203,10 +203,10 @@ void main() { ...@@ -203,10 +203,10 @@ void main() {
RenderObject painter; RenderObject painter;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
scrollBehavior: new TestScrollBehavior1(), scrollBehavior: new TestScrollBehavior1(),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 20.0)), new SliverToBoxAdapter(child: new SizedBox(height: 20.0)),
], ],
), ),
...@@ -218,10 +218,10 @@ void main() { ...@@ -218,10 +218,10 @@ void main() {
await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1)); await tester.pumpUntilNoTransientCallbacks(const Duration(seconds: 1));
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
scrollBehavior: new TestScrollBehavior2(), scrollBehavior: new TestScrollBehavior2(),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 20.0)), new SliverToBoxAdapter(child: new SizedBox(height: 20.0)),
], ],
), ),
......
...@@ -75,25 +75,6 @@ class TestScrollBehavior extends ScrollBehavior2 { ...@@ -75,25 +75,6 @@ class TestScrollBehavior extends ScrollBehavior2 {
@override @override
Widget wrap(BuildContext context, Widget child, AxisDirection axisDirection) => child; Widget wrap(BuildContext context, Widget child, AxisDirection axisDirection) => child;
@override
Widget createViewport({
Key key,
AxisDirection axisDirection: AxisDirection.down,
double anchor: 0.0,
ViewportOffset offset,
Key center,
List<Widget> children: const <Widget>[],
}) {
return new Viewport2(
key: key,
axisDirection: axisDirection,
anchor: anchor,
offset: offset,
center: center,
children: children,
);
}
@override @override
ScrollPosition createScrollPosition(BuildContext context, Scrollable2State state, ScrollPosition oldPosition) { ScrollPosition createScrollPosition(BuildContext context, Scrollable2State state, ScrollPosition oldPosition) {
return new TestScrollPosition(extentMultiplier, state, ViewportScrollBehavior.defaultScrollTolerances, oldPosition); return new TestScrollPosition(extentMultiplier, state, ViewportScrollBehavior.defaultScrollTolerances, oldPosition);
...@@ -107,22 +88,21 @@ class TestScrollBehavior extends ScrollBehavior2 { ...@@ -107,22 +88,21 @@ class TestScrollBehavior extends ScrollBehavior2 {
void main() { void main() {
testWidgets('Changing the scroll behavior dynamically', (WidgetTester tester) async { testWidgets('Changing the scroll behavior dynamically', (WidgetTester tester) async {
GlobalKey<Scrollable2State> key = new GlobalKey<Scrollable2State>(); await tester.pumpWidget(new ScrollableViewport2(
await tester.pumpWidget(new Scrollable2(
key: key,
scrollBehavior: new TestScrollBehavior(1.0), scrollBehavior: new TestScrollBehavior(1.0),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)), new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)),
], ],
)); ));
expect(key.currentState.position.getMetrics().extentInside, 1.0); Scrollable2State state = tester.state(find.byType(Scrollable2));
await tester.pumpWidget(new Scrollable2(
key: key, expect(state.position.getMetrics().extentInside, 1.0);
await tester.pumpWidget(new ScrollableViewport2(
scrollBehavior: new TestScrollBehavior(2.0), scrollBehavior: new TestScrollBehavior(2.0),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)), new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)),
], ],
)); ));
expect(key.currentState.position.getMetrics().extentInside, 2.0); expect(state.position.getMetrics().extentInside, 2.0);
}); });
} }
...@@ -11,8 +11,8 @@ Future<Null> pumpTest(WidgetTester tester, TargetPlatform platform) async { ...@@ -11,8 +11,8 @@ Future<Null> pumpTest(WidgetTester tester, TargetPlatform platform) async {
theme: new ThemeData( theme: new ThemeData(
platform: platform, platform: platform,
), ),
home: new Scrollable2( home: new ScrollableViewport2(
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)), new SliverToBoxAdapter(child: new SizedBox(height: 2000.0)),
], ],
), ),
......
...@@ -24,20 +24,18 @@ void verifyActualBoxPosition(WidgetTester tester, Finder finder, int index, Rect ...@@ -24,20 +24,18 @@ void verifyActualBoxPosition(WidgetTester tester, Finder finder, int index, Rect
void main() { void main() {
testWidgets('Sliver appbars - floating - scroll offset doesn\'t change', (WidgetTester tester) async { testWidgets('Sliver appbars - floating - scroll offset doesn\'t change', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
const double bigHeight = 1000.0; const double bigHeight = 1000.0;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(height: bigHeight), new BigSliver(height: bigHeight),
new SliverAppBar(delegate: new TestDelegate(), floating: true), new SliverAppBar(delegate: new TestDelegate(), floating: true),
new BigSliver(height: bigHeight), new BigSliver(height: bigHeight),
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
final double max = bigHeight * 2.0 + new TestDelegate().maxExtent - 600.0; // 600 is the height of the test viewport final double max = bigHeight * 2.0 + new TestDelegate().maxExtent - 600.0; // 600 is the height of the test viewport
assert(max < 10000.0); assert(max < 10000.0);
expect(max, 1600.0); expect(max, 1600.0);
...@@ -52,22 +50,20 @@ void main() { ...@@ -52,22 +50,20 @@ void main() {
}); });
testWidgets('Sliver appbars - floating - normal behavior works', (WidgetTester tester) async { testWidgets('Sliver appbars - floating - normal behavior works', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
final TestDelegate delegate = new TestDelegate(); final TestDelegate delegate = new TestDelegate();
const double bigHeight = 1000.0; const double bigHeight = 1000.0;
GlobalKey key1, key2, key3; GlobalKey key1, key2, key3;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: delegate, floating: true), new SliverAppBar(key: key2 = new GlobalKey(), delegate: delegate, floating: true),
new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), new BigSliver(key: key3 = new GlobalKey(), height: bigHeight),
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
verifyPaintPosition(key1, new Offset(0.0, 0.0), true); verifyPaintPosition(key1, new Offset(0.0, 0.0), true);
verifyPaintPosition(key2, new Offset(0.0, 600.0), false); verifyPaintPosition(key2, new Offset(0.0, 600.0), false);
...@@ -124,22 +120,20 @@ void main() { ...@@ -124,22 +120,20 @@ void main() {
}); });
testWidgets('Sliver appbars - floating - no floating behavior when animating', (WidgetTester tester) async { testWidgets('Sliver appbars - floating - no floating behavior when animating', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
final TestDelegate delegate = new TestDelegate(); final TestDelegate delegate = new TestDelegate();
const double bigHeight = 1000.0; const double bigHeight = 1000.0;
GlobalKey key1, key2, key3; GlobalKey key1, key2, key3;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: delegate, floating: true), new SliverAppBar(key: key2 = new GlobalKey(), delegate: delegate, floating: true),
new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), new BigSliver(key: key3 = new GlobalKey(), height: bigHeight),
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
verifyPaintPosition(key1, new Offset(0.0, 0.0), true); verifyPaintPosition(key1, new Offset(0.0, 0.0), true);
verifyPaintPosition(key2, new Offset(0.0, 600.0), false); verifyPaintPosition(key2, new Offset(0.0, 600.0), false);
...@@ -159,22 +153,20 @@ void main() { ...@@ -159,22 +153,20 @@ void main() {
}); });
testWidgets('Sliver appbars - floating - floating behavior when dragging down', (WidgetTester tester) async { testWidgets('Sliver appbars - floating - floating behavior when dragging down', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
final TestDelegate delegate = new TestDelegate(); final TestDelegate delegate = new TestDelegate();
const double bigHeight = 1000.0; const double bigHeight = 1000.0;
GlobalKey key1, key2, key3; GlobalKey key1, key2, key3;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: delegate, floating: true), new SliverAppBar(key: key2 = new GlobalKey(), delegate: delegate, floating: true),
new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), new BigSliver(key: key3 = new GlobalKey(), height: bigHeight),
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
verifyPaintPosition(key1, new Offset(0.0, 0.0), true); verifyPaintPosition(key1, new Offset(0.0, 0.0), true);
verifyPaintPosition(key2, new Offset(0.0, 600.0), false); verifyPaintPosition(key2, new Offset(0.0, 600.0), false);
......
...@@ -24,14 +24,12 @@ void verifyActualBoxPosition(WidgetTester tester, Finder finder, int index, Rect ...@@ -24,14 +24,12 @@ void verifyActualBoxPosition(WidgetTester tester, Finder finder, int index, Rect
void main() { void main() {
testWidgets('Sliver appbars - pinned', (WidgetTester tester) async { testWidgets('Sliver appbars - pinned', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
const double bigHeight = 550.0; const double bigHeight = 550.0;
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
...@@ -40,7 +38,7 @@ void main() { ...@@ -40,7 +38,7 @@ void main() {
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
final double max = bigHeight * 3.0 + new TestDelegate().maxExtent * 2.0 - 600.0; // 600 is the height of the test viewport final double max = bigHeight * 3.0 + new TestDelegate().maxExtent * 2.0 - 600.0; // 600 is the height of the test viewport
assert(max < 10000.0); assert(max < 10000.0);
expect(max, 1450.0); expect(max, 1450.0);
...@@ -60,14 +58,12 @@ void main() { ...@@ -60,14 +58,12 @@ void main() {
}); });
testWidgets('Sliver appbars - pinned with slow scroll', (WidgetTester tester) async { testWidgets('Sliver appbars - pinned with slow scroll', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
const double bigHeight = 550.0; const double bigHeight = 550.0;
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
...@@ -76,7 +72,7 @@ void main() { ...@@ -76,7 +72,7 @@ void main() {
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
verifyPaintPosition(key1, new Offset(0.0, 0.0), true); verifyPaintPosition(key1, new Offset(0.0, 0.0), true);
verifyPaintPosition(key2, new Offset(0.0, 550.0), true); verifyPaintPosition(key2, new Offset(0.0, 550.0), true);
verifyPaintPosition(key3, new Offset(0.0, 600.0), false); verifyPaintPosition(key3, new Offset(0.0, 600.0), false);
...@@ -152,14 +148,12 @@ void main() { ...@@ -152,14 +148,12 @@ void main() {
}); });
testWidgets('Sliver appbars - pinned with less overlap', (WidgetTester tester) async { testWidgets('Sliver appbars - pinned with less overlap', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
const double bigHeight = 650.0; const double bigHeight = 650.0;
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
...@@ -168,7 +162,7 @@ void main() { ...@@ -168,7 +162,7 @@ void main() {
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
final double max = bigHeight * 3.0 + new TestDelegate().maxExtent * 2.0 - 600.0; // 600 is the height of the test viewport final double max = bigHeight * 3.0 + new TestDelegate().maxExtent * 2.0 - 600.0; // 600 is the height of the test viewport
assert(max < 10000.0); assert(max < 10000.0);
expect(max, 1750.0); expect(max, 1750.0);
......
...@@ -16,13 +16,11 @@ void verifyPaintPosition(GlobalKey key, Offset ideal) { ...@@ -16,13 +16,11 @@ void verifyPaintPosition(GlobalKey key, Offset ideal) {
void main() { void main() {
testWidgets('Sliver appbars - scrolling', (WidgetTester tester) async { testWidgets('Sliver appbars - scrolling', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey()), new BigSliver(key: key1 = new GlobalKey()),
new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate()), new SliverAppBar(key: key2 = new GlobalKey(), delegate: new TestDelegate()),
new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate()), new SliverAppBar(key: key3 = new GlobalKey(), delegate: new TestDelegate()),
...@@ -31,7 +29,7 @@ void main() { ...@@ -31,7 +29,7 @@ void main() {
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
final double max = RenderBigSliver.height * 3.0 + new TestDelegate().maxExtent * 2.0 - 600.0; // 600 is the height of the test viewport final double max = RenderBigSliver.height * 3.0 + new TestDelegate().maxExtent * 2.0 - 600.0; // 600 is the height of the test viewport
assert(max < 10000.0); assert(max < 10000.0);
expect(max, 1450.0); expect(max, 1450.0);
...@@ -51,14 +49,12 @@ void main() { ...@@ -51,14 +49,12 @@ void main() {
}); });
testWidgets('Sliver appbars - scrolling off screen', (WidgetTester tester) async { testWidgets('Sliver appbars - scrolling off screen', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
GlobalKey key = new GlobalKey(); GlobalKey key = new GlobalKey();
TestDelegate delegate = new TestDelegate(); TestDelegate delegate = new TestDelegate();
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(), new BigSliver(),
new SliverAppBar(key: key, delegate: delegate), new SliverAppBar(key: key, delegate: delegate),
new BigSliver(), new BigSliver(),
...@@ -66,7 +62,7 @@ void main() { ...@@ -66,7 +62,7 @@ void main() {
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
position.animate(to: RenderBigSliver.height + delegate.maxExtent - 5.0, curve: Curves.linear, duration: const Duration(minutes: 1)); position.animate(to: RenderBigSliver.height + delegate.maxExtent - 5.0, curve: Curves.linear, duration: const Duration(minutes: 1));
await tester.pumpUntilNoTransientCallbacks(const Duration(milliseconds: 1000)); await tester.pumpUntilNoTransientCallbacks(const Duration(milliseconds: 1000));
RenderBox box = tester.renderObject/*<RenderBox>*/(find.byType(Container)); RenderBox box = tester.renderObject/*<RenderBox>*/(find.byType(Container));
......
...@@ -26,7 +26,7 @@ Future<Null> test(WidgetTester tester, double offset, List<int> keys) { ...@@ -26,7 +26,7 @@ Future<Null> test(WidgetTester tester, double offset, List<int> keys) {
globalGeneration += 1; globalGeneration += 1;
return tester.pumpWidget(new Viewport2( return tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(keys.map((int key) { delegate: new SliverBlockChildListDelegate(keys.map((int key) {
return new SizedBox(key: new GlobalObjectKey(key), height: 100.0, child: new GenerationText(key)); return new SizedBox(key: new GlobalObjectKey(key), height: 100.0, child: new GenerationText(key));
......
...@@ -11,7 +11,7 @@ import '../rendering/mock_canvas.dart'; ...@@ -11,7 +11,7 @@ import '../rendering/mock_canvas.dart';
Future<Null> test(WidgetTester tester, double offset) { Future<Null> test(WidgetTester tester, double offset) {
return tester.pumpWidget(new Viewport2( return tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 400.0, child: new Text('a')), new SizedBox(height: 400.0, child: new Text('a')),
...@@ -76,7 +76,7 @@ void main() { ...@@ -76,7 +76,7 @@ void main() {
ViewportOffset offset = new ViewportOffset.zero(); ViewportOffset offset = new ViewportOffset.zero();
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: offset, offset: offset,
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 251.0, child: new Text('a')), new SizedBox(height: 251.0, child: new Text('a')),
...@@ -93,7 +93,7 @@ void main() { ...@@ -93,7 +93,7 @@ void main() {
], 'abc'); ], 'abc');
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: offset, offset: offset,
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(key: key1, height: 253.0, child: new Text('c')), new SizedBox(key: key1, height: 253.0, child: new Text('c')),
...@@ -110,7 +110,7 @@ void main() { ...@@ -110,7 +110,7 @@ void main() {
], 'cab'); ], 'cab');
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: offset, offset: offset,
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 251.0, child: new Text('a')), new SizedBox(height: 251.0, child: new Text('a')),
...@@ -127,7 +127,7 @@ void main() { ...@@ -127,7 +127,7 @@ void main() {
], 'acb'); ], 'acb');
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: offset, offset: offset,
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 251.0, child: new Text('a')), new SizedBox(height: 251.0, child: new Text('a')),
...@@ -142,7 +142,7 @@ void main() { ...@@ -142,7 +142,7 @@ void main() {
], 'ab'); ], 'ab');
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: offset, offset: offset,
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 251.0, child: new Text('a')), new SizedBox(height: 251.0, child: new Text('a')),
...@@ -162,7 +162,7 @@ void main() { ...@@ -162,7 +162,7 @@ void main() {
testWidgets('Viewport2 overflow clipping of SliverToBoxAdapter', (WidgetTester tester) async { testWidgets('Viewport2 overflow clipping of SliverToBoxAdapter', (WidgetTester tester) async {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter( new SliverToBoxAdapter(
child: new SizedBox(height: 400.0, child: new Text('a')), child: new SizedBox(height: 400.0, child: new Text('a')),
), ),
...@@ -173,7 +173,7 @@ void main() { ...@@ -173,7 +173,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter( new SliverToBoxAdapter(
child: new SizedBox(height: 400.0, child: new Text('a')), child: new SizedBox(height: 400.0, child: new Text('a')),
), ),
...@@ -184,7 +184,7 @@ void main() { ...@@ -184,7 +184,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter( new SliverToBoxAdapter(
child: new SizedBox(height: 4000.0, child: new Text('a')), child: new SizedBox(height: 4000.0, child: new Text('a')),
), ),
...@@ -195,7 +195,7 @@ void main() { ...@@ -195,7 +195,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter( new SliverToBoxAdapter(
child: new SizedBox(height: 4000.0, child: new Text('a')), child: new SizedBox(height: 4000.0, child: new Text('a')),
), ),
...@@ -208,7 +208,7 @@ void main() { ...@@ -208,7 +208,7 @@ void main() {
testWidgets('Viewport2 overflow clipping of SliverBlock', (WidgetTester tester) async { testWidgets('Viewport2 overflow clipping of SliverBlock', (WidgetTester tester) async {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 400.0, child: new Text('a')), new SizedBox(height: 400.0, child: new Text('a')),
...@@ -221,7 +221,7 @@ void main() { ...@@ -221,7 +221,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 400.0, child: new Text('a')), new SizedBox(height: 400.0, child: new Text('a')),
...@@ -234,7 +234,7 @@ void main() { ...@@ -234,7 +234,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 4000.0, child: new Text('a')), new SizedBox(height: 4000.0, child: new Text('a')),
...@@ -247,7 +247,7 @@ void main() { ...@@ -247,7 +247,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <Widget>[ slivers: <Widget>[
new SliverBlock( new SliverBlock(
delegate: new SliverBlockChildListDelegate(<Widget>[ delegate: new SliverBlockChildListDelegate(<Widget>[
new SizedBox(height: 4000.0, child: new Text('a')), new SizedBox(height: 4000.0, child: new Text('a')),
......
...@@ -10,7 +10,7 @@ Future<Null> test(WidgetTester tester, double offset, EdgeInsets padding, AxisDi ...@@ -10,7 +10,7 @@ Future<Null> test(WidgetTester tester, double offset, EdgeInsets padding, AxisDi
return tester.pumpWidget(new Viewport2( return tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
axisDirection: axisDirection, axisDirection: axisDirection,
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(width: 400.0, height: 400.0, child: new Text('before'))), new SliverToBoxAdapter(child: new SizedBox(width: 400.0, height: 400.0, child: new Text('before'))),
new SliverPadding( new SliverPadding(
padding: padding, padding: padding,
...@@ -163,7 +163,7 @@ void main() { ...@@ -163,7 +163,7 @@ void main() {
testWidgets('Viewport2+SliverPadding no child', (WidgetTester tester) async { testWidgets('Viewport2+SliverPadding no child', (WidgetTester tester) async {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.all(100.0)), new SliverPadding(padding: new EdgeInsets.all(100.0)),
new SliverToBoxAdapter(child: new SizedBox(width: 400.0, height: 400.0, child: new Text('x'))), new SliverToBoxAdapter(child: new SizedBox(width: 400.0, height: 400.0, child: new Text('x'))),
], ],
...@@ -176,7 +176,7 @@ void main() { ...@@ -176,7 +176,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(90.0, 1.0, 110.0, 2.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(90.0, 1.0, 110.0, 2.0)),
new SliverToBoxAdapter(child: new SizedBox(width: 201.0, child: new Text('x'))), new SliverToBoxAdapter(child: new SizedBox(width: 201.0, child: new Text('x'))),
], ],
...@@ -186,7 +186,7 @@ void main() { ...@@ -186,7 +186,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(110.0, 1.0, 80.0, 2.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(110.0, 1.0, 80.0, 2.0)),
new SliverToBoxAdapter(child: new SizedBox(width: 201.0, child: new Text('x'))), new SliverToBoxAdapter(child: new SizedBox(width: 201.0, child: new Text('x'))),
], ],
...@@ -199,7 +199,7 @@ void main() { ...@@ -199,7 +199,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.up, axisDirection: AxisDirection.up,
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)),
], ],
)); ));
...@@ -207,7 +207,7 @@ void main() { ...@@ -207,7 +207,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)),
], ],
)); ));
...@@ -215,7 +215,7 @@ void main() { ...@@ -215,7 +215,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)),
], ],
)); ));
...@@ -223,7 +223,7 @@ void main() { ...@@ -223,7 +223,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
offset: new ViewportOffset.fixed(0.0), offset: new ViewportOffset.fixed(0.0),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)),
], ],
)); ));
...@@ -231,7 +231,7 @@ void main() { ...@@ -231,7 +231,7 @@ void main() {
await tester.pumpWidget(new Viewport2( await tester.pumpWidget(new Viewport2(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
offset: new ViewportOffset.fixed(99999.9), offset: new ViewportOffset.fixed(99999.9),
children: <Widget>[ slivers: <Widget>[
new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), new SliverPadding(padding: new EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)),
], ],
)); ));
......
...@@ -18,13 +18,11 @@ void verifyPaintPosition(GlobalKey key, Offset ideal) { ...@@ -18,13 +18,11 @@ void verifyPaintPosition(GlobalKey key, Offset ideal) {
void main() { void main() {
testWidgets('Sliver protocol', (WidgetTester tester) async { testWidgets('Sliver protocol', (WidgetTester tester) async {
final GlobalKey<Scrollable2State> scrollableKey = new GlobalKey<Scrollable2State>();
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new Scrollable2( new ScrollableViewport2(
key: scrollableKey,
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
children: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey()), new BigSliver(key: key1 = new GlobalKey()),
new OverlappingSliver(key: key2 = new GlobalKey()), new OverlappingSliver(key: key2 = new GlobalKey()),
new OverlappingSliver(key: key3 = new GlobalKey()), new OverlappingSliver(key: key3 = new GlobalKey()),
...@@ -33,7 +31,7 @@ void main() { ...@@ -33,7 +31,7 @@ void main() {
], ],
), ),
); );
AbsoluteScrollPosition position = scrollableKey.currentState.position; AbsoluteScrollPosition position = tester.state<Scrollable2State>(find.byType(Scrollable2)).position;
final double max = RenderBigSliver.height * 3.0 + (RenderOverlappingSliver.totalHeight) * 2.0 - 600.0; // 600 is the height of the test viewport final double max = RenderBigSliver.height * 3.0 + (RenderOverlappingSliver.totalHeight) * 2.0 - 600.0; // 600 is the height of the test viewport
assert(max < 10000.0); assert(max < 10000.0);
expect(max, 1450.0); expect(max, 1450.0);
......
...@@ -10,7 +10,7 @@ Future<Null> test(WidgetTester tester, double offset, { double anchor: 0.0 }) { ...@@ -10,7 +10,7 @@ Future<Null> test(WidgetTester tester, double offset, { double anchor: 0.0 }) {
return tester.pumpWidget(new Viewport2( return tester.pumpWidget(new Viewport2(
anchor: anchor / 600.0, anchor: anchor / 600.0,
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
children: <Widget>[ slivers: <Widget>[
new SliverToBoxAdapter(child: new SizedBox(height: 400.0)), new SliverToBoxAdapter(child: new SizedBox(height: 400.0)),
new SliverToBoxAdapter(child: new SizedBox(height: 400.0)), new SliverToBoxAdapter(child: new SizedBox(height: 400.0)),
new SliverToBoxAdapter(child: new SizedBox(height: 400.0)), new SliverToBoxAdapter(child: new SizedBox(height: 400.0)),
......
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