Commit 8eb6ad27 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Add RTL support to GridView (#11921)

Fixes #11855
parent c896fe2f
...@@ -205,6 +205,7 @@ class _DayPickerGridDelegate extends SliverGridDelegate { ...@@ -205,6 +205,7 @@ class _DayPickerGridDelegate extends SliverGridDelegate {
crossAxisStride: tileWidth, crossAxisStride: tileWidth,
childMainAxisExtent: tileHeight, childMainAxisExtent: tileHeight,
childCrossAxisExtent: tileWidth, childCrossAxisExtent: tileWidth,
reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
); );
} }
......
...@@ -80,7 +80,7 @@ class ExpansionPanelList extends StatelessWidget { ...@@ -80,7 +80,7 @@ class ExpansionPanelList extends StatelessWidget {
assert(animationDuration != null), assert(animationDuration != null),
super(key: key); super(key: key);
/// The children of the expansion panel list. They are layed in a similar /// The children of the expansion panel list. They are laid out in a similar
/// fashion to [ListBody]. /// fashion to [ListBody].
final List<ExpansionPanel> children; final List<ExpansionPanel> children;
......
...@@ -49,15 +49,15 @@ class GridTile extends StatelessWidget { ...@@ -49,15 +49,15 @@ class GridTile extends StatelessWidget {
final List<Widget> children = <Widget>[ final List<Widget> children = <Widget>[
new Positioned.fill( new Positioned.fill(
child: child child: child,
) ),
]; ];
if (header != null) { if (header != null) {
children.add(new Positioned( children.add(new Positioned(
top: 0.0, top: 0.0,
left: 0.0, left: 0.0,
right: 0.0, right: 0.0,
child: header child: header,
)); ));
} }
if (footer != null) { if (footer != null) {
...@@ -65,7 +65,7 @@ class GridTile extends StatelessWidget { ...@@ -65,7 +65,7 @@ class GridTile extends StatelessWidget {
left: 0.0, left: 0.0,
bottom: 0.0, bottom: 0.0,
right: 0.0, right: 0.0,
child: footer child: footer,
)); ));
} }
return new Stack(children: children); return new Stack(children: children);
......
...@@ -89,6 +89,21 @@ Axis axisDirectionToAxis(AxisDirection axisDirection) { ...@@ -89,6 +89,21 @@ Axis axisDirectionToAxis(AxisDirection axisDirection) {
return null; return null;
} }
/// Returns the [AxisDirection] in which reading occurs in the given [TextDirection].
///
/// Specifically, returns [AxisDirection.left] for [TextDirection.rtl] and
/// [AxisDirection.right] for [TextDirection.ltr].
AxisDirection textDirectionToAxisDirection(TextDirection textDirection) {
assert(textDirection != null);
switch (textDirection) {
case TextDirection.rtl:
return AxisDirection.left;
case TextDirection.ltr:
return AxisDirection.right;
}
return null;
}
/// Returns the opposite of the given [AxisDirection]. /// Returns the opposite of the given [AxisDirection].
/// ///
/// Specifically, returns [AxisDirection.up] for [AxisDirection.down] (and /// Specifically, returns [AxisDirection.up] for [AxisDirection.down] (and
...@@ -192,6 +207,7 @@ class SliverConstraints extends Constraints { ...@@ -192,6 +207,7 @@ class SliverConstraints extends Constraints {
@required this.overlap, @required this.overlap,
@required this.remainingPaintExtent, @required this.remainingPaintExtent,
@required this.crossAxisExtent, @required this.crossAxisExtent,
@required this.crossAxisDirection,
@required this.viewportMainAxisExtent, @required this.viewportMainAxisExtent,
}) : assert(axisDirection != null), }) : assert(axisDirection != null),
assert(growthDirection != null), assert(growthDirection != null),
...@@ -200,6 +216,7 @@ class SliverConstraints extends Constraints { ...@@ -200,6 +216,7 @@ class SliverConstraints extends Constraints {
assert(overlap != null), assert(overlap != null),
assert(remainingPaintExtent != null), assert(remainingPaintExtent != null),
assert(crossAxisExtent != null), assert(crossAxisExtent != null),
assert(crossAxisDirection != null),
assert(viewportMainAxisExtent != null); assert(viewportMainAxisExtent != null);
/// Creates a copy of this object but with the given fields replaced with the /// Creates a copy of this object but with the given fields replaced with the
...@@ -212,6 +229,7 @@ class SliverConstraints extends Constraints { ...@@ -212,6 +229,7 @@ class SliverConstraints extends Constraints {
double overlap, double overlap,
double remainingPaintExtent, double remainingPaintExtent,
double crossAxisExtent, double crossAxisExtent,
AxisDirection crossAxisDirection,
double viewportMainAxisExtent, double viewportMainAxisExtent,
}) { }) {
return new SliverConstraints( return new SliverConstraints(
...@@ -222,6 +240,7 @@ class SliverConstraints extends Constraints { ...@@ -222,6 +240,7 @@ class SliverConstraints extends Constraints {
overlap: overlap ?? this.overlap, overlap: overlap ?? this.overlap,
remainingPaintExtent: remainingPaintExtent ?? this.remainingPaintExtent, remainingPaintExtent: remainingPaintExtent ?? this.remainingPaintExtent,
crossAxisExtent: crossAxisExtent ?? this.crossAxisExtent, crossAxisExtent: crossAxisExtent ?? this.crossAxisExtent,
crossAxisDirection: crossAxisDirection ?? this.crossAxisDirection,
viewportMainAxisExtent: viewportMainAxisExtent ?? this.viewportMainAxisExtent, viewportMainAxisExtent: viewportMainAxisExtent ?? this.viewportMainAxisExtent,
); );
} }
...@@ -315,9 +334,15 @@ class SliverConstraints extends Constraints { ...@@ -315,9 +334,15 @@ class SliverConstraints extends Constraints {
/// The number of pixels in the cross-axis. /// The number of pixels in the cross-axis.
/// ///
/// For a vertical list, this is the width of the sliver.. /// For a vertical list, this is the width of the sliver.
final double crossAxisExtent; final double crossAxisExtent;
/// The direction in which children should be placed in the cross axis.
///
/// Typically used in vertical lists to describe whether the ambient
/// [TextDirection] is [TextDirection.rtl] or [TextDirection.ltr].
final AxisDirection crossAxisDirection;
/// The number of pixels the viewport can display in the main axis. /// The number of pixels the viewport can display in the main axis.
/// ///
/// For a vertical list, this is the height of the viewport. /// For a vertical list, this is the height of the viewport.
...@@ -361,6 +386,7 @@ class SliverConstraints extends Constraints { ...@@ -361,6 +386,7 @@ class SliverConstraints extends Constraints {
bool get isNormalized { bool get isNormalized {
return scrollOffset >= 0.0 return scrollOffset >= 0.0
&& crossAxisExtent >= 0.0 && crossAxisExtent >= 0.0
&& axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection)
&& viewportMainAxisExtent >= 0.0 && viewportMainAxisExtent >= 0.0
&& remainingPaintExtent >= 0.0; && remainingPaintExtent >= 0.0;
} }
...@@ -421,6 +447,8 @@ class SliverConstraints extends Constraints { ...@@ -421,6 +447,8 @@ class SliverConstraints extends Constraints {
verify(viewportMainAxisExtent != null, 'The "viewportMainAxisExtent" is null.'); verify(viewportMainAxisExtent != null, 'The "viewportMainAxisExtent" is null.');
verify(scrollOffset >= 0.0, 'The "scrollOffset" is negative.'); verify(scrollOffset >= 0.0, 'The "scrollOffset" is negative.');
verify(crossAxisExtent >= 0.0, 'The "crossAxisExtent" is negative.'); verify(crossAxisExtent >= 0.0, 'The "crossAxisExtent" is negative.');
verify(crossAxisDirection != null, 'The "crossAxisDirection" is null.');
verify(axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection), 'The "axisDirection" and the "crossAxisDirection" are along the same axis.');
verify(viewportMainAxisExtent >= 0.0, 'The "viewportMainAxisExtent" is negative.'); verify(viewportMainAxisExtent >= 0.0, 'The "viewportMainAxisExtent" is negative.');
verify(remainingPaintExtent >= 0.0, 'The "remainingPaintExtent" is negative.'); verify(remainingPaintExtent >= 0.0, 'The "remainingPaintExtent" is negative.');
verify(isNormalized, 'The constraints are not normalized.'); // should be redundant with earlier checks verify(isNormalized, 'The constraints are not normalized.'); // should be redundant with earlier checks
...@@ -437,18 +465,28 @@ class SliverConstraints extends Constraints { ...@@ -437,18 +465,28 @@ class SliverConstraints extends Constraints {
return false; return false;
final SliverConstraints typedOther = other; final SliverConstraints typedOther = other;
assert(typedOther.debugAssertIsValid()); assert(typedOther.debugAssertIsValid());
return axisDirection == typedOther.axisDirection && return typedOther.axisDirection == axisDirection
growthDirection == typedOther.growthDirection && && typedOther.growthDirection == growthDirection
scrollOffset == typedOther.scrollOffset && && typedOther.scrollOffset == scrollOffset
overlap == typedOther.overlap && && typedOther.overlap == overlap
remainingPaintExtent == typedOther.remainingPaintExtent && && typedOther.remainingPaintExtent == remainingPaintExtent
crossAxisExtent == typedOther.crossAxisExtent && && typedOther.crossAxisExtent == crossAxisExtent
viewportMainAxisExtent == typedOther.viewportMainAxisExtent; && typedOther.crossAxisDirection == crossAxisDirection
&& typedOther.viewportMainAxisExtent == viewportMainAxisExtent;
} }
@override @override
int get hashCode { int get hashCode {
return hashValues(axisDirection, growthDirection, scrollOffset, overlap, remainingPaintExtent, crossAxisExtent, viewportMainAxisExtent); return hashValues(
axisDirection,
growthDirection,
scrollOffset,
overlap,
remainingPaintExtent,
crossAxisExtent,
crossAxisDirection,
viewportMainAxisExtent,
);
} }
@override @override
...@@ -461,6 +499,7 @@ class SliverConstraints extends Constraints { ...@@ -461,6 +499,7 @@ class SliverConstraints extends Constraints {
'remainingPaintExtent: ${remainingPaintExtent.toStringAsFixed(1)}, ' + 'remainingPaintExtent: ${remainingPaintExtent.toStringAsFixed(1)}, ' +
(overlap != 0.0 ? 'overlap: ${overlap.toStringAsFixed(1)}, ' : '') + (overlap != 0.0 ? 'overlap: ${overlap.toStringAsFixed(1)}, ' : '') +
'crossAxisExtent: ${crossAxisExtent.toStringAsFixed(1)}, ' + 'crossAxisExtent: ${crossAxisExtent.toStringAsFixed(1)}, ' +
'crossAxisDirection: $crossAxisDirection, ' +
'viewportMainAxisExtent: ${viewportMainAxisExtent.toStringAsFixed(1)}' + 'viewportMainAxisExtent: ${viewportMainAxisExtent.toStringAsFixed(1)}' +
')'; ')';
} }
......
...@@ -151,11 +151,13 @@ class SliverGridRegularTileLayout extends SliverGridLayout { ...@@ -151,11 +151,13 @@ class SliverGridRegularTileLayout extends SliverGridLayout {
@required this.crossAxisStride, @required this.crossAxisStride,
@required this.childMainAxisExtent, @required this.childMainAxisExtent,
@required this.childCrossAxisExtent, @required this.childCrossAxisExtent,
@required this.reverseCrossAxis,
}) : assert(crossAxisCount != null && crossAxisCount > 0), }) : assert(crossAxisCount != null && crossAxisCount > 0),
assert(mainAxisStride != null && mainAxisStride >= 0), assert(mainAxisStride != null && mainAxisStride >= 0),
assert(crossAxisStride != null && crossAxisStride >= 0), assert(crossAxisStride != null && crossAxisStride >= 0),
assert(childMainAxisExtent != null && childMainAxisExtent >= 0), assert(childMainAxisExtent != null && childMainAxisExtent >= 0),
assert(childCrossAxisExtent != null && childCrossAxisExtent >= 0); assert(childCrossAxisExtent != null && childCrossAxisExtent >= 0),
assert(reverseCrossAxis != null);
/// The number of children in the cross axis. /// The number of children in the cross axis.
final int crossAxisCount; final int crossAxisCount;
...@@ -176,6 +178,17 @@ class SliverGridRegularTileLayout extends SliverGridLayout { ...@@ -176,6 +178,17 @@ class SliverGridRegularTileLayout extends SliverGridLayout {
/// edge of the same tile in the cross axis. /// edge of the same tile in the cross axis.
final double childCrossAxisExtent; final double childCrossAxisExtent;
/// Whether the children should be placed in the opposite order of increasing
/// coordinates in the cross axis.
///
/// For example, if the cross axis is horizontal, the children are placed from
/// left to right when [reverseCrossAxis] is false and from right to left when
/// [reverseCrossAxis] is true.
///
/// Typically set to the return value of [axisDirectionIsReversed] applied to
/// the [SliverConstraints.crossAxisDirection].
final bool reverseCrossAxis;
@override @override
int getMinChildIndexForScrollOffset(double scrollOffset) { int getMinChildIndexForScrollOffset(double scrollOffset) {
return mainAxisStride > 0.0 ? crossAxisCount * (scrollOffset ~/ mainAxisStride) : 0; return mainAxisStride > 0.0 ? crossAxisCount * (scrollOffset ~/ mainAxisStride) : 0;
...@@ -190,11 +203,18 @@ class SliverGridRegularTileLayout extends SliverGridLayout { ...@@ -190,11 +203,18 @@ class SliverGridRegularTileLayout extends SliverGridLayout {
return 0; return 0;
} }
double _getOffsetFromStartInCrossAxis(double crossAxisStart) {
if (reverseCrossAxis)
return crossAxisCount * crossAxisStride - crossAxisStart - childCrossAxisExtent;
return crossAxisStart;
}
@override @override
SliverGridGeometry getGeometryForChildIndex(int index) { SliverGridGeometry getGeometryForChildIndex(int index) {
final double crossAxisStart = (index % crossAxisCount) * crossAxisStride;
return new SliverGridGeometry( return new SliverGridGeometry(
scrollOffset: (index ~/ crossAxisCount) * mainAxisStride, scrollOffset: (index ~/ crossAxisCount) * mainAxisStride,
crossAxisOffset: (index % crossAxisCount) * crossAxisStride, crossAxisOffset: _getOffsetFromStartInCrossAxis(crossAxisStart),
mainAxisExtent: childMainAxisExtent, mainAxisExtent: childMainAxisExtent,
crossAxisExtent: childCrossAxisExtent, crossAxisExtent: childCrossAxisExtent,
); );
...@@ -313,6 +333,7 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate { ...@@ -313,6 +333,7 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate {
crossAxisStride: childCrossAxisExtent + crossAxisSpacing, crossAxisStride: childCrossAxisExtent + crossAxisSpacing,
childMainAxisExtent: childMainAxisExtent, childMainAxisExtent: childMainAxisExtent,
childCrossAxisExtent: childCrossAxisExtent, childCrossAxisExtent: childCrossAxisExtent,
reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
); );
} }
...@@ -410,6 +431,7 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate { ...@@ -410,6 +431,7 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate {
crossAxisStride: childCrossAxisExtent + crossAxisSpacing, crossAxisStride: childCrossAxisExtent + crossAxisSpacing,
childMainAxisExtent: childMainAxisExtent, childMainAxisExtent: childMainAxisExtent,
childCrossAxisExtent: childCrossAxisExtent, childCrossAxisExtent: childCrossAxisExtent,
reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
); );
} }
......
...@@ -81,10 +81,14 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -81,10 +81,14 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
/// Initializes fields for subclasses. /// Initializes fields for subclasses.
RenderViewportBase({ RenderViewportBase({
AxisDirection axisDirection: AxisDirection.down, AxisDirection axisDirection: AxisDirection.down,
@required AxisDirection crossAxisDirection,
@required ViewportOffset offset, @required ViewportOffset offset,
}) : assert(axisDirection != null), }) : assert(axisDirection != null),
assert(crossAxisDirection != null),
assert(offset != null), assert(offset != null),
assert(axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection)),
_axisDirection = axisDirection, _axisDirection = axisDirection,
_crossAxisDirection = crossAxisDirection,
_offset = offset; _offset = offset;
@override @override
...@@ -118,6 +122,22 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -118,6 +122,22 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
markNeedsLayout(); markNeedsLayout();
} }
/// The direction in which child should be laid out in the cross axis.
///
/// For example, if the [axisDirection] is [AxisDirection.down], this property
/// is typically [AxisDirection.left] if the ambient [TextDirection] is
/// [TextDirection.rtl] and [AxisDirection.right] if the ambient
/// [TextDirection] is [TextDirection.ltr].
AxisDirection get crossAxisDirection => _crossAxisDirection;
AxisDirection _crossAxisDirection;
set crossAxisDirection(AxisDirection value) {
assert(value != null);
if (value == _crossAxisDirection)
return;
_crossAxisDirection = value;
markNeedsLayout();
}
/// The axis along which the viewport scrolls. /// The axis along which the viewport scrolls.
/// ///
/// For example, if the [axisDirection] is [AxisDirection.down], then the /// For example, if the [axisDirection] is [AxisDirection.down], then the
...@@ -271,6 +291,7 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -271,6 +291,7 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
overlap: maxPaintOffset - layoutOffset, overlap: maxPaintOffset - layoutOffset,
remainingPaintExtent: math.max(0.0, remainingPaintExtent - layoutOffset + initialLayoutOffset), remainingPaintExtent: math.max(0.0, remainingPaintExtent - layoutOffset + initialLayoutOffset),
crossAxisExtent: crossAxisExtent, crossAxisExtent: crossAxisExtent,
crossAxisDirection: crossAxisDirection,
viewportMainAxisExtent: mainAxisExtent, viewportMainAxisExtent: mainAxisExtent,
), parentUsesSize: true); ), parentUsesSize: true);
...@@ -507,6 +528,7 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -507,6 +528,7 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
void debugFillProperties(DiagnosticPropertiesBuilder description) { void debugFillProperties(DiagnosticPropertiesBuilder description) {
super.debugFillProperties(description); super.debugFillProperties(description);
description.add(new EnumProperty<AxisDirection>('axisDirection', axisDirection)); description.add(new EnumProperty<AxisDirection>('axisDirection', axisDirection));
description.add(new EnumProperty<AxisDirection>('crossAxisDirection', crossAxisDirection));
description.add(new DiagnosticsProperty<ViewportOffset>('offset', offset)); description.add(new DiagnosticsProperty<ViewportOffset>('offset', offset));
} }
...@@ -687,6 +709,7 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat ...@@ -687,6 +709,7 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat
/// [new ViewportOffset.zero] or [new ViewportOffset.fixed]. /// [new ViewportOffset.zero] or [new ViewportOffset.fixed].
RenderViewport({ RenderViewport({
AxisDirection axisDirection: AxisDirection.down, AxisDirection axisDirection: AxisDirection.down,
@required AxisDirection crossAxisDirection,
@required ViewportOffset offset, @required ViewportOffset offset,
double anchor: 0.0, double anchor: 0.0,
List<RenderSliver> children, List<RenderSliver> children,
...@@ -695,7 +718,7 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat ...@@ -695,7 +718,7 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat
assert(anchor >= 0.0 && anchor <= 1.0), assert(anchor >= 0.0 && anchor <= 1.0),
_anchor = anchor, _anchor = anchor,
_center = center, _center = center,
super(axisDirection: axisDirection, offset: offset) { super(axisDirection: axisDirection, crossAxisDirection: crossAxisDirection, offset: offset) {
addAll(children); addAll(children);
if (center == null && firstChild != null) if (center == null && firstChild != null)
_center = firstChild; _center = firstChild;
...@@ -1120,9 +1143,10 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta ...@@ -1120,9 +1143,10 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta
/// [new ViewportOffset.zero] or [new ViewportOffset.fixed]. /// [new ViewportOffset.zero] or [new ViewportOffset.fixed].
RenderShrinkWrappingViewport({ RenderShrinkWrappingViewport({
AxisDirection axisDirection: AxisDirection.down, AxisDirection axisDirection: AxisDirection.down,
@required AxisDirection crossAxisDirection,
@required ViewportOffset offset, @required ViewportOffset offset,
List<RenderSliver> children, List<RenderSliver> children,
}) : super(axisDirection: axisDirection, offset: offset) { }) : super(axisDirection: axisDirection, crossAxisDirection: crossAxisDirection, offset: offset) {
addAll(children); addAll(children);
} }
......
...@@ -453,13 +453,8 @@ class _PageViewState extends State<PageView> { ...@@ -453,13 +453,8 @@ class _PageViewState extends State<PageView> {
case Axis.horizontal: case Axis.horizontal:
final TextDirection textDirection = Directionality.of(context); final TextDirection textDirection = Directionality.of(context);
assert(textDirection != null); assert(textDirection != null);
switch (textDirection) { final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
case TextDirection.rtl: return widget.reverse ? flipAxisDirection(axisDirection) : axisDirection;
return widget.reverse ? AxisDirection.right : AxisDirection.left;
case TextDirection.ltr:
return widget.reverse ? AxisDirection.left : AxisDirection.right;
}
return null;
case Axis.vertical: case Axis.vertical:
return widget.reverse ? AxisDirection.up : AxisDirection.down; return widget.reverse ? AxisDirection.up : AxisDirection.down;
} }
......
...@@ -182,13 +182,8 @@ abstract class ScrollView extends StatelessWidget { ...@@ -182,13 +182,8 @@ abstract class ScrollView extends StatelessWidget {
case Axis.horizontal: case Axis.horizontal:
final TextDirection textDirection = Directionality.of(context); final TextDirection textDirection = Directionality.of(context);
assert(textDirection != null); assert(textDirection != null);
switch (textDirection) { final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
case TextDirection.rtl: return reverse ? flipAxisDirection(axisDirection) : axisDirection;
return reverse ? AxisDirection.right : AxisDirection.left;
case TextDirection.ltr:
return reverse ? AxisDirection.left : AxisDirection.right;
}
return null;
case Axis.vertical: case Axis.vertical:
return reverse ? AxisDirection.up : AxisDirection.down; return reverse ? AxisDirection.up : AxisDirection.down;
} }
......
...@@ -119,13 +119,8 @@ class SingleChildScrollView extends StatelessWidget { ...@@ -119,13 +119,8 @@ class SingleChildScrollView extends StatelessWidget {
case Axis.horizontal: case Axis.horizontal:
final TextDirection textDirection = Directionality.of(context); final TextDirection textDirection = Directionality.of(context);
assert(textDirection != null); assert(textDirection != null);
switch (textDirection) { final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
case TextDirection.rtl: return reverse ? flipAxisDirection(axisDirection) : axisDirection;
return reverse ? AxisDirection.right : AxisDirection.left;
case TextDirection.ltr:
return reverse ? AxisDirection.left : AxisDirection.right;
}
return null;
case Axis.vertical: case Axis.vertical:
return reverse ? AxisDirection.up : AxisDirection.down; return reverse ? AxisDirection.up : AxisDirection.down;
} }
......
...@@ -5,12 +5,28 @@ ...@@ -5,12 +5,28 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'basic.dart';
import 'framework.dart'; import 'framework.dart';
export 'package:flutter/rendering.dart' show export 'package:flutter/rendering.dart' show
AxisDirection, AxisDirection,
GrowthDirection; GrowthDirection;
AxisDirection _getDefaultCrossAxisDirection(BuildContext context, AxisDirection axisDirection) {
assert(axisDirection != null);
switch (axisDirection) {
case AxisDirection.up:
return textDirectionToAxisDirection(Directionality.of(context));
case AxisDirection.right:
return AxisDirection.down;
case AxisDirection.down:
return textDirectionToAxisDirection(Directionality.of(context));
case AxisDirection.left:
return AxisDirection.down;
}
return null;
}
/// A widget that is bigger on the inside. /// A widget that is bigger on the inside.
/// ///
/// [Viewport] is the visual workhorse of the scrolling machinery. It displays a /// [Viewport] is the visual workhorse of the scrolling machinery. It displays a
...@@ -52,6 +68,7 @@ class Viewport extends MultiChildRenderObjectWidget { ...@@ -52,6 +68,7 @@ class Viewport extends MultiChildRenderObjectWidget {
Viewport({ Viewport({
Key key, Key key,
this.axisDirection: AxisDirection.down, this.axisDirection: AxisDirection.down,
this.crossAxisDirection,
this.anchor: 0.0, this.anchor: 0.0,
@required this.offset, @required this.offset,
this.center, this.center,
...@@ -68,6 +85,17 @@ class Viewport extends MultiChildRenderObjectWidget { ...@@ -68,6 +85,17 @@ class Viewport extends MultiChildRenderObjectWidget {
/// bottom of the viewport. /// bottom of the viewport.
final AxisDirection axisDirection; final AxisDirection axisDirection;
/// The direction in which child should be laid out in the cross axis.
///
/// If the [axisDirection] is [AxisDirection.down] or [AxisDirection.up], this
/// property defaults to [AxisDirection.left] if the ambient [Directionality]
/// is [TextDirection.rtl] and [AxisDirection.right] if the ambient
/// [Directionality] is [TextDirection.ltr].
///
/// If the [axisDirection] is [AxisDirection.left] or [AxisDirection.right],
/// this property defaults to [AxisDirection.down].
final AxisDirection crossAxisDirection;
/// The relative position of the zero scroll offset. /// The relative position of the zero scroll offset.
/// ///
/// For example, if [anchor] is 0.5 and the [axisDirection] is /// For example, if [anchor] is 0.5 and the [axisDirection] is
...@@ -100,6 +128,7 @@ class Viewport extends MultiChildRenderObjectWidget { ...@@ -100,6 +128,7 @@ class Viewport extends MultiChildRenderObjectWidget {
RenderViewport createRenderObject(BuildContext context) { RenderViewport createRenderObject(BuildContext context) {
return new RenderViewport( return new RenderViewport(
axisDirection: axisDirection, axisDirection: axisDirection,
crossAxisDirection: crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection),
anchor: anchor, anchor: anchor,
offset: offset, offset: offset,
); );
...@@ -107,9 +136,11 @@ class Viewport extends MultiChildRenderObjectWidget { ...@@ -107,9 +136,11 @@ class Viewport extends MultiChildRenderObjectWidget {
@override @override
void updateRenderObject(BuildContext context, RenderViewport renderObject) { void updateRenderObject(BuildContext context, RenderViewport renderObject) {
renderObject.axisDirection = axisDirection; renderObject
renderObject.anchor = anchor; ..axisDirection = axisDirection
renderObject.offset = offset; ..crossAxisDirection = crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection)
..anchor = anchor
..offset = offset;
} }
@override @override
...@@ -119,6 +150,7 @@ class Viewport extends MultiChildRenderObjectWidget { ...@@ -119,6 +150,7 @@ class Viewport extends MultiChildRenderObjectWidget {
void debugFillProperties(DiagnosticPropertiesBuilder description) { void debugFillProperties(DiagnosticPropertiesBuilder description) {
super.debugFillProperties(description); super.debugFillProperties(description);
description.add(new EnumProperty<AxisDirection>('axisDirection', axisDirection)); description.add(new EnumProperty<AxisDirection>('axisDirection', axisDirection));
description.add(new EnumProperty<AxisDirection>('crossAxisDirection', crossAxisDirection, defaultValue: null));
description.add(new DoubleProperty('anchor', anchor)); description.add(new DoubleProperty('anchor', anchor));
description.add(new DiagnosticsProperty<ViewportOffset>('offset', offset)); description.add(new DiagnosticsProperty<ViewportOffset>('offset', offset));
if (center != null) { if (center != null) {
...@@ -201,6 +233,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ...@@ -201,6 +233,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget {
ShrinkWrappingViewport({ ShrinkWrappingViewport({
Key key, Key key,
this.axisDirection: AxisDirection.down, this.axisDirection: AxisDirection.down,
this.crossAxisDirection,
@required this.offset, @required this.offset,
List<Widget> slivers: const <Widget>[], List<Widget> slivers: const <Widget>[],
}) : assert(offset != null), }) : assert(offset != null),
...@@ -213,6 +246,17 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ...@@ -213,6 +246,17 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget {
/// bottom of the viewport. /// bottom of the viewport.
final AxisDirection axisDirection; final AxisDirection axisDirection;
/// The direction in which child should be laid out in the cross axis.
///
/// If the [axisDirection] is [AxisDirection.down] or [AxisDirection.up], this
/// property defaults to [AxisDirection.left] if the ambient [Directionality]
/// is [TextDirection.rtl] and [AxisDirection.right] if the ambient
/// [Directionality] is [TextDirection.ltr].
///
/// If the [axisDirection] is [AxisDirection.left] or [AxisDirection.right],
/// this property defaults to [AxisDirection.down].
final AxisDirection crossAxisDirection;
/// Which part of the content inside the viewport should be visible. /// Which part of the content inside the viewport should be visible.
/// ///
/// The [ViewportOffset.pixels] value determines the scroll offset that the /// The [ViewportOffset.pixels] value determines the scroll offset that the
...@@ -227,6 +271,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ...@@ -227,6 +271,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget {
RenderShrinkWrappingViewport createRenderObject(BuildContext context) { RenderShrinkWrappingViewport createRenderObject(BuildContext context) {
return new RenderShrinkWrappingViewport( return new RenderShrinkWrappingViewport(
axisDirection: axisDirection, axisDirection: axisDirection,
crossAxisDirection: crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection),
offset: offset, offset: offset,
); );
} }
...@@ -235,6 +280,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ...@@ -235,6 +280,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget {
void updateRenderObject(BuildContext context, RenderShrinkWrappingViewport renderObject) { void updateRenderObject(BuildContext context, RenderShrinkWrappingViewport renderObject) {
renderObject renderObject
..axisDirection = axisDirection ..axisDirection = axisDirection
..crossAxisDirection = crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection)
..offset = offset; ..offset = offset;
} }
...@@ -242,6 +288,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ...@@ -242,6 +288,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget {
void debugFillProperties(DiagnosticPropertiesBuilder description) { void debugFillProperties(DiagnosticPropertiesBuilder description) {
super.debugFillProperties(description); super.debugFillProperties(description);
description.add(new EnumProperty<AxisDirection>('axisDirection', axisDirection)); description.add(new EnumProperty<AxisDirection>('axisDirection', axisDirection));
description.add(new EnumProperty<AxisDirection>('crossAxisDirection', crossAxisDirection, defaultValue: null));
description.add(new DiagnosticsProperty<ViewportOffset>('offset', offset)); description.add(new DiagnosticsProperty<ViewportOffset>('offset', offset));
} }
} }
...@@ -121,7 +121,10 @@ void main() { ...@@ -121,7 +121,10 @@ void main() {
testWidgets('splashing survives scrolling when keep-alive is enabled', (WidgetTester tester) async { testWidgets('splashing survives scrolling when keep-alive is enabled', (WidgetTester tester) async {
Future<Null> runTest(bool keepAlive) async { Future<Null> runTest(bool keepAlive) async {
await tester.pumpWidget(new Material( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new CompositedTransformFollower( // forces a layer, which makes the paints easier to separate out child: new CompositedTransformFollower( // forces a layer, which makes the paints easier to separate out
link: new LayerLink(), link: new LayerLink(),
child: new ListView( child: new ListView(
...@@ -133,7 +136,9 @@ void main() { ...@@ -133,7 +136,9 @@ void main() {
], ],
), ),
), ),
)); ),
),
);
expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child, paintsNothing); expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child, paintsNothing);
await tester.tap(find.byType(InkWell)); await tester.tap(find.byType(InkWell));
await tester.pump(); await tester.pump();
......
...@@ -60,7 +60,9 @@ void main() { ...@@ -60,7 +60,9 @@ void main() {
final List<Size> log = <Size>[]; final List<Size> log = <Size>[];
await tester.pumpWidget( await tester.pumpWidget(
new Column( new Directionality(
textDirection: TextDirection.ltr,
child: new Column(
children: <Widget>[ children: <Widget>[
new SizedBox( new SizedBox(
width: 150.0, width: 150.0,
...@@ -96,6 +98,7 @@ void main() { ...@@ -96,6 +98,7 @@ void main() {
), ),
], ],
), ),
),
); );
// We paint twice because we have two CustomPaint widgets in the tree above // We paint twice because we have two CustomPaint widgets in the tree above
......
...@@ -23,7 +23,9 @@ void main() { ...@@ -23,7 +23,9 @@ void main() {
testWidgets('RefreshIndicator', (WidgetTester tester) async { testWidgets('RefreshIndicator', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: refresh, onRefresh: refresh,
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -35,6 +37,7 @@ void main() { ...@@ -35,6 +37,7 @@ void main() {
}).toList(), }).toList(),
), ),
), ),
),
); );
await tester.fling(find.text('A'), const Offset(0.0, 300.0), 1000.0); await tester.fling(find.text('A'), const Offset(0.0, 300.0), 1000.0);
...@@ -48,7 +51,9 @@ void main() { ...@@ -48,7 +51,9 @@ void main() {
testWidgets('RefreshIndicator - bottom', (WidgetTester tester) async { testWidgets('RefreshIndicator - bottom', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: refresh, onRefresh: refresh,
child: new ListView( child: new ListView(
reverse: true, reverse: true,
...@@ -61,6 +66,7 @@ void main() { ...@@ -61,6 +66,7 @@ void main() {
], ],
), ),
), ),
),
); );
await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0); await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0);
...@@ -74,7 +80,9 @@ void main() { ...@@ -74,7 +80,9 @@ void main() {
testWidgets('RefreshIndicator - top - position', (WidgetTester tester) async { testWidgets('RefreshIndicator - top - position', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: holdRefresh, onRefresh: holdRefresh,
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -86,6 +94,7 @@ void main() { ...@@ -86,6 +94,7 @@ void main() {
], ],
), ),
), ),
),
); );
await tester.fling(find.text('X'), const Offset(0.0, 300.0), 1000.0); await tester.fling(find.text('X'), const Offset(0.0, 300.0), 1000.0);
...@@ -98,7 +107,9 @@ void main() { ...@@ -98,7 +107,9 @@ void main() {
testWidgets('RefreshIndicator - bottom - position', (WidgetTester tester) async { testWidgets('RefreshIndicator - bottom - position', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: holdRefresh, onRefresh: holdRefresh,
child: new ListView( child: new ListView(
reverse: true, reverse: true,
...@@ -111,6 +122,7 @@ void main() { ...@@ -111,6 +122,7 @@ void main() {
], ],
), ),
), ),
),
); );
await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0); await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0);
...@@ -123,7 +135,9 @@ void main() { ...@@ -123,7 +135,9 @@ void main() {
testWidgets('RefreshIndicator - no movement', (WidgetTester tester) async { testWidgets('RefreshIndicator - no movement', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: refresh, onRefresh: refresh,
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -135,6 +149,7 @@ void main() { ...@@ -135,6 +149,7 @@ void main() {
], ],
), ),
), ),
),
); );
// this fling is horizontal, not up or down // this fling is horizontal, not up or down
...@@ -149,7 +164,9 @@ void main() { ...@@ -149,7 +164,9 @@ void main() {
testWidgets('RefreshIndicator - not enough', (WidgetTester tester) async { testWidgets('RefreshIndicator - not enough', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: refresh, onRefresh: refresh,
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -161,6 +178,7 @@ void main() { ...@@ -161,6 +178,7 @@ void main() {
], ],
), ),
), ),
),
); );
await tester.fling(find.text('X'), const Offset(0.0, 100.0), 1000.0); await tester.fling(find.text('X'), const Offset(0.0, 100.0), 1000.0);
...@@ -174,7 +192,9 @@ void main() { ...@@ -174,7 +192,9 @@ void main() {
testWidgets('RefreshIndicator - show - slow', (WidgetTester tester) async { testWidgets('RefreshIndicator - show - slow', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: holdRefresh, // this one never returns onRefresh: holdRefresh, // this one never returns
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -186,6 +206,7 @@ void main() { ...@@ -186,6 +206,7 @@ void main() {
], ],
), ),
), ),
),
); );
bool completed = false; bool completed = false;
...@@ -215,7 +236,9 @@ void main() { ...@@ -215,7 +236,9 @@ void main() {
testWidgets('RefreshIndicator - show - fast', (WidgetTester tester) async { testWidgets('RefreshIndicator - show - fast', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: refresh, onRefresh: refresh,
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -227,6 +250,7 @@ void main() { ...@@ -227,6 +250,7 @@ void main() {
], ],
), ),
), ),
),
); );
bool completed = false; bool completed = false;
...@@ -257,7 +281,9 @@ void main() { ...@@ -257,7 +281,9 @@ void main() {
testWidgets('RefreshIndicator - show - fast - twice', (WidgetTester tester) async { testWidgets('RefreshIndicator - show - fast - twice', (WidgetTester tester) async {
refreshCalled = false; refreshCalled = false;
await tester.pumpWidget( await tester.pumpWidget(
new RefreshIndicator( new Directionality(
textDirection: TextDirection.ltr,
child: new RefreshIndicator(
onRefresh: refresh, onRefresh: refresh,
child: new ListView( child: new ListView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
...@@ -269,6 +295,7 @@ void main() { ...@@ -269,6 +295,7 @@ void main() {
], ],
), ),
), ),
),
); );
bool completed1 = false; bool completed1 = false;
......
...@@ -79,6 +79,7 @@ void main() { ...@@ -79,6 +79,7 @@ void main() {
RenderSliver s; RenderSliver s;
RenderBox b; RenderBox b;
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
s = new RenderSliverPadding( s = new RenderSliverPadding(
...@@ -106,6 +107,7 @@ void main() { ...@@ -106,6 +107,7 @@ void main() {
final RenderBox b = new RenderPadding( final RenderBox b = new RenderPadding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: new RenderViewport( child: new RenderViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
s = new RenderSliverPadding( s = new RenderSliverPadding(
......
...@@ -78,6 +78,7 @@ void main() { ...@@ -78,6 +78,7 @@ void main() {
); );
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
inner = childManager.createRenderObject(), inner = childManager.createRenderObject(),
...@@ -152,6 +153,7 @@ void main() { ...@@ -152,6 +153,7 @@ void main() {
); );
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.up, axisDirection: AxisDirection.up,
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
inner = childManager.createRenderObject(), inner = childManager.createRenderObject(),
...@@ -226,6 +228,7 @@ void main() { ...@@ -226,6 +228,7 @@ void main() {
); );
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
inner = childManager.createRenderObject(), inner = childManager.createRenderObject(),
......
...@@ -25,6 +25,7 @@ void main() { ...@@ -25,6 +25,7 @@ void main() {
overlap: 0.0, overlap: 0.0,
remainingPaintExtent: 0.0, remainingPaintExtent: 0.0,
crossAxisExtent: 0.0, crossAxisExtent: 0.0,
crossAxisDirection: AxisDirection.right,
viewportMainAxisExtent: 0.0, viewportMainAxisExtent: 0.0,
); );
final SliverConstraints b = a.copyWith(); final SliverConstraints b = a.copyWith();
...@@ -52,6 +53,7 @@ void main() { ...@@ -52,6 +53,7 @@ void main() {
overlap: 20.0, overlap: 20.0,
remainingPaintExtent: 30.0, remainingPaintExtent: 30.0,
crossAxisExtent: 40.0, crossAxisExtent: 40.0,
crossAxisDirection: AxisDirection.right,
viewportMainAxisExtent: 30.0, viewportMainAxisExtent: 30.0,
); );
expect(c, equals(d)); expect(c, equals(d));
......
...@@ -25,6 +25,7 @@ void main() { ...@@ -25,6 +25,7 @@ void main() {
RenderBox box; RenderBox box;
final RenderObject root = new RenderLayoutWatcher( final RenderObject root = new RenderLayoutWatcher(
viewport = new RenderViewport( viewport = new RenderViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
sliver = new RenderSliverToBoxAdapter(child: box = new RenderSizedBox(const Size(100.0, 400.0))), sliver = new RenderSliverToBoxAdapter(child: box = new RenderSizedBox(const Size(100.0, 400.0))),
......
...@@ -11,6 +11,7 @@ import 'rendering_tester.dart'; ...@@ -11,6 +11,7 @@ import 'rendering_tester.dart';
void main() { void main() {
test('RenderViewport basic test - no children', () { test('RenderViewport basic test - no children', () {
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
); );
expect(root, hasAGoodToStringDeep); expect(root, hasAGoodToStringDeep);
...@@ -22,6 +23,7 @@ void main() { ...@@ -22,6 +23,7 @@ void main() {
' constraints: null\n' ' constraints: null\n'
' size: MISSING\n' ' size: MISSING\n'
' axisDirection: down\n' ' axisDirection: down\n'
' crossAxisDirection: right\n'
' offset: _FixedViewportOffset#00000(offset: 0.0)\n' ' offset: _FixedViewportOffset#00000(offset: 0.0)\n'
' anchor: 0.0\n' ' anchor: 0.0\n'
), ),
...@@ -37,6 +39,7 @@ void main() { ...@@ -37,6 +39,7 @@ void main() {
' constraints: BoxConstraints(w=800.0, h=600.0)\n' ' constraints: BoxConstraints(w=800.0, h=600.0)\n'
' size: Size(800.0, 600.0)\n' ' size: Size(800.0, 600.0)\n'
' axisDirection: down\n' ' axisDirection: down\n'
' crossAxisDirection: right\n'
' offset: _FixedViewportOffset#00000(offset: 900.0)\n' ' offset: _FixedViewportOffset#00000(offset: 900.0)\n'
' anchor: 0.0\n', ' anchor: 0.0\n',
), ),
...@@ -48,6 +51,7 @@ void main() { ...@@ -48,6 +51,7 @@ void main() {
test('RenderViewport basic test - down', () { test('RenderViewport basic test - down', () {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))),
...@@ -72,6 +76,7 @@ void main() { ...@@ -72,6 +76,7 @@ void main() {
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n' ' │ size: Size(800.0, 600.0)\n'
' │ axisDirection: down\n' ' │ axisDirection: down\n'
' │ crossAxisDirection: right\n'
' │ offset: _FixedViewportOffset#00000(offset: 0.0)\n' ' │ offset: _FixedViewportOffset#00000(offset: 0.0)\n'
' │ anchor: 0.0\n' ' │ anchor: 0.0\n'
' │\n' ' │\n'
...@@ -80,6 +85,7 @@ void main() { ...@@ -80,6 +85,7 @@ void main() {
' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' ' │ │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
' │ │ crossAxisDirection: AxisDirection.right,\n'
' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ viewportMainAxisExtent: 600.0)\n'
' │ │ geometry: SliverGeometry(scrollExtent: 400.0, paintExtent: 400.0,\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, paintExtent: 400.0,\n'
' │ │ maxPaintExtent: 400.0)\n' ' │ │ maxPaintExtent: 400.0)\n'
...@@ -94,6 +100,7 @@ void main() { ...@@ -94,6 +100,7 @@ void main() {
' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ │ 0.0, remainingPaintExtent: 200.0, crossAxisExtent: 800.0,\n' ' │ │ 0.0, remainingPaintExtent: 200.0, crossAxisExtent: 800.0,\n'
' │ │ crossAxisDirection: AxisDirection.right,\n'
' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ viewportMainAxisExtent: 600.0)\n'
' │ │ geometry: SliverGeometry(scrollExtent: 400.0, paintExtent: 200.0,\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, paintExtent: 200.0,\n'
' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' ' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n'
...@@ -108,6 +115,7 @@ void main() { ...@@ -108,6 +115,7 @@ void main() {
' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n' ' │ │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n'
' │ │ crossAxisDirection: AxisDirection.right,\n'
' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ viewportMainAxisExtent: 600.0)\n'
' │ │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n'
' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' ' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n'
...@@ -122,6 +130,7 @@ void main() { ...@@ -122,6 +130,7 @@ void main() {
' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n' ' │ │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n'
' │ │ crossAxisDirection: AxisDirection.right,\n'
' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ viewportMainAxisExtent: 600.0)\n'
' │ │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n'
' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' ' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n'
...@@ -136,6 +145,7 @@ void main() { ...@@ -136,6 +145,7 @@ void main() {
' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n' ' │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n'
' │ crossAxisDirection: AxisDirection.right,\n'
' │ viewportMainAxisExtent: 600.0)\n' ' │ viewportMainAxisExtent: 600.0)\n'
' │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n' ' │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n'
' │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' ' │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n'
...@@ -143,7 +153,7 @@ void main() { ...@@ -143,7 +153,7 @@ void main() {
' └─child: RenderSizedBox#00000 NEEDS-PAINT\n' ' └─child: RenderSizedBox#00000 NEEDS-PAINT\n'
' parentData: paintOffset=Offset(0.0, -0.0) (can use size)\n' ' parentData: paintOffset=Offset(0.0, -0.0) (can use size)\n'
' constraints: BoxConstraints(w=800.0, 0.0<=h<=Infinity)\n' ' constraints: BoxConstraints(w=800.0, 0.0<=h<=Infinity)\n'
' size: Size(800.0, 400.0)\n', ' size: Size(800.0, 400.0)\n'
), ),
); );
expect(a.localToGlobal(const Offset(0.0, 0.0)), const Offset(0.0, 0.0)); expect(a.localToGlobal(const Offset(0.0, 0.0)), const Offset(0.0, 0.0));
...@@ -191,6 +201,7 @@ void main() { ...@@ -191,6 +201,7 @@ void main() {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.up, axisDirection: AxisDirection.up,
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))),
...@@ -249,6 +260,7 @@ void main() { ...@@ -249,6 +260,7 @@ void main() {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))),
...@@ -332,6 +344,7 @@ void main() { ...@@ -332,6 +344,7 @@ void main() {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))),
...@@ -387,6 +400,7 @@ void main() { ...@@ -387,6 +400,7 @@ void main() {
test('RenderShrinkWrappingViewport basic test - no children', () { test('RenderShrinkWrappingViewport basic test - no children', () {
final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
); );
expect(root, hasAGoodToStringDeep); expect(root, hasAGoodToStringDeep);
...@@ -398,6 +412,7 @@ void main() { ...@@ -398,6 +412,7 @@ void main() {
test('RenderShrinkWrappingViewport basic test - down', () { test('RenderShrinkWrappingViewport basic test - down', () {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))),
...@@ -457,6 +472,7 @@ void main() { ...@@ -457,6 +472,7 @@ void main() {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport(
axisDirection: AxisDirection.up, axisDirection: AxisDirection.up,
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))),
...@@ -510,6 +526,7 @@ void main() { ...@@ -510,6 +526,7 @@ void main() {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))),
...@@ -563,6 +580,7 @@ void main() { ...@@ -563,6 +580,7 @@ void main() {
RenderBox a, b, c, d, e; RenderBox a, b, c, d, e;
final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))),
...@@ -617,6 +635,7 @@ void main() { ...@@ -617,6 +635,7 @@ void main() {
final RenderBox root = new RenderPositionedBox( final RenderBox root = new RenderPositionedBox(
child: child = new RenderShrinkWrappingViewport( child: child = new RenderShrinkWrappingViewport(
axisDirection: AxisDirection.left, axisDirection: AxisDirection.left,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.fixed(200.0), offset: new ViewportOffset.fixed(200.0),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: new RenderSizedBox(const Size(400.0, 100.0))), new RenderSliverToBoxAdapter(child: new RenderSizedBox(const Size(400.0, 100.0))),
...@@ -636,6 +655,7 @@ void main() { ...@@ -636,6 +655,7 @@ void main() {
final RenderBox root = new RenderPositionedBox( final RenderBox root = new RenderPositionedBox(
child: child = new RenderShrinkWrappingViewport( child: child = new RenderShrinkWrappingViewport(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.fixed(200.0), offset: new ViewportOffset.fixed(200.0),
children: <RenderSliver>[ children: <RenderSliver>[
new RenderSliverToBoxAdapter(child: new RenderSizedBox(const Size(300.0, 100.0))), new RenderSliverToBoxAdapter(child: new RenderSizedBox(const Size(300.0, 100.0))),
...@@ -687,6 +707,7 @@ void main() { ...@@ -687,6 +707,7 @@ void main() {
); );
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
sliver, sliver,
...@@ -708,6 +729,7 @@ void main() { ...@@ -708,6 +729,7 @@ void main() {
); );
final RenderViewport root = new RenderViewport( final RenderViewport root = new RenderViewport(
axisDirection: AxisDirection.right, axisDirection: AxisDirection.right,
crossAxisDirection: AxisDirection.down,
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
children: <RenderSliver>[ children: <RenderSliver>[
sliver, sliver,
......
...@@ -10,7 +10,9 @@ void main() { ...@@ -10,7 +10,9 @@ void main() {
final Map<int, Animation<double>> animations = <int, Animation<double>>{}; final Map<int, Animation<double>> animations = <int, Animation<double>>{};
await tester.pumpWidget( await tester.pumpWidget(
new AnimatedList( new Directionality(
textDirection: TextDirection.ltr,
child: new AnimatedList(
initialItemCount: 2, initialItemCount: 2,
itemBuilder: (BuildContext context, int index, Animation<double> animation) { itemBuilder: (BuildContext context, int index, Animation<double> animation) {
animations[index] = animation; animations[index] = animation;
...@@ -22,6 +24,7 @@ void main() { ...@@ -22,6 +24,7 @@ void main() {
); );
}, },
), ),
),
); );
expect(find.text('item 0'), findsOneWidget); expect(find.text('item 0'), findsOneWidget);
...@@ -36,7 +39,9 @@ void main() { ...@@ -36,7 +39,9 @@ void main() {
final GlobalKey<AnimatedListState> listKey = new GlobalKey<AnimatedListState>(); final GlobalKey<AnimatedListState> listKey = new GlobalKey<AnimatedListState>();
await tester.pumpWidget( await tester.pumpWidget(
new AnimatedList( new Directionality(
textDirection: TextDirection.ltr,
child: new AnimatedList(
key: listKey, key: listKey,
itemBuilder: (BuildContext context, int index, Animation<double> animation) { itemBuilder: (BuildContext context, int index, Animation<double> animation) {
return new SizeTransition( return new SizeTransition(
...@@ -52,6 +57,7 @@ void main() { ...@@ -52,6 +57,7 @@ void main() {
); );
}, },
), ),
),
); );
double itemHeight(int index) => tester.getSize(find.byKey(new ValueKey<int>(index))).height; double itemHeight(int index) => tester.getSize(find.byKey(new ValueKey<int>(index))).height;
...@@ -122,13 +128,16 @@ void main() { ...@@ -122,13 +128,16 @@ void main() {
} }
await tester.pumpWidget( await tester.pumpWidget(
new AnimatedList( new Directionality(
textDirection: TextDirection.ltr,
child: new AnimatedList(
key: listKey, key: listKey,
initialItemCount: 3, initialItemCount: 3,
itemBuilder: (BuildContext context, int index, Animation<double> animation) { itemBuilder: (BuildContext context, int index, Animation<double> animation) {
return buildItem(context, items[index], animation); return buildItem(context, items[index], animation);
}, },
), ),
),
); );
double itemTop(int index) => tester.getTopLeft(find.byKey(new ValueKey<int>(index))).dy; double itemTop(int index) => tester.getTopLeft(find.byKey(new ValueKey<int>(index))).dy;
......
...@@ -65,12 +65,17 @@ List<Widget> generateList(Widget child, { @required bool impliedMode }) { ...@@ -65,12 +65,17 @@ List<Widget> generateList(Widget child, { @required bool impliedMode }) {
void tests({ @required bool impliedMode }) { void tests({ @required bool impliedMode }) {
testWidgets('AutomaticKeepAlive with ListView with itemExtent', (WidgetTester tester) async { testWidgets('AutomaticKeepAlive with ListView with itemExtent', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
addAutomaticKeepAlives: impliedMode, addAutomaticKeepAlives: impliedMode,
addRepaintBoundaries: impliedMode, addRepaintBoundaries: impliedMode,
itemExtent: 12.3, // about 50 widgets visible itemExtent: 12.3, // about 50 widgets visible
children: generateList(const Placeholder(), impliedMode: impliedMode), children: generateList(const Placeholder(), impliedMode: impliedMode),
)); ),
),
);
expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing);
...@@ -105,14 +110,19 @@ void tests({ @required bool impliedMode }) { ...@@ -105,14 +110,19 @@ void tests({ @required bool impliedMode }) {
}); });
testWidgets('AutomaticKeepAlive with ListView without itemExtent', (WidgetTester tester) async { testWidgets('AutomaticKeepAlive with ListView without itemExtent', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
addAutomaticKeepAlives: impliedMode, addAutomaticKeepAlives: impliedMode,
addRepaintBoundaries: impliedMode, addRepaintBoundaries: impliedMode,
children: generateList( children: generateList(
new Container(height: 12.3, child: const Placeholder()), // about 50 widgets visible new Container(height: 12.3, child: const Placeholder()), // about 50 widgets visible
impliedMode: impliedMode, impliedMode: impliedMode,
), ),
)); ),
),
);
expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing);
...@@ -147,7 +157,10 @@ void tests({ @required bool impliedMode }) { ...@@ -147,7 +157,10 @@ void tests({ @required bool impliedMode }) {
}); });
testWidgets('AutomaticKeepAlive with GridView', (WidgetTester tester) async { testWidgets('AutomaticKeepAlive with GridView', (WidgetTester tester) async {
await tester.pumpWidget(new GridView.count( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.count(
addAutomaticKeepAlives: impliedMode, addAutomaticKeepAlives: impliedMode,
addRepaintBoundaries: impliedMode, addRepaintBoundaries: impliedMode,
crossAxisCount: 2, crossAxisCount: 2,
...@@ -156,7 +169,9 @@ void tests({ @required bool impliedMode }) { ...@@ -156,7 +169,9 @@ void tests({ @required bool impliedMode }) {
new Container(child: const Placeholder()), new Container(child: const Placeholder()),
impliedMode: impliedMode, impliedMode: impliedMode,
), ),
)); ),
),
);
expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing);
...@@ -196,7 +211,8 @@ void main() { ...@@ -196,7 +211,8 @@ void main() {
group('Implied automatic keep-alive', () { tests(impliedMode: true); }); group('Implied automatic keep-alive', () { tests(impliedMode: true); });
testWidgets('AutomaticKeepAlive double', (WidgetTester tester) async { testWidgets('AutomaticKeepAlive double', (WidgetTester tester) async {
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new ListView( child: new ListView(
addAutomaticKeepAlives: false, addAutomaticKeepAlives: false,
...@@ -225,7 +241,8 @@ void main() { ...@@ -225,7 +241,8 @@ void main() {
), ),
], ],
), ),
)); ),
);
expect(find.byKey(const GlobalObjectKey<_LeafState>(0)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(0)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(1)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(1)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(2)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(2)), findsOneWidget);
...@@ -270,7 +287,8 @@ void main() { ...@@ -270,7 +287,8 @@ void main() {
}); });
testWidgets('AutomaticKeepAlive double', (WidgetTester tester) async { testWidgets('AutomaticKeepAlive double', (WidgetTester tester) async {
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new ListView( child: new ListView(
addAutomaticKeepAlives: false, addAutomaticKeepAlives: false,
...@@ -305,7 +323,8 @@ void main() { ...@@ -305,7 +323,8 @@ void main() {
), ),
], ],
), ),
)); ),
);
expect(find.byKey(const GlobalObjectKey<_LeafState>(0)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(0)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(1)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(1)), findsOneWidget);
expect(find.byKey(const GlobalObjectKey<_LeafState>(2)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(2)), findsOneWidget);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
void main() { void main() {
...@@ -33,24 +34,28 @@ void main() { ...@@ -33,24 +34,28 @@ void main() {
testWidgets('Box in a sliver', (WidgetTester tester) async { testWidgets('Box in a sliver', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Viewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(),
slivers: <Widget>[ slivers: <Widget>[
const SizedBox(), const SizedBox(),
], ],
) ),
); );
expect(tester.takeException(), isFlutterError); expect(tester.takeException(), isFlutterError);
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Viewport(
crossAxisDirection: AxisDirection.right,
offset: new ViewportOffset.zero(),
slivers: <Widget>[ slivers: <Widget>[
const SliverPadding( const SliverPadding(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
sliver: const SizedBox(), sliver: const SizedBox(),
), ),
], ],
) ),
); );
expect(tester.takeException(), isFlutterError); expect(tester.takeException(), isFlutterError);
......
...@@ -7,6 +7,11 @@ import 'package:flutter/widgets.dart'; ...@@ -7,6 +7,11 @@ import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
await tester.pumpWidget(new ListView(children: <Widget>[const Center()])); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(children: <Widget>[const Center()])
),
);
}); });
} }
...@@ -135,6 +135,11 @@ void main() { ...@@ -135,6 +135,11 @@ void main() {
}); });
testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
await tester.pumpWidget(new ListView(children: <Widget>[new Container()])); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(children: <Widget>[new Container()]),
),
);
}); });
} }
...@@ -9,7 +9,9 @@ void main() { ...@@ -9,7 +9,9 @@ void main() {
testWidgets('Can select a day', (WidgetTester tester) async { testWidgets('Can select a day', (WidgetTester tester) async {
DateTime currentValue; DateTime currentValue;
final Widget widget = new Material( final Widget widget = new Directionality(
textDirection: TextDirection.ltr,
child: new Material(
child: new ListView( child: new ListView(
children: <Widget>[ children: <Widget>[
new MonthPicker( new MonthPicker(
...@@ -18,10 +20,11 @@ void main() { ...@@ -18,10 +20,11 @@ void main() {
lastDate: new DateTime.utc(2018), lastDate: new DateTime.utc(2018),
onChanged: (DateTime dateTime) { onChanged: (DateTime dateTime) {
currentValue = dateTime; currentValue = dateTime;
} },
) ),
] ],
) ),
),
); );
await tester.pumpWidget(widget); await tester.pumpWidget(widget);
......
...@@ -387,7 +387,10 @@ void main() { ...@@ -387,7 +387,10 @@ void main() {
); );
} }
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new SizedBox( child: new SizedBox(
width: 600.0, width: 600.0,
height: 400.0, height: 400.0,
...@@ -409,7 +412,9 @@ void main() { ...@@ -409,7 +412,9 @@ void main() {
}, },
), ),
), ),
)); ),
),
);
await prepare(-125.0); await prepare(-125.0);
Scrollable.ensureVisible(findContext(3)); Scrollable.ensureVisible(findContext(3));
...@@ -628,7 +633,10 @@ void main() { ...@@ -628,7 +633,10 @@ void main() {
await tester.pump(); await tester.pump();
} }
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new SizedBox( child: new SizedBox(
width: 600.0, width: 600.0,
height: 400.0, height: 400.0,
...@@ -656,7 +664,9 @@ void main() { ...@@ -656,7 +664,9 @@ void main() {
}, },
), ),
), ),
)); ),
),
);
await prepare(480.0); await prepare(480.0);
Scrollable.ensureVisible(findContext(3)); Scrollable.ensureVisible(findContext(3));
......
...@@ -118,7 +118,9 @@ void main() { ...@@ -118,7 +118,9 @@ void main() {
String errorText(String input) => fieldKey.currentState.value?.toString() + '/error'; String errorText(String input) => fieldKey.currentState.value?.toString() + '/error';
Widget builder() { Widget builder() {
return new Center( return new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new Material( child: new Material(
child: new Form( child: new Form(
key: formKey, key: formKey,
...@@ -135,6 +137,7 @@ void main() { ...@@ -135,6 +137,7 @@ void main() {
), ),
), ),
), ),
),
); );
} }
......
...@@ -14,7 +14,10 @@ void main() { ...@@ -14,7 +14,10 @@ void main() {
const DecoratedBox(decoration: const BoxDecoration()), const DecoratedBox(decoration: const BoxDecoration()),
]; ];
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new Container( child: new Container(
width: 200.0, width: 200.0,
child: new GridView.extent( child: new GridView.extent(
...@@ -23,7 +26,9 @@ void main() { ...@@ -23,7 +26,9 @@ void main() {
children: children, children: children,
), ),
), ),
)); ),
),
);
expect(tester.renderObjectList<RenderBox>(find.byType(DecoratedBox)), hasLength(4)); expect(tester.renderObjectList<RenderBox>(find.byType(DecoratedBox)), hasLength(4));
...@@ -38,7 +43,10 @@ void main() { ...@@ -38,7 +43,10 @@ void main() {
expect(grid.debugNeedsLayout, false); expect(grid.debugNeedsLayout, false);
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new Container( child: new Container(
width: 200.0, width: 200.0,
child: new GridView.extent( child: new GridView.extent(
...@@ -47,7 +55,9 @@ void main() { ...@@ -47,7 +55,9 @@ void main() {
children: children, children: children,
), ),
), ),
)); ),
),
);
for (RenderBox box in tester.renderObjectList<RenderBox>(find.byType(DecoratedBox))) { for (RenderBox box in tester.renderObjectList<RenderBox>(find.byType(DecoratedBox))) {
expect(box.size.width, equals(50.0), reason: "child width"); expect(box.size.width, equals(50.0), reason: "child width");
......
...@@ -10,16 +10,24 @@ import 'states.dart'; ...@@ -10,16 +10,24 @@ import 'states.dart';
void main() { void main() {
testWidgets('Empty GridView', (WidgetTester tester) async { testWidgets('Empty GridView', (WidgetTester tester) async {
await tester.pumpWidget(new GridView.count( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
children: const <Widget>[], children: const <Widget>[],
)); ),
),
);
}); });
testWidgets('GridView.count control test', (WidgetTester tester) async { testWidgets('GridView.count control test', (WidgetTester tester) async {
final List<String> log = <String>[]; final List<String> log = <String>[];
await tester.pumpWidget(new GridView.count( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
children: kStates.map((String state) { children: kStates.map((String state) {
return new GestureDetector( return new GestureDetector(
...@@ -32,7 +40,9 @@ void main() { ...@@ -32,7 +40,9 @@ void main() {
), ),
); );
}).toList(), }).toList(),
)); ),
),
);
expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0))); expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0)));
...@@ -85,7 +95,10 @@ void main() { ...@@ -85,7 +95,10 @@ void main() {
testWidgets('GridView.extent control test', (WidgetTester tester) async { testWidgets('GridView.extent control test', (WidgetTester tester) async {
final List<String> log = <String>[]; final List<String> log = <String>[];
await tester.pumpWidget(new GridView.extent( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.extent(
maxCrossAxisExtent: 200.0, maxCrossAxisExtent: 200.0,
children: kStates.map((String state) { children: kStates.map((String state) {
return new GestureDetector( return new GestureDetector(
...@@ -98,7 +111,9 @@ void main() { ...@@ -98,7 +111,9 @@ void main() {
), ),
); );
}).toList(), }).toList(),
)); ),
),
);
expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0))); expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0)));
...@@ -126,7 +141,8 @@ void main() { ...@@ -126,7 +141,8 @@ void main() {
testWidgets('GridView large scroll jump', (WidgetTester tester) async { testWidgets('GridView large scroll jump', (WidgetTester tester) async {
final List<int> log = <int>[]; final List<int> log = <int>[];
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new GridView.extent( child: new GridView.extent(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
...@@ -143,7 +159,8 @@ void main() { ...@@ -143,7 +159,8 @@ void main() {
); );
}), }),
), ),
)); ),
);
expect(tester.getSize(find.text('4')), equals(const Size(200.0 / 0.75, 200.0))); expect(tester.getSize(find.text('4')), equals(const Size(200.0 / 0.75, 200.0)));
...@@ -154,7 +171,6 @@ void main() { ...@@ -154,7 +171,6 @@ void main() {
])); ]));
log.clear(); log.clear();
final ScrollableState state = tester.state(find.byType(Scrollable)); final ScrollableState state = tester.state(find.byType(Scrollable));
final ScrollPosition position = state.position; final ScrollPosition position = state.position;
position.jumpTo(3025.0); position.jumpTo(3025.0);
...@@ -188,7 +204,9 @@ void main() { ...@@ -188,7 +204,9 @@ void main() {
final List<int> log = <int>[]; final List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new GridView( new Directionality(
textDirection: TextDirection.ltr,
child: new GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4, crossAxisCount: 4,
), ),
...@@ -203,6 +221,7 @@ void main() { ...@@ -203,6 +221,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(tester.getSize(find.text('4')), equals(const Size(200.0, 200.0))); expect(tester.getSize(find.text('4')), equals(const Size(200.0, 200.0)));
...@@ -215,7 +234,9 @@ void main() { ...@@ -215,7 +234,9 @@ void main() {
log.clear(); log.clear();
await tester.pumpWidget( await tester.pumpWidget(
new GridView( new Directionality(
textDirection: TextDirection.ltr,
child: new GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, crossAxisCount: 2,
), ),
...@@ -230,6 +251,7 @@ void main() { ...@@ -230,6 +251,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(log, equals(<int>[ expect(log, equals(<int>[
...@@ -247,7 +269,9 @@ void main() { ...@@ -247,7 +269,9 @@ void main() {
final List<int> log = <int>[]; final List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new GridView( new Directionality(
textDirection: TextDirection.ltr,
child: new GridView(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200.0, maxCrossAxisExtent: 200.0,
), ),
...@@ -262,6 +286,7 @@ void main() { ...@@ -262,6 +286,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(tester.getSize(find.text('4')), equals(const Size(200.0, 200.0))); expect(tester.getSize(find.text('4')), equals(const Size(200.0, 200.0)));
...@@ -274,7 +299,9 @@ void main() { ...@@ -274,7 +299,9 @@ void main() {
log.clear(); log.clear();
await tester.pumpWidget( await tester.pumpWidget(
new GridView( new Directionality(
textDirection: TextDirection.ltr,
child: new GridView(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 400.0, maxCrossAxisExtent: 400.0,
), ),
...@@ -289,6 +316,7 @@ void main() { ...@@ -289,6 +316,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(log, equals(<int>[ expect(log, equals(<int>[
...@@ -311,7 +339,10 @@ void main() { ...@@ -311,7 +339,10 @@ void main() {
), ),
); );
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new SizedBox( child: new SizedBox(
height: 200.0, height: 200.0,
child: new GridView.count( child: new GridView.count(
...@@ -319,7 +350,9 @@ void main() { ...@@ -319,7 +350,9 @@ void main() {
children: <Widget>[ container, container, container, container ], children: <Widget>[ container, container, container, container ],
), ),
), ),
)); ),
),
);
expect(find.byType(GridView), paints..rect(color: green)..rect(color: green)); expect(find.byType(GridView), paints..rect(color: green)..rect(color: green));
expect(find.byType(GridView), isNot(paints..rect(color: green)..rect(color: green)..rect(color: green))); expect(find.byType(GridView), isNot(paints..rect(color: green)..rect(color: green)..rect(color: green)));
...@@ -327,7 +360,9 @@ void main() { ...@@ -327,7 +360,9 @@ void main() {
testWidgets('GridView in zero context', (WidgetTester tester) async { testWidgets('GridView in zero context', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Center( new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new SizedBox( child: new SizedBox(
width: 0.0, width: 0.0,
height: 0.0, height: 0.0,
...@@ -341,6 +376,7 @@ void main() { ...@@ -341,6 +376,7 @@ void main() {
), ),
), ),
), ),
),
); );
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
...@@ -349,7 +385,9 @@ void main() { ...@@ -349,7 +385,9 @@ void main() {
testWidgets('GridView in unbounded context', (WidgetTester tester) async { testWidgets('GridView in unbounded context', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new SingleChildScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new SingleChildScrollView(
child: new GridView.count( child: new GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
shrinkWrap: true, shrinkWrap: true,
...@@ -360,6 +398,7 @@ void main() { ...@@ -360,6 +398,7 @@ void main() {
}), }),
), ),
), ),
),
); );
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
...@@ -367,7 +406,10 @@ void main() { ...@@ -367,7 +406,10 @@ void main() {
}); });
testWidgets('GridView.builder control test', (WidgetTester tester) async { testWidgets('GridView.builder control test', (WidgetTester tester) async {
await tester.pumpWidget(new GridView.builder( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4, crossAxisCount: 4,
), ),
...@@ -378,12 +420,40 @@ void main() { ...@@ -378,12 +420,40 @@ void main() {
child: new Text('$index'), child: new Text('$index'),
); );
}, },
)); ),
),
);
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
expect(find.text('11'), findsOneWidget); expect(find.text('11'), findsOneWidget);
expect(find.text('12'), findsNothing); expect(find.text('12'), findsNothing);
}); });
testWidgets('GridView cross axis layout', (WidgetTester tester) async {
final Key target = new UniqueKey();
Widget build(TextDirection textDirection) {
return new Directionality(
textDirection: textDirection,
child: new GridView.count(
crossAxisCount: 4,
children: <Widget>[
new Container(key: target),
],
),
);
}
await tester.pumpWidget(build(TextDirection.ltr));
expect(tester.getTopLeft(find.byKey(target)), Offset.zero);
expect(tester.getBottomRight(find.byKey(target)), const Offset(200.0, 200.0));
await tester.pumpWidget(build(TextDirection.rtl));
expect(tester.getTopLeft(find.byKey(target)), const Offset(600.0, 0.0));
expect(tester.getBottomRight(find.byKey(target)), const Offset(800.0, 200.0));
});
// TODO(ianh): can you tap a grid cell that is slightly off the bottom of the screen? // TODO(ianh): can you tap a grid cell that is slightly off the bottom of the screen?
// (try it with the flutter_gallery Grid demo) // (try it with the flutter_gallery Grid demo)
} }
...@@ -282,7 +282,9 @@ class _TestState extends State<Test> { ...@@ -282,7 +282,9 @@ class _TestState extends State<Test> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Column( return new Directionality(
textDirection: TextDirection.ltr,
child: new Column(
children: <Widget>[ children: <Widget>[
new Expanded( new Expanded(
child: new ListView( child: new ListView(
...@@ -356,6 +358,7 @@ class _TestState extends State<Test> { ...@@ -356,6 +358,7 @@ class _TestState extends State<Test> {
), ),
), ),
], ],
),
); );
} }
} }
......
...@@ -15,7 +15,9 @@ void main() { ...@@ -15,7 +15,9 @@ void main() {
// so if our widget is 100 pixels tall, it should fit exactly 6 times. // so if our widget is 100 pixels tall, it should fit exactly 6 times.
Widget builder() { Widget builder() {
return new FlipWidget( return new Directionality(
textDirection: TextDirection.ltr,
child: new FlipWidget(
left: new ListView.builder( left: new ListView.builder(
itemExtent: 100.0, itemExtent: 100.0,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
...@@ -28,6 +30,7 @@ void main() { ...@@ -28,6 +30,7 @@ void main() {
}, },
), ),
right: const Text('Not Today'), right: const Text('Not Today'),
),
); );
} }
...@@ -67,14 +70,17 @@ void main() { ...@@ -67,14 +70,17 @@ void main() {
); );
}; };
FlipWidget buildWidget() { Widget buildWidget() {
return new FlipWidget( return new Directionality(
textDirection: TextDirection.ltr,
child: new FlipWidget(
left: new ListView.builder( left: new ListView.builder(
controller: new ScrollController(initialScrollOffset: 300.0), controller: new ScrollController(initialScrollOffset: 300.0),
itemExtent: 200.0, itemExtent: 200.0,
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
), ),
right: const Text('Not Today') right: const Text('Not Today')
),
); );
} }
...@@ -187,10 +193,13 @@ void main() { ...@@ -187,10 +193,13 @@ void main() {
return new Text('$index', key: new ValueKey<int>(index)); return new Text('$index', key: new ValueKey<int>(index));
}; };
final Widget testWidget = new ListView.builder( final Widget testWidget = new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
itemExtent: 300.0, itemExtent: 300.0,
itemCount: 10, itemCount: 10,
),
); );
void jumpTo(double newScrollOffset) { void jumpTo(double newScrollOffset) {
......
...@@ -8,7 +8,10 @@ import 'package:flutter/material.dart'; ...@@ -8,7 +8,10 @@ import 'package:flutter/material.dart';
void main() { void main() {
testWidgets('ListView can handle shrinking top elements', (WidgetTester tester) async { testWidgets('ListView can handle shrinking top elements', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[ children: <Widget>[
new Container(height: 400.0, child: const Text('1')), new Container(height: 400.0, child: const Text('1')),
...@@ -18,14 +21,19 @@ void main() { ...@@ -18,14 +21,19 @@ void main() {
new Container(height: 400.0, child: const Text('5')), new Container(height: 400.0, child: const Text('5')),
new Container(height: 400.0, child: const Text('6')), new Container(height: 400.0, child: const Text('6')),
], ],
)); ),
),
);
controller.jumpTo(1000.0); controller.jumpTo(1000.0);
await tester.pump(); await tester.pump();
expect(tester.getTopLeft(find.text('4')).dy, equals(200.0)); expect(tester.getTopLeft(find.text('4')).dy, equals(200.0));
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[ children: <Widget>[
new Container(height: 200.0, child: const Text('1')), new Container(height: 200.0, child: const Text('1')),
...@@ -35,7 +43,9 @@ void main() { ...@@ -35,7 +43,9 @@ void main() {
new Container(height: 400.0, child: const Text('5')), new Container(height: 400.0, child: const Text('5')),
new Container(height: 400.0, child: const Text('6')), new Container(height: 400.0, child: const Text('6')),
], ],
)); ),
),
);
expect(controller.offset, equals(1000.0)); expect(controller.offset, equals(1000.0));
expect(tester.getTopLeft(find.text('4')).dy, equals(200.0)); expect(tester.getTopLeft(find.text('4')).dy, equals(200.0));
...@@ -55,7 +65,10 @@ void main() { ...@@ -55,7 +65,10 @@ void main() {
testWidgets('ListView can handle inserts at 0', (WidgetTester tester) async { testWidgets('ListView can handle inserts at 0', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[ children: <Widget>[
new Container(height: 400.0, child: const Text('0')), new Container(height: 400.0, child: const Text('0')),
...@@ -63,7 +76,9 @@ void main() { ...@@ -63,7 +76,9 @@ void main() {
new Container(height: 400.0, child: const Text('2')), new Container(height: 400.0, child: const Text('2')),
new Container(height: 400.0, child: const Text('3')), new Container(height: 400.0, child: const Text('3')),
], ],
)); ),
),
);
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsOneWidget); expect(find.text('1'), findsOneWidget);
expect(find.text('2'), findsNothing); expect(find.text('2'), findsNothing);
...@@ -71,7 +86,10 @@ void main() { ...@@ -71,7 +86,10 @@ void main() {
final Finder findItemA = find.descendant(of: find.byType(Container), matching: find.text('A')); final Finder findItemA = find.descendant(of: find.byType(Container), matching: find.text('A'));
final Finder findItemB = find.descendant(of: find.byType(Container), matching: find.text('B')); final Finder findItemB = find.descendant(of: find.byType(Container), matching: find.text('B'));
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[ children: <Widget>[
new Container(height: 10.0, child: const Text('A')), new Container(height: 10.0, child: const Text('A')),
...@@ -81,7 +99,9 @@ void main() { ...@@ -81,7 +99,9 @@ void main() {
new Container(height: 400.0, child: const Text('2')), new Container(height: 400.0, child: const Text('2')),
new Container(height: 400.0, child: const Text('3')), new Container(height: 400.0, child: const Text('3')),
], ],
)); ),
),
);
expect(find.text('A'), findsOneWidget); expect(find.text('A'), findsOneWidget);
expect(find.text('B'), findsOneWidget); expect(find.text('B'), findsOneWidget);
expect(tester.getTopLeft(findItemA).dy, 0.0); expect(tester.getTopLeft(findItemA).dy, 0.0);
...@@ -95,7 +115,10 @@ void main() { ...@@ -95,7 +115,10 @@ void main() {
expect(find.text('A'), findsNothing); expect(find.text('A'), findsNothing);
expect(find.text('B'), findsNothing); expect(find.text('B'), findsNothing);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[ children: <Widget>[
new Container(height: 200.0, child: const Text('A')), new Container(height: 200.0, child: const Text('A')),
...@@ -105,7 +128,9 @@ void main() { ...@@ -105,7 +128,9 @@ void main() {
new Container(height: 400.0, child: const Text('2')), new Container(height: 400.0, child: const Text('2')),
new Container(height: 400.0, child: const Text('3')), new Container(height: 400.0, child: const Text('3')),
], ],
)); ),
),
);
expect(find.text('A'), findsNothing); expect(find.text('A'), findsNothing);
expect(find.text('B'), findsNothing); expect(find.text('B'), findsNothing);
......
...@@ -10,11 +10,16 @@ const double kFlingOffset = kHeight * 20.0; ...@@ -10,11 +10,16 @@ const double kFlingOffset = kHeight * 20.0;
void main() { void main() {
testWidgets('Flings don\'t stutter', (WidgetTester tester) async { testWidgets('Flings don\'t stutter', (WidgetTester tester) async {
await tester.pumpWidget(new ListView.builder( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return new Container(height: kHeight); return new Container(height: kHeight);
}, },
)); ),
),
);
double getCurrentOffset() { double getCurrentOffset() {
return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels; return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels;
......
...@@ -11,15 +11,18 @@ final Key blockKey = const Key('test'); ...@@ -11,15 +11,18 @@ final Key blockKey = const Key('test');
void main() { void main() {
testWidgets('Cannot scroll a non-overflowing block', (WidgetTester tester) async { testWidgets('Cannot scroll a non-overflowing block', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
key: blockKey, key: blockKey,
children: <Widget>[ children: <Widget>[
new Container( new Container(
height: 200.0, // less than 600, the height of the test area height: 200.0, // less than 600, the height of the test area
child: const Text('Hello') child: const Text('Hello'),
) ),
] ],
) ),
),
); );
final Offset middleOfContainer = tester.getCenter(find.text('Hello')); final Offset middleOfContainer = tester.getCenter(find.text('Hello'));
...@@ -36,15 +39,18 @@ void main() { ...@@ -36,15 +39,18 @@ void main() {
testWidgets('Can scroll an overflowing block', (WidgetTester tester) async { testWidgets('Can scroll an overflowing block', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
key: blockKey, key: blockKey,
children: <Widget>[ children: <Widget>[
new Container( new Container(
height: 2000.0, // more than 600, the height of the test area height: 2000.0, // more than 600, the height of the test area
child: const Text('Hello') child: const Text('Hello'),
) ),
] ],
) ),
),
); );
final Offset middleOfContainer = tester.getCenter(find.text('Hello')); final Offset middleOfContainer = tester.getCenter(find.text('Hello'));
...@@ -67,7 +73,9 @@ void main() { ...@@ -67,7 +73,9 @@ void main() {
int second = 0; int second = 0;
Widget buildBlock({ bool reverse: false }) { Widget buildBlock({ bool reverse: false }) {
return new ListView( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
key: new UniqueKey(), key: new UniqueKey(),
reverse: reverse, reverse: reverse,
children: <Widget>[ children: <Widget>[
...@@ -83,9 +91,10 @@ void main() { ...@@ -83,9 +91,10 @@ void main() {
child: new Container( child: new Container(
height: 350.0, // more than half the height of the test area height: 350.0, // more than half the height of the test area
color: const Color(0xFF0000FF), color: const Color(0xFF0000FF),
) ),
) ),
] ],
),
); );
} }
...@@ -107,9 +116,12 @@ void main() { ...@@ -107,9 +116,12 @@ void main() {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
Widget buildBlock() { Widget buildBlock() {
return new ListView( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[const Text("A"), const Text("B"), const Text("C")] children: <Widget>[const Text("A"), const Text("B"), const Text("C")],
),
); );
} }
await tester.pumpWidget(buildBlock()); await tester.pumpWidget(buildBlock());
...@@ -125,13 +137,18 @@ void main() { ...@@ -125,13 +137,18 @@ void main() {
new Container(), new Container(),
]); ]);
await tester.pumpWidget(new CustomScrollView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
delegate: delegate, delegate: delegate,
), ),
], ],
)); ),
),
);
final SliverMultiBoxAdaptorElement element = tester.element(find.byType(SliverList)); final SliverMultiBoxAdaptorElement element = tester.element(find.byType(SliverList));
...@@ -154,7 +171,9 @@ void main() { ...@@ -154,7 +171,9 @@ void main() {
// The overall height of the frame is (as ever) 600 // The overall height of the frame is (as ever) 600
Widget buildFrame() { Widget buildFrame() {
return new Column( return new Directionality(
textDirection: TextDirection.ltr,
child: new Column(
children: <Widget>[ children: <Widget>[
new Flexible( new Flexible(
// The overall height of the ListView's contents is 500 // The overall height of the ListView's contents is 500
...@@ -190,6 +209,7 @@ void main() { ...@@ -190,6 +209,7 @@ void main() {
), ),
), ),
], ],
),
); );
} }
......
...@@ -8,7 +8,10 @@ import 'package:flutter/rendering.dart'; ...@@ -8,7 +8,10 @@ import 'package:flutter/rendering.dart';
void main() { void main() {
testWidgets('Nested ListView with shrinkWrap', (WidgetTester tester) async { testWidgets('Nested ListView with shrinkWrap', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
shrinkWrap: true, shrinkWrap: true,
children: <Widget>[ children: <Widget>[
new ListView( new ListView(
...@@ -28,98 +31,150 @@ void main() { ...@@ -28,98 +31,150 @@ void main() {
], ],
), ),
], ],
)); ),
),
);
}); });
testWidgets('Underflowing ListView should relayout for additional children', (WidgetTester tester) async { testWidgets('Underflowing ListView should relayout for additional children', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/5950 // Regression test for https://github.com/flutter/flutter/issues/5950
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
], ],
)); ),
),
);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
const SizedBox(height: 200.0, child: const Text('200')), const SizedBox(height: 200.0, child: const Text('200')),
], ],
)); ),
),
);
expect(find.text('200'), findsOneWidget); expect(find.text('200'), findsOneWidget);
}); });
testWidgets('Underflowing ListView contentExtent should track additional children', (WidgetTester tester) async { testWidgets('Underflowing ListView contentExtent should track additional children', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
], ],
)); ),
),
);
final RenderSliverList list = tester.renderObject(find.byType(SliverList)); final RenderSliverList list = tester.renderObject(find.byType(SliverList));
expect(list.geometry.scrollExtent, equals(100.0)); expect(list.geometry.scrollExtent, equals(100.0));
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
const SizedBox(height: 200.0, child: const Text('200')), const SizedBox(height: 200.0, child: const Text('200')),
], ],
)); ),
),
);
expect(list.geometry.scrollExtent, equals(300.0)); expect(list.geometry.scrollExtent, equals(300.0));
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[] children: <Widget>[]
)); ),
),
);
expect(list.geometry.scrollExtent, equals(0.0)); expect(list.geometry.scrollExtent, equals(0.0));
}); });
testWidgets('Overflowing ListView should relayout for missing children', (WidgetTester tester) async { testWidgets('Overflowing ListView should relayout for missing children', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 300.0, child: const Text('300')), const SizedBox(height: 300.0, child: const Text('300')),
const SizedBox(height: 400.0, child: const Text('400')), const SizedBox(height: 400.0, child: const Text('400')),
], ],
)); ),
),
);
expect(find.text('300'), findsOneWidget); expect(find.text('300'), findsOneWidget);
expect(find.text('400'), findsOneWidget); expect(find.text('400'), findsOneWidget);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 300.0, child: const Text('300')), const SizedBox(height: 300.0, child: const Text('300')),
], ],
)); ),
),
);
expect(find.text('300'), findsOneWidget); expect(find.text('300'), findsOneWidget);
expect(find.text('400'), findsNothing); expect(find.text('400'), findsNothing);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[] children: <Widget>[]
)); ),
),
);
expect(find.text('300'), findsNothing); expect(find.text('300'), findsNothing);
expect(find.text('400'), findsNothing); expect(find.text('400'), findsNothing);
}); });
testWidgets('Overflowing ListView should not relayout for additional children', (WidgetTester tester) async { testWidgets('Overflowing ListView should not relayout for additional children', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 300.0, child: const Text('300')), const SizedBox(height: 300.0, child: const Text('300')),
const SizedBox(height: 400.0, child: const Text('400')), const SizedBox(height: 400.0, child: const Text('400')),
], ],
)); ),
),
);
expect(find.text('300'), findsOneWidget); expect(find.text('300'), findsOneWidget);
expect(find.text('400'), findsOneWidget); expect(find.text('400'), findsOneWidget);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 300.0, child: const Text('300')), const SizedBox(height: 300.0, child: const Text('300')),
const SizedBox(height: 400.0, child: const Text('400')), const SizedBox(height: 400.0, child: const Text('400')),
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
], ],
)); ),
),
);
expect(find.text('300'), findsOneWidget); expect(find.text('300'), findsOneWidget);
expect(find.text('400'), findsOneWidget); expect(find.text('400'), findsOneWidget);
...@@ -132,22 +187,32 @@ void main() { ...@@ -132,22 +187,32 @@ void main() {
// When children are added that cause it to overflow, scrolling should // When children are added that cause it to overflow, scrolling should
// be enabled. // be enabled.
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
], ],
)); ),
),
);
final ScrollableState scrollable = tester.state(find.byType(Scrollable)); final ScrollableState scrollable = tester.state(find.byType(Scrollable));
expect(scrollable.position.maxScrollExtent, 0.0); expect(scrollable.position.maxScrollExtent, 0.0);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
const SizedBox(height: 100.0, child: const Text('100')), const SizedBox(height: 100.0, child: const Text('100')),
const SizedBox(height: 200.0, child: const Text('200')), const SizedBox(height: 200.0, child: const Text('200')),
const SizedBox(height: 400.0, child: const Text('400')), const SizedBox(height: 400.0, child: const Text('400')),
], ],
)); ),
),
);
expect(scrollable.position.maxScrollExtent, 100.0); expect(scrollable.position.maxScrollExtent, 100.0);
}); });
......
...@@ -18,12 +18,21 @@ class TestSliverChildListDelegate extends SliverChildListDelegate { ...@@ -18,12 +18,21 @@ class TestSliverChildListDelegate extends SliverChildListDelegate {
void main() { void main() {
testWidgets('ListView default control', (WidgetTester tester) async { testWidgets('ListView default control', (WidgetTester tester) async {
await tester.pumpWidget(new Center(child: new ListView(itemExtent: 100.0))); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new ListView(itemExtent: 100.0),
),
),
);
}); });
testWidgets('ListView itemExtent control test', (WidgetTester tester) async { testWidgets('ListView itemExtent control test', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 200.0, itemExtent: 200.0,
children: new List<Widget>.generate(20, (int i) { children: new List<Widget>.generate(20, (int i) {
return new Container( return new Container(
...@@ -31,6 +40,7 @@ void main() { ...@@ -31,6 +40,7 @@ void main() {
); );
}), }),
), ),
),
); );
final RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).first); final RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).first);
...@@ -68,7 +78,9 @@ void main() { ...@@ -68,7 +78,9 @@ void main() {
final List<int> log = <int>[]; final List<int> log = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 200.0, itemExtent: 200.0,
children: new List<Widget>.generate(20, (int i) { children: new List<Widget>.generate(20, (int i) {
return new Builder( return new Builder(
...@@ -81,6 +93,7 @@ void main() { ...@@ -81,6 +93,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(log, equals(<int>[0, 1, 2])); expect(log, equals(<int>[0, 1, 2]));
...@@ -107,9 +120,12 @@ void main() { ...@@ -107,9 +120,12 @@ void main() {
testWidgets('ListView can build out of underflow', (WidgetTester tester) async { testWidgets('ListView can build out of underflow', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 100.0, itemExtent: 100.0,
), ),
),
); );
expect(find.text('0'), findsNothing); expect(find.text('0'), findsNothing);
...@@ -120,7 +136,9 @@ void main() { ...@@ -120,7 +136,9 @@ void main() {
expect(find.text('5'), findsNothing); expect(find.text('5'), findsNothing);
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 100.0, itemExtent: 100.0,
children: new List<Widget>.generate(2, (int i) { children: new List<Widget>.generate(2, (int i) {
return new Container( return new Container(
...@@ -128,6 +146,7 @@ void main() { ...@@ -128,6 +146,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
...@@ -138,7 +157,9 @@ void main() { ...@@ -138,7 +157,9 @@ void main() {
expect(find.text('5'), findsNothing); expect(find.text('5'), findsNothing);
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 100.0, itemExtent: 100.0,
children: new List<Widget>.generate(5, (int i) { children: new List<Widget>.generate(5, (int i) {
return new Container( return new Container(
...@@ -146,6 +167,7 @@ void main() { ...@@ -146,6 +167,7 @@ void main() {
); );
}), }),
), ),
),
); );
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
...@@ -158,7 +180,9 @@ void main() { ...@@ -158,7 +180,9 @@ void main() {
testWidgets('ListView can build out of overflow padding', (WidgetTester tester) async { testWidgets('ListView can build out of overflow padding', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new Center( new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new SizedBox( child: new SizedBox(
width: 0.0, width: 0.0,
height: 0.0, height: 0.0,
...@@ -170,13 +194,16 @@ void main() { ...@@ -170,13 +194,16 @@ void main() {
), ),
), ),
), ),
),
); );
expect(find.text('padded'), findsOneWidget); expect(find.text('padded'), findsOneWidget);
}); });
testWidgets('ListView with itemExtent in unbounded context', (WidgetTester tester) async { testWidgets('ListView with itemExtent in unbounded context', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new SingleChildScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new SingleChildScrollView(
child: new ListView( child: new ListView(
itemExtent: 100.0, itemExtent: 100.0,
shrinkWrap: true, shrinkWrap: true,
...@@ -187,6 +214,7 @@ void main() { ...@@ -187,6 +214,7 @@ void main() {
}), }),
), ),
), ),
),
); );
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
...@@ -203,20 +231,26 @@ void main() { ...@@ -203,20 +231,26 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
new ListView.custom( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.custom(
itemExtent: 110.0, itemExtent: 110.0,
childrenDelegate: delegate, childrenDelegate: delegate,
), ),
),
); );
expect(delegate.log, equals(<String>['didFinishLayout firstIndex=0 lastIndex=5'])); expect(delegate.log, equals(<String>['didFinishLayout firstIndex=0 lastIndex=5']));
delegate.log.clear(); delegate.log.clear();
await tester.pumpWidget( await tester.pumpWidget(
new ListView.custom( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.custom(
itemExtent: 210.0, itemExtent: 210.0,
childrenDelegate: delegate, childrenDelegate: delegate,
), ),
),
); );
expect(delegate.log, equals(<String>['didFinishLayout firstIndex=0 lastIndex=2'])); expect(delegate.log, equals(<String>['didFinishLayout firstIndex=0 lastIndex=2']));
......
...@@ -8,7 +8,9 @@ import 'package:flutter/widgets.dart'; ...@@ -8,7 +8,9 @@ import 'package:flutter/widgets.dart';
const List<int> items = const <int>[0, 1, 2, 3, 4, 5]; const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
Widget buildFrame() { Widget buildFrame() {
return new ListView( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 290.0, itemExtent: 290.0,
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
children: items.map((int item) { children: items.map((int item) {
...@@ -16,6 +18,7 @@ Widget buildFrame() { ...@@ -16,6 +18,7 @@ Widget buildFrame() {
child: new Text('$item') child: new Text('$item')
); );
}).toList(), }).toList(),
),
); );
} }
...@@ -65,7 +68,9 @@ void main() { ...@@ -65,7 +68,9 @@ void main() {
testWidgets('Drag vertically', (WidgetTester tester) async { testWidgets('Drag vertically', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 290.0, itemExtent: 290.0,
padding: const EdgeInsets.only(top: 250.0), padding: const EdgeInsets.only(top: 250.0),
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
...@@ -75,6 +80,7 @@ void main() { ...@@ -75,6 +80,7 @@ void main() {
); );
}).toList(), }).toList(),
), ),
),
); );
await tester.pump(); await tester.pump();
......
...@@ -16,7 +16,9 @@ void main() { ...@@ -16,7 +16,9 @@ void main() {
// so if our widget is 100 pixels tall, it should fit exactly 6 times. // so if our widget is 100 pixels tall, it should fit exactly 6 times.
Widget builder() { Widget builder() {
return new FlipWidget( return new Directionality(
textDirection: TextDirection.ltr,
child: new FlipWidget(
left: new ListView.builder( left: new ListView.builder(
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
callbackTracker.add(index); callbackTracker.add(index);
...@@ -28,6 +30,7 @@ void main() { ...@@ -28,6 +30,7 @@ void main() {
}, },
), ),
right: const Text('Not Today'), right: const Text('Not Today'),
),
); );
} }
...@@ -68,12 +71,15 @@ void main() { ...@@ -68,12 +71,15 @@ void main() {
}; };
Widget builder() { Widget builder() {
return new FlipWidget( return new Directionality(
textDirection: TextDirection.ltr,
child: new FlipWidget(
left: new ListView.builder( left: new ListView.builder(
controller: new ScrollController(initialScrollOffset: 300.0), controller: new ScrollController(initialScrollOffset: 300.0),
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
), ),
right: const Text('Not Today'), right: const Text('Not Today'),
),
); );
} }
...@@ -173,8 +179,11 @@ void main() { ...@@ -173,8 +179,11 @@ void main() {
} }
Widget builder() { Widget builder() {
return new ListView.builder( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
),
); );
} }
...@@ -214,12 +223,15 @@ void main() { ...@@ -214,12 +223,15 @@ void main() {
); );
await tester.pumpWidget( await tester.pumpWidget(
new StatefulBuilder( new Directionality(
textDirection: TextDirection.ltr,
child: new StatefulBuilder(
builder: (BuildContext context, StateSetter setter) { builder: (BuildContext context, StateSetter setter) {
setState = setter; setState = setter;
return new Theme(data: themeData, child: viewport); return new Theme(data: themeData, child: viewport);
} },
) ),
),
); );
DecoratedBox widget = tester.firstWidget(find.byType(DecoratedBox)); DecoratedBox widget = tester.firstWidget(find.byType(DecoratedBox));
...@@ -249,10 +261,13 @@ void main() { ...@@ -249,10 +261,13 @@ void main() {
}; };
await tester.pumpWidget( await tester.pumpWidget(
new ListView.builder( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
padding: const EdgeInsets.fromLTRB(7.0, 3.0, 5.0, 11.0), padding: const EdgeInsets.fromLTRB(7.0, 3.0, 5.0, 11.0),
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
), ),
),
); );
final RenderBox firstBox = tester.renderObject(find.text('0')); final RenderBox firstBox = tester.renderObject(find.text('0'));
...@@ -262,14 +277,19 @@ void main() { ...@@ -262,14 +277,19 @@ void main() {
}); });
testWidgets('ListView underflow extents', (WidgetTester tester) async { testWidgets('ListView underflow extents', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
addAutomaticKeepAlives: false, addAutomaticKeepAlives: false,
children: <Widget>[ children: <Widget>[
new Container(height: 100.0), new Container(height: 100.0),
new Container(height: 100.0), new Container(height: 100.0),
new Container(height: 100.0), new Container(height: 100.0),
], ],
)); ),
),
);
final RenderSliverList list = tester.renderObject(find.byType(SliverList)); final RenderSliverList list = tester.renderObject(find.byType(SliverList));
...@@ -294,6 +314,7 @@ void main() { ...@@ -294,6 +314,7 @@ void main() {
' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
' │ crossAxisDirection: AxisDirection.right,\n'
' │ viewportMainAxisExtent: 600.0)\n' ' │ viewportMainAxisExtent: 600.0)\n'
' │ geometry: SliverGeometry(scrollExtent: 300.0, paintExtent: 300.0,\n' ' │ geometry: SliverGeometry(scrollExtent: 300.0, paintExtent: 300.0,\n'
' │ maxPaintExtent: 300.0)\n' ' │ maxPaintExtent: 300.0)\n'
...@@ -453,7 +474,7 @@ void main() { ...@@ -453,7 +474,7 @@ void main() {
' parentData: <none> (can use size)\n' ' parentData: <none> (can use size)\n'
' constraints: BoxConstraints(w=800.0, h=100.0)\n' ' constraints: BoxConstraints(w=800.0, h=100.0)\n'
' size: Size(800.0, 100.0)\n' ' size: Size(800.0, 100.0)\n'
' additionalConstraints: BoxConstraints(biggest)\n', ' additionalConstraints: BoxConstraints(biggest)\n'
), ),
); );
......
...@@ -21,8 +21,11 @@ Widget buildCard(BuildContext context, int index) { ...@@ -21,8 +21,11 @@ Widget buildCard(BuildContext context, int index) {
} }
Widget buildFrame() { Widget buildFrame() {
return new ListView.builder( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
itemBuilder: buildCard, itemBuilder: buildCard,
),
); );
} }
......
...@@ -10,10 +10,13 @@ void main() { ...@@ -10,10 +10,13 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/9506 // Regression test for https://github.com/flutter/flutter/issues/9506
Widget buildFrame(int itemCount) { Widget buildFrame(int itemCount) {
return new ListView.builder( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
itemExtent: 200.0, itemExtent: 200.0,
itemCount: itemCount, itemCount: itemCount,
itemBuilder: (BuildContext context, int index) => new Text('item $index'), itemBuilder: (BuildContext context, int index) => new Text('item $index'),
),
); );
} }
...@@ -34,7 +37,9 @@ void main() { ...@@ -34,7 +37,9 @@ void main() {
// Regression test for https://github.com/flutter/flutter/issues/9506 // Regression test for https://github.com/flutter/flutter/issues/9506
Widget buildFrame(int itemCount) { Widget buildFrame(int itemCount) {
return new ListView.builder( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView.builder(
itemCount: itemCount, itemCount: itemCount,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return new SizedBox( return new SizedBox(
...@@ -42,6 +47,7 @@ void main() { ...@@ -42,6 +47,7 @@ void main() {
child: new Text('item $index'), child: new Text('item $index'),
); );
}, },
),
); );
} }
......
...@@ -24,11 +24,14 @@ Future<Null> slowDrag(WidgetTester tester, Offset start, Offset offset) async { ...@@ -24,11 +24,14 @@ Future<Null> slowDrag(WidgetTester tester, Offset 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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)),
], ],
), ),
),
); );
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
...@@ -57,11 +60,14 @@ void main() { ...@@ -57,11 +60,14 @@ 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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)),
], ],
), ),
),
); );
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
...@@ -92,11 +98,14 @@ void main() { ...@@ -92,11 +98,14 @@ 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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)),
], ],
), ),
),
); );
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
final TestGesture gesture = await tester.startGesture(const Offset(300.0, 200.0)); final TestGesture gesture = await tester.startGesture(const Offset(300.0, 200.0));
...@@ -125,12 +134,15 @@ void main() { ...@@ -125,12 +134,15 @@ 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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), const SliverToBoxAdapter(child: const SizedBox(height: 20.0)),
], ],
), ),
),
); );
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0)); await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
...@@ -142,13 +154,16 @@ void main() { ...@@ -142,13 +154,16 @@ void main() {
testWidgets('up', (WidgetTester tester) async { testWidgets('up', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
reverse: true, reverse: true,
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), const SliverToBoxAdapter(child: const SizedBox(height: 20.0)),
], ],
), ),
),
); );
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0)); await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
...@@ -161,12 +176,15 @@ void main() { ...@@ -161,12 +176,15 @@ 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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(), physics: const AlwaysScrollableScrollPhysics(),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), const SliverToBoxAdapter(child: const SizedBox(height: 20.0)),
], ],
), ),
),
); );
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0)); await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
...@@ -180,7 +198,8 @@ void main() { ...@@ -180,7 +198,8 @@ void main() {
}); });
testWidgets('Overscroll horizontally', (WidgetTester tester) async { testWidgets('Overscroll horizontally', (WidgetTester tester) async {
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new CustomScrollView( child: new CustomScrollView(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
...@@ -189,7 +208,8 @@ void main() { ...@@ -189,7 +208,8 @@ void main() {
const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), const SliverToBoxAdapter(child: const SizedBox(height: 20.0)),
], ],
), ),
)); ),
);
final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0)); await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0));
expect(painter, paints..rotate(angle: math.PI / 2.0)..circle()..saveRestore()); expect(painter, paints..rotate(angle: math.PI / 2.0)..circle()..saveRestore());
...@@ -227,7 +247,8 @@ void main() { ...@@ -227,7 +247,8 @@ void main() {
testWidgets('Changing settings', (WidgetTester tester) async { testWidgets('Changing settings', (WidgetTester tester) async {
RenderObject painter; RenderObject painter;
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new ScrollConfiguration( child: new ScrollConfiguration(
behavior: new TestScrollBehavior1(), behavior: new TestScrollBehavior1(),
...@@ -240,14 +261,16 @@ void main() { ...@@ -240,14 +261,16 @@ void main() {
], ],
), ),
), ),
)); ),
);
painter = tester.renderObject(find.byType(CustomPaint)); painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0)); await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0));
expect(painter, paints..rotate(angle: math.PI / 2.0)..circle(color: const Color(0x0A00FF00))); expect(painter, paints..rotate(angle: math.PI / 2.0)..circle(color: const Color(0x0A00FF00)));
expect(painter, isNot(paints..circle()..circle())); expect(painter, isNot(paints..circle()..circle()));
await tester.pumpAndSettle(const Duration(seconds: 1)); await tester.pumpAndSettle(const Duration(seconds: 1));
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new ScrollConfiguration( child: new ScrollConfiguration(
behavior: new TestScrollBehavior2(), behavior: new TestScrollBehavior2(),
...@@ -259,7 +282,8 @@ void main() { ...@@ -259,7 +282,8 @@ void main() {
], ],
), ),
), ),
)); ),
);
painter = tester.renderObject(find.byType(CustomPaint)); painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0)); await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0));
expect(painter, paints..rotate(angle: math.PI / 2.0)..circle(color: const Color(0x0A0000FF))..saveRestore()); expect(painter, paints..rotate(angle: math.PI / 2.0)..circle(color: const Color(0x0A0000FF))..saveRestore());
......
...@@ -30,7 +30,10 @@ class ThePositiveNumbers extends StatelessWidget { ...@@ -30,7 +30,10 @@ class ThePositiveNumbers extends StatelessWidget {
Future<Null> performTest(WidgetTester tester, bool maintainState) async { Future<Null> performTest(WidgetTester tester, bool maintainState) async {
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
await tester.pumpWidget(new Navigator( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Navigator(
key: navigatorKey, key: navigatorKey,
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
if (settings.name == '/') { if (settings.name == '/') {
...@@ -48,7 +51,9 @@ Future<Null> performTest(WidgetTester tester, bool maintainState) async { ...@@ -48,7 +51,9 @@ Future<Null> performTest(WidgetTester tester, bool maintainState) async {
} }
return null; return null;
} }
)); ),
),
);
// we're 600 pixels high, each item is 100 pixels high, scroll position is // we're 600 pixels high, each item is 100 pixels high, scroll position is
// 110.0, so we should have 7 items, 1..7. // 110.0, so we should have 7 items, 1..7.
......
...@@ -195,7 +195,10 @@ void main() { ...@@ -195,7 +195,10 @@ void main() {
final StateMarkerState keyState = key.currentState; final StateMarkerState keyState = key.currentState;
keyState.marker = "marked"; keyState.marker = "marked";
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 100.0, itemExtent: 100.0,
children: <Widget>[ children: <Widget>[
new Container( new Container(
...@@ -204,7 +207,9 @@ void main() { ...@@ -204,7 +207,9 @@ void main() {
child: new StateMarker(key: key), child: new StateMarker(key: key),
), ),
], ],
)); ),
),
);
expect(key.currentState, equals(keyState)); expect(key.currentState, equals(keyState));
expect(keyState.marker, equals("marked")); expect(keyState.marker, equals("marked"));
......
...@@ -11,15 +11,20 @@ void main() { ...@@ -11,15 +11,20 @@ void main() {
testWidgets('ScrollController control test', (WidgetTester tester) async { testWidgets('ScrollController control test', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: kStates.map<Widget>((String state) { children: kStates.map<Widget>((String state) {
return new Container( return new Container(
height: 200.0, height: 200.0,
child: new Text(state), child: new Text(state),
); );
}).toList() }).toList(),
)); ),
),
);
double realOffset() { double realOffset() {
return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels; return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels;
...@@ -44,7 +49,10 @@ void main() { ...@@ -44,7 +49,10 @@ void main() {
expect(controller.offset, equals(326.0)); expect(controller.offset, equals(326.0));
expect(realOffset(), equals(controller.offset)); expect(realOffset(), equals(controller.offset));
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
key: const Key('second'), key: const Key('second'),
controller: controller, controller: controller,
children: kStates.map<Widget>((String state) { children: kStates.map<Widget>((String state) {
...@@ -52,8 +60,10 @@ void main() { ...@@ -52,8 +60,10 @@ void main() {
height: 200.0, height: 200.0,
child: new Text(state), child: new Text(state),
); );
}).toList() }).toList(),
)); ),
),
);
expect(controller.offset, equals(0.0)); expect(controller.offset, equals(0.0));
expect(realOffset(), equals(controller.offset)); expect(realOffset(), equals(controller.offset));
...@@ -65,7 +75,10 @@ void main() { ...@@ -65,7 +75,10 @@ void main() {
final ScrollController controller2 = new ScrollController(); final ScrollController controller2 = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
key: const Key('second'), key: const Key('second'),
controller: controller2, controller: controller2,
children: kStates.map<Widget>((String state) { children: kStates.map<Widget>((String state) {
...@@ -73,8 +86,10 @@ void main() { ...@@ -73,8 +86,10 @@ void main() {
height: 200.0, height: 200.0,
child: new Text(state), child: new Text(state),
); );
}).toList() }).toList(),
)); ),
),
);
expect(() => controller.offset, throwsAssertionError); expect(() => controller.offset, throwsAssertionError);
expect(controller2.offset, equals(653.0)); expect(controller2.offset, equals(653.0));
...@@ -83,7 +98,10 @@ void main() { ...@@ -83,7 +98,10 @@ void main() {
expect(() => controller.jumpTo(120.0), throwsAssertionError); expect(() => controller.jumpTo(120.0), throwsAssertionError);
expect(() => controller.animateTo(132.0, duration: const Duration(milliseconds: 300), curve: Curves.ease), throwsAssertionError); expect(() => controller.animateTo(132.0, duration: const Duration(milliseconds: 300), curve: Curves.ease), throwsAssertionError);
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
key: const Key('second'), key: const Key('second'),
controller: controller2, controller: controller2,
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
...@@ -92,8 +110,10 @@ void main() { ...@@ -92,8 +110,10 @@ void main() {
height: 200.0, height: 200.0,
child: new Text(state), child: new Text(state),
); );
}).toList() }).toList(),
)); ),
),
);
expect(controller2.offset, equals(653.0)); expect(controller2.offset, equals(653.0));
expect(realOffset(), equals(controller2.offset)); expect(realOffset(), equals(controller2.offset));
...@@ -114,11 +134,16 @@ void main() { ...@@ -114,11 +134,16 @@ void main() {
initialScrollOffset: 209.0, initialScrollOffset: 209.0,
); );
await tester.pumpWidget(new GridView.count( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.count(
crossAxisCount: 4, crossAxisCount: 4,
controller: controller, controller: controller,
children: kStates.map<Widget>((String state) => new Text(state)).toList(), children: kStates.map<Widget>((String state) => new Text(state)).toList(),
)); ),
),
);
double realOffset() { double realOffset() {
return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels; return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels;
...@@ -134,11 +159,16 @@ void main() { ...@@ -134,11 +159,16 @@ void main() {
expect(controller.offset, equals(105.0)); expect(controller.offset, equals(105.0));
expect(realOffset(), equals(controller.offset)); expect(realOffset(), equals(controller.offset));
await tester.pumpWidget(new GridView.count( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.count(
crossAxisCount: 2, crossAxisCount: 2,
controller: controller, controller: controller,
children: kStates.map<Widget>((String state) => new Text(state)).toList(), children: kStates.map<Widget>((String state) => new Text(state)).toList(),
)); ),
),
);
expect(controller.offset, equals(105.0)); expect(controller.offset, equals(105.0));
expect(realOffset(), equals(controller.offset)); expect(realOffset(), equals(controller.offset));
...@@ -147,10 +177,15 @@ void main() { ...@@ -147,10 +177,15 @@ void main() {
testWidgets('DrivenScrollActivity ending after dispose', (WidgetTester tester) async { testWidgets('DrivenScrollActivity ending after dispose', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: <Widget>[ new Container(height: 200000.0) ], children: <Widget>[ new Container(height: 200000.0) ],
)); ),
),
);
controller.animateTo(1000.0, duration: const Duration(seconds: 1), curve: Curves.linear); controller.animateTo(1000.0, duration: const Duration(seconds: 1), curve: Curves.linear);
...@@ -168,7 +203,10 @@ void main() { ...@@ -168,7 +203,10 @@ void main() {
testWidgets('Read operations on ScrollControllers with more than one position fail', (WidgetTester tester) async { testWidgets('Read operations on ScrollControllers with more than one position fail', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
new Container( new Container(
constraints: const BoxConstraints(maxHeight: 500.0), constraints: const BoxConstraints(maxHeight: 500.0),
...@@ -189,7 +227,9 @@ void main() { ...@@ -189,7 +227,9 @@ void main() {
), ),
), ),
], ],
)); ),
),
);
expect(() => controller.offset, throwsAssertionError); expect(() => controller.offset, throwsAssertionError);
expect(() => controller.position, throwsAssertionError); expect(() => controller.position, throwsAssertionError);
...@@ -203,7 +243,10 @@ void main() { ...@@ -203,7 +243,10 @@ void main() {
testWidgets('Write operations on ScrollControllers with more than one position do not throw', (WidgetTester tester) async { testWidgets('Write operations on ScrollControllers with more than one position do not throw', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
new Container( new Container(
constraints: const BoxConstraints(maxHeight: 500.0), constraints: const BoxConstraints(maxHeight: 500.0),
...@@ -224,7 +267,9 @@ void main() { ...@@ -224,7 +267,9 @@ void main() {
), ),
), ),
], ],
)); ),
),
);
controller.jumpTo(1.0); controller.jumpTo(1.0);
controller.animateTo(1.0, duration: const Duration(seconds: 1), curve: Curves.linear); controller.animateTo(1.0, duration: const Duration(seconds: 1), curve: Curves.linear);
...@@ -240,12 +285,17 @@ void main() { ...@@ -240,12 +285,17 @@ void main() {
log.add(controller.offset); log.add(controller.offset);
}); });
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: controller, controller: controller,
children: kStates.map<Widget>((String state) { children: kStates.map<Widget>((String state) {
return new Container(height: 200.0, child: new Text(state)); return new Container(height: 200.0, child: new Text(state));
}).toList(), }).toList(),
)); ),
),
);
expect(log, isEmpty); expect(log, isEmpty);
...@@ -264,7 +314,9 @@ void main() { ...@@ -264,7 +314,9 @@ void main() {
final PageStorageBucket bucket = new PageStorageBucket(); final PageStorageBucket bucket = new PageStorageBucket();
Widget buildFrame(ScrollController controller) { Widget buildFrame(ScrollController controller) {
return new PageStorage( return new Directionality(
textDirection: TextDirection.ltr,
child: new PageStorage(
bucket: bucket, bucket: bucket,
child: new KeyedSubtree( child: new KeyedSubtree(
key: const PageStorageKey<String>('ListView'), key: const PageStorageKey<String>('ListView'),
...@@ -276,6 +328,7 @@ void main() { ...@@ -276,6 +328,7 @@ void main() {
}).toList(), }).toList(),
), ),
), ),
),
); );
} }
......
...@@ -7,11 +7,16 @@ import 'package:flutter/widgets.dart'; ...@@ -7,11 +7,16 @@ import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('Scroll flings twice in a row does not crash', (WidgetTester tester) async { testWidgets('Scroll flings twice in a row does not crash', (WidgetTester tester) async {
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: <Widget>[ children: <Widget>[
new Container(height: 100000.0) new Container(height: 100000.0)
] ],
)); ),
),
);
final ScrollableState scrollable = final ScrollableState scrollable =
tester.state<ScrollableState>(find.byType(Scrollable)); tester.state<ScrollableState>(find.byType(Scrollable));
......
...@@ -11,7 +11,10 @@ void main() { ...@@ -11,7 +11,10 @@ void main() {
testWidgets('ListView control test', (WidgetTester tester) async { testWidgets('ListView control test', (WidgetTester tester) async {
final List<String> log = <String>[]; final List<String> log = <String>[];
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: kStates.map<Widget>((String state) { children: kStates.map<Widget>((String state) {
return new GestureDetector( return new GestureDetector(
onTap: () { onTap: () {
...@@ -23,8 +26,10 @@ void main() { ...@@ -23,8 +26,10 @@ void main() {
child: new Text(state), child: new Text(state),
), ),
); );
}).toList() }).toList(),
)); ),
),
);
await tester.tap(find.text('Alabama')); await tester.tap(find.text('Alabama'));
expect(log, equals(<String>['Alabama'])); expect(log, equals(<String>['Alabama']));
...@@ -45,14 +50,17 @@ void main() { ...@@ -45,14 +50,17 @@ void main() {
testWidgets('ListView restart ballistic activity out of range', (WidgetTester tester) async { testWidgets('ListView restart ballistic activity out of range', (WidgetTester tester) async {
Widget buildListView(int n) { Widget buildListView(int n) {
return new ListView( return new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: kStates.take(n).map<Widget>((String state) { children: kStates.take(n).map<Widget>((String state) {
return new Container( return new Container(
height: 200.0, height: 200.0,
color: const Color(0xFF0000FF), color: const Color(0xFF0000FF),
child: new Text(state), child: new Text(state),
); );
}).toList() }).toList(),
),
); );
} }
...@@ -72,7 +80,10 @@ void main() { ...@@ -72,7 +80,10 @@ void main() {
testWidgets('CustomScrollView control test', (WidgetTester tester) async { testWidgets('CustomScrollView control test', (WidgetTester tester) async {
final List<String> log = <String>[]; final List<String> log = <String>[];
await tester.pumpWidget(new CustomScrollView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
delegate: new SliverChildListDelegate( delegate: new SliverChildListDelegate(
...@@ -91,7 +102,9 @@ void main() { ...@@ -91,7 +102,9 @@ void main() {
), ),
), ),
], ],
)); ),
),
);
await tester.tap(find.text('Alabama')); await tester.tap(find.text('Alabama'));
expect(log, equals(<String>['Alabama'])); expect(log, equals(<String>['Alabama']));
...@@ -114,7 +127,10 @@ void main() { ...@@ -114,7 +127,10 @@ void main() {
final List<Type> log = <Type>[]; final List<Type> log = <Type>[];
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new NotificationListener<ScrollNotification>( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) { onNotification: (ScrollNotification notification) {
log.add(notification.runtimeType); log.add(notification.runtimeType);
return false; return false;
...@@ -128,7 +144,9 @@ void main() { ...@@ -128,7 +144,9 @@ void main() {
); );
}).toList(), }).toList(),
), ),
)); ),
),
);
expect(log, isEmpty); expect(log, isEmpty);
...@@ -226,30 +244,45 @@ void main() { ...@@ -226,30 +244,45 @@ void main() {
testWidgets('CustomScrollView sets PrimaryScrollController when primary', (WidgetTester tester) async { testWidgets('CustomScrollView sets PrimaryScrollController when primary', (WidgetTester tester) async {
final ScrollController primaryScrollController = new ScrollController(); final ScrollController primaryScrollController = new ScrollController();
await tester.pumpWidget(new PrimaryScrollController( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new PrimaryScrollController(
controller: primaryScrollController, controller: primaryScrollController,
child: new CustomScrollView(primary: true), child: new CustomScrollView(primary: true),
)); ),
),
);
final Scrollable scrollable = tester.widget(find.byType(Scrollable)); final Scrollable scrollable = tester.widget(find.byType(Scrollable));
expect(scrollable.controller, primaryScrollController); expect(scrollable.controller, primaryScrollController);
}); });
testWidgets('ListView sets PrimaryScrollController when primary', (WidgetTester tester) async { testWidgets('ListView sets PrimaryScrollController when primary', (WidgetTester tester) async {
final ScrollController primaryScrollController = new ScrollController(); final ScrollController primaryScrollController = new ScrollController();
await tester.pumpWidget(new PrimaryScrollController( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new PrimaryScrollController(
controller: primaryScrollController, controller: primaryScrollController,
child: new ListView(primary: true), child: new ListView(primary: true),
)); ),
),
);
final Scrollable scrollable = tester.widget(find.byType(Scrollable)); final Scrollable scrollable = tester.widget(find.byType(Scrollable));
expect(scrollable.controller, primaryScrollController); expect(scrollable.controller, primaryScrollController);
}); });
testWidgets('GridView sets PrimaryScrollController when primary', (WidgetTester tester) async { testWidgets('GridView sets PrimaryScrollController when primary', (WidgetTester tester) async {
final ScrollController primaryScrollController = new ScrollController(); final ScrollController primaryScrollController = new ScrollController();
await tester.pumpWidget(new PrimaryScrollController( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new PrimaryScrollController(
controller: primaryScrollController, controller: primaryScrollController,
child: new GridView.count(primary: true, crossAxisCount: 1), child: new GridView.count(primary: true, crossAxisCount: 1),
)); ),
),
);
final Scrollable scrollable = tester.widget(find.byType(Scrollable)); final Scrollable scrollable = tester.widget(find.byType(Scrollable));
expect(scrollable.controller, primaryScrollController); expect(scrollable.controller, primaryScrollController);
}); });
...@@ -257,7 +290,10 @@ void main() { ...@@ -257,7 +290,10 @@ void main() {
testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async { testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async {
const Key innerKey = const Key('inner'); const Key innerKey = const Key('inner');
final ScrollController primaryScrollController = new ScrollController(); final ScrollController primaryScrollController = new ScrollController();
await tester.pumpWidget(new PrimaryScrollController( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new PrimaryScrollController(
controller: primaryScrollController, controller: primaryScrollController,
child: new ListView( child: new ListView(
primary: true, primary: true,
...@@ -268,7 +304,9 @@ void main() { ...@@ -268,7 +304,9 @@ void main() {
), ),
], ],
), ),
)); ),
),
);
final Scrollable innerScrollable = tester.widget( final Scrollable innerScrollable = tester.widget(
find.descendant( find.descendant(
...@@ -302,13 +340,16 @@ void main() { ...@@ -302,13 +340,16 @@ void main() {
testWidgets('primary:true leads to scrolling', (WidgetTester tester) async { testWidgets('primary:true leads to scrolling', (WidgetTester tester) async {
bool scrolled = false; bool scrolled = false;
await tester.pumpWidget( await tester.pumpWidget(
new NotificationListener<OverscrollNotification>( new Directionality(
textDirection: TextDirection.ltr,
child: new NotificationListener<OverscrollNotification>(
onNotification: (OverscrollNotification message) { scrolled = true; return false; }, onNotification: (OverscrollNotification message) { scrolled = true; return false; },
child: new ListView( child: new ListView(
primary: true, primary: true,
children: <Widget>[], children: <Widget>[],
), ),
), ),
),
); );
await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0)); await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
expect(scrolled, isTrue); expect(scrolled, isTrue);
...@@ -317,13 +358,16 @@ void main() { ...@@ -317,13 +358,16 @@ void main() {
testWidgets('primary:false leads to no scrolling', (WidgetTester tester) async { testWidgets('primary:false leads to no scrolling', (WidgetTester tester) async {
bool scrolled = false; bool scrolled = false;
await tester.pumpWidget( await tester.pumpWidget(
new NotificationListener<OverscrollNotification>( new Directionality(
textDirection: TextDirection.ltr,
child: new NotificationListener<OverscrollNotification>(
onNotification: (OverscrollNotification message) { scrolled = true; return false; }, onNotification: (OverscrollNotification message) { scrolled = true; return false; },
child: new ListView( child: new ListView(
primary: false, primary: false,
children: <Widget>[], children: <Widget>[],
), ),
), ),
),
); );
await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0)); await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
expect(scrolled, isFalse); expect(scrolled, isFalse);
...@@ -332,7 +376,9 @@ void main() { ...@@ -332,7 +376,9 @@ void main() {
testWidgets('physics:AlwaysScrollableScrollPhysics actually overrides primary:false default behaviour', (WidgetTester tester) async { testWidgets('physics:AlwaysScrollableScrollPhysics actually overrides primary:false default behaviour', (WidgetTester tester) async {
bool scrolled = false; bool scrolled = false;
await tester.pumpWidget( await tester.pumpWidget(
new NotificationListener<OverscrollNotification>( new Directionality(
textDirection: TextDirection.ltr,
child: new NotificationListener<OverscrollNotification>(
onNotification: (OverscrollNotification message) { scrolled = true; return false; }, onNotification: (OverscrollNotification message) { scrolled = true; return false; },
child: new ListView( child: new ListView(
primary: false, primary: false,
...@@ -340,6 +386,7 @@ void main() { ...@@ -340,6 +386,7 @@ void main() {
children: <Widget>[], children: <Widget>[],
), ),
), ),
),
); );
await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0)); await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
expect(scrolled, isTrue); expect(scrolled, isTrue);
...@@ -348,7 +395,9 @@ void main() { ...@@ -348,7 +395,9 @@ void main() {
testWidgets('physics:ScrollPhysics actually overrides primary:true default behaviour', (WidgetTester tester) async { testWidgets('physics:ScrollPhysics actually overrides primary:true default behaviour', (WidgetTester tester) async {
bool scrolled = false; bool scrolled = false;
await tester.pumpWidget( await tester.pumpWidget(
new NotificationListener<OverscrollNotification>( new Directionality(
textDirection: TextDirection.ltr,
child: new NotificationListener<OverscrollNotification>(
onNotification: (OverscrollNotification message) { scrolled = true; return false; }, onNotification: (OverscrollNotification message) { scrolled = true; return false; },
child: new ListView( child: new ListView(
primary: true, primary: true,
...@@ -356,6 +405,7 @@ void main() { ...@@ -356,6 +405,7 @@ void main() {
children: <Widget>[], children: <Widget>[],
), ),
), ),
),
); );
await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0)); await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
expect(scrolled, isFalse); expect(scrolled, isFalse);
......
...@@ -12,10 +12,15 @@ void main() { ...@@ -12,10 +12,15 @@ void main() {
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
textWidgets.add(new Text('$i')); textWidgets.add(new Text('$i'));
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: textWidgets, children: textWidgets,
controller: controller, controller: controller,
)); ),
),
);
expectNoAnimation(); expectNoAnimation();
final double currentPosition = controller.position.pixels; final double currentPosition = controller.position.pixels;
...@@ -30,10 +35,15 @@ void main() { ...@@ -30,10 +35,15 @@ void main() {
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
textWidgets.add(new Text('$i')); textWidgets.add(new Text('$i'));
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: textWidgets, children: textWidgets,
controller: controller, controller: controller,
)); ),
),
);
expectNoAnimation(); expectNoAnimation();
...@@ -51,10 +61,15 @@ void main() { ...@@ -51,10 +61,15 @@ void main() {
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
textWidgets.add(new Text('$i')); textWidgets.add(new Text('$i'));
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
children: textWidgets, children: textWidgets,
controller: controller, controller: controller,
)); ),
),
);
expectNoAnimation(); expectNoAnimation();
......
...@@ -12,10 +12,15 @@ void main() { ...@@ -12,10 +12,15 @@ void main() {
final List<Widget> textWidgets = <Widget>[]; final List<Widget> textWidgets = <Widget>[];
for (int i = 0; i < 250; i++) for (int i = 0; i < 250; i++)
textWidgets.add(new Text('$i')); textWidgets.add(new Text('$i'));
await tester.pumpWidget(new FlipWidget( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new FlipWidget(
left: new ListView(children: textWidgets), left: new ListView(children: textWidgets),
right: new Container() right: new Container()
)); ),
),
);
await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 1000.0); await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 1000.0);
await tester.pump(); await tester.pump();
......
...@@ -61,7 +61,12 @@ void main() { ...@@ -61,7 +61,12 @@ void main() {
final List<Widget> textWidgets = <Widget>[]; final List<Widget> textWidgets = <Widget>[];
for (int i = 0; i < 250; i += 1) for (int i = 0; i < 250; i += 1)
textWidgets.add(new GestureDetector(onTap: () { log.add('tap $i'); }, child: new Text('$i', style: testFont))); textWidgets.add(new GestureDetector(onTap: () { log.add('tap $i'); }, child: new Text('$i', style: testFont)));
await tester.pumpWidget(new ListView(children: textWidgets)); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(children: textWidgets)
),
);
expect(log, equals(<String>[])); expect(log, equals(<String>[]));
await tester.tap(find.byType(Scrollable)); await tester.tap(find.byType(Scrollable));
...@@ -84,7 +89,12 @@ void main() { ...@@ -84,7 +89,12 @@ void main() {
final List<Widget> textWidgets = <Widget>[]; final List<Widget> textWidgets = <Widget>[];
for (int i = 0; i < 250; i += 1) for (int i = 0; i < 250; i += 1)
textWidgets.add(new GestureDetector(onTap: () { log.add('tap $i'); }, child: new Text('$i', style: testFont))); textWidgets.add(new GestureDetector(onTap: () { log.add('tap $i'); }, child: new Text('$i', style: testFont)));
await tester.pumpWidget(new ListView(children: textWidgets)); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(children: textWidgets)
),
);
expect(log, equals(<String>[])); expect(log, equals(<String>[]));
await tester.tap(find.byType(Scrollable)); await tester.tap(find.byType(Scrollable));
......
...@@ -8,18 +8,25 @@ import 'package:flutter/rendering.dart'; ...@@ -8,18 +8,25 @@ import 'package:flutter/rendering.dart';
void main() { void main() {
testWidgets('GridView default control', (WidgetTester tester) async { testWidgets('GridView default control', (WidgetTester tester) async {
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new GridView.count( child: new GridView.count(
crossAxisCount: 1, crossAxisCount: 1,
), ),
)); ),
),
);
}); });
// Tests https://github.com/flutter/flutter/issues/5522 // Tests https://github.com/flutter/flutter/issues/5522
testWidgets('GridView displays correct children with nonzero padding', (WidgetTester tester) async { testWidgets('GridView displays correct children with nonzero padding', (WidgetTester tester) async {
final EdgeInsets padding = const EdgeInsets.fromLTRB(0.0, 100.0, 0.0, 0.0); final EdgeInsets padding = const EdgeInsets.fromLTRB(0.0, 100.0, 0.0, 0.0);
final Widget testWidget = new Align( final Widget testWidget = new Directionality(
textDirection: TextDirection.ltr,
child: new Align(
child: new SizedBox( child: new SizedBox(
height: 800.0, height: 800.0,
width: 300.0, // forces the grid children to be 300..300 width: 300.0, // forces the grid children to be 300..300
...@@ -31,6 +38,7 @@ void main() { ...@@ -31,6 +38,7 @@ void main() {
}).toList(), }).toList(),
), ),
), ),
),
); );
await tester.pumpWidget(testWidget); await tester.pumpWidget(testWidget);
...@@ -72,7 +80,9 @@ void main() { ...@@ -72,7 +80,9 @@ void main() {
testWidgets('GridView.count() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async { testWidgets('GridView.count() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/9506 // Regression test for https://github.com/flutter/flutter/issues/9506
Widget buildFrame(int itemCount) { Widget buildFrame(int itemCount) {
return new GridView.count( return new Directionality(
textDirection: TextDirection.ltr,
child: new GridView.count(
crossAxisCount: itemCount, crossAxisCount: itemCount,
children: new List<Widget>.generate(itemCount, (int index) { children: new List<Widget>.generate(itemCount, (int index) {
return new SizedBox( return new SizedBox(
...@@ -80,6 +90,7 @@ void main() { ...@@ -80,6 +90,7 @@ void main() {
child: new Text('item $index'), child: new Text('item $index'),
); );
}), }),
),
); );
} }
......
...@@ -11,7 +11,8 @@ const List<int> items = const <int>[0, 1, 2, 3, 4, 5]; ...@@ -11,7 +11,8 @@ const List<int> items = const <int>[0, 1, 2, 3, 4, 5];
void main() { void main() {
testWidgets('Tap item after scroll - horizontal', (WidgetTester tester) async { testWidgets('Tap item after scroll - horizontal', (WidgetTester tester) async {
final List<int> tapped = <int>[]; final List<int> tapped = <int>[];
await tester.pumpWidget(new Directionality( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new Center( child: new Center(
child: new Container( child: new Container(
...@@ -30,7 +31,8 @@ void main() { ...@@ -30,7 +31,8 @@ void main() {
), ),
), ),
), ),
)); ),
);
await tester.drag(find.text('2'), const Offset(-280.0, 0.0)); await tester.drag(find.text('2'), const Offset(-280.0, 0.0));
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
// screen is 800px wide, and has the following items: // screen is 800px wide, and has the following items:
...@@ -51,7 +53,10 @@ void main() { ...@@ -51,7 +53,10 @@ void main() {
testWidgets('Tap item after scroll - vertical', (WidgetTester tester) async { testWidgets('Tap item after scroll - vertical', (WidgetTester tester) async {
final List<int> tapped = <int>[]; final List<int> tapped = <int>[];
await tester.pumpWidget(new Center( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new Container( child: new Container(
width: 50.0, width: 50.0,
child: new ListView( child: new ListView(
...@@ -67,7 +72,9 @@ void main() { ...@@ -67,7 +72,9 @@ void main() {
}).toList(), }).toList(),
), ),
), ),
)); ),
),
);
await tester.drag(find.text('1'), const Offset(0.0, -280.0)); await tester.drag(find.text('1'), const Offset(0.0, -280.0));
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
// screen is 600px tall, and has the following items: // screen is 600px tall, and has the following items:
...@@ -92,7 +99,9 @@ void main() { ...@@ -92,7 +99,9 @@ void main() {
final List<int> tapped = <int>[]; final List<int> tapped = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 290.0, itemExtent: 290.0,
padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0),
children: items.map((int item) { children: items.map((int item) {
...@@ -104,6 +113,7 @@ void main() { ...@@ -104,6 +113,7 @@ void main() {
); );
}).toList(), }).toList(),
), ),
),
); );
await tester.tapAt(const Offset(200.0, 19.0)); await tester.tapAt(const Offset(200.0, 19.0));
expect(tapped, equals(<int>[])); expect(tapped, equals(<int>[]));
...@@ -123,7 +133,9 @@ void main() { ...@@ -123,7 +133,9 @@ void main() {
final List<int> tapped = <int>[]; final List<int> tapped = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 290.0, itemExtent: 290.0,
reverse: true, reverse: true,
padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0),
...@@ -136,6 +148,7 @@ void main() { ...@@ -136,6 +148,7 @@ void main() {
); );
}).toList(), }).toList(),
), ),
),
); );
await tester.tapAt(const Offset(200.0, 600.0 - 9.0)); await tester.tapAt(const Offset(200.0, 600.0 - 9.0));
expect(tapped, equals(<int>[])); expect(tapped, equals(<int>[]));
...@@ -156,7 +169,9 @@ void main() { ...@@ -156,7 +169,9 @@ void main() {
final List<int> tapped = <int>[]; final List<int> tapped = <int>[];
await tester.pumpWidget( await tester.pumpWidget(
new ListView( new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
itemExtent: 200.0, itemExtent: 200.0,
children: items.map((int item) { children: items.map((int item) {
return new Container( return new Container(
...@@ -167,6 +182,7 @@ void main() { ...@@ -167,6 +182,7 @@ void main() {
); );
}).toList(), }).toList(),
), ),
),
); );
await tester.fling(find.text('0'), const Offset(0.0, 400.0), 1000.0); await tester.fling(find.text('0'), const Offset(0.0, 400.0), 1000.0);
......
...@@ -15,7 +15,12 @@ void main() { ...@@ -15,7 +15,12 @@ void main() {
final List<Widget> textWidgets = <Widget>[]; final List<Widget> textWidgets = <Widget>[];
for (int i = 0; i < 80; i++) for (int i = 0; i < 80; i++)
textWidgets.add(new Text('$i')); textWidgets.add(new Text('$i'));
await tester.pumpWidget(new ListView(children: textWidgets)); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(children: textWidgets),
),
);
expect(semantics,includesNodeWith(actions: <SemanticsAction>[SemanticsAction.scrollUp])); expect(semantics,includesNodeWith(actions: <SemanticsAction>[SemanticsAction.scrollUp]));
...@@ -48,10 +53,15 @@ void main() { ...@@ -48,10 +53,15 @@ void main() {
initialScrollOffset: kItemHeight / 2, initialScrollOffset: kItemHeight / 2,
); );
await tester.pumpWidget(new ListView( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new ListView(
controller: scrollController, controller: scrollController,
children: containers children: containers,
)); ),
),
);
expect(scrollController.offset, kItemHeight / 2); expect(scrollController.offset, kItemHeight / 2);
......
...@@ -124,7 +124,9 @@ void main() { ...@@ -124,7 +124,9 @@ void main() {
final List<String> log = <String>[]; final List<String> log = <String>[];
await tester.pumpWidget( await tester.pumpWidget(
new SemanticsDebugger( new Directionality(
textDirection: TextDirection.ltr,
child: new SemanticsDebugger(
child: new Material( child: new Material(
child: new ListView( child: new ListView(
children: <Widget>[ children: <Widget>[
...@@ -144,6 +146,7 @@ void main() { ...@@ -144,6 +146,7 @@ void main() {
), ),
), ),
), ),
),
); );
await tester.tap(find.text('TOP')); await tester.tap(find.text('TOP'));
...@@ -159,7 +162,9 @@ void main() { ...@@ -159,7 +162,9 @@ void main() {
final Key childKey = new UniqueKey(); final Key childKey = new UniqueKey();
await tester.pumpWidget( await tester.pumpWidget(
new SemanticsDebugger( new Directionality(
textDirection: TextDirection.ltr,
child: new SemanticsDebugger(
child: new ListView( child: new ListView(
children: <Widget>[ children: <Widget>[
new Container( new Container(
...@@ -170,6 +175,7 @@ void main() { ...@@ -170,6 +175,7 @@ void main() {
], ],
), ),
), ),
),
); );
expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0));
...@@ -252,7 +258,9 @@ void main() { ...@@ -252,7 +258,9 @@ void main() {
final bool valueBottom = true; final bool valueBottom = true;
await tester.pumpWidget( await tester.pumpWidget(
new SemanticsDebugger( new Directionality(
textDirection: TextDirection.ltr,
child: new SemanticsDebugger(
child: new Material( child: new Material(
child: new ListView( child: new ListView(
children: <Widget>[ children: <Widget>[
...@@ -272,6 +280,7 @@ void main() { ...@@ -272,6 +280,7 @@ void main() {
), ),
), ),
), ),
),
); );
await tester.tap(find.byKey(keyTop)); await tester.tap(find.byKey(keyTop));
......
...@@ -146,7 +146,10 @@ void main() { ...@@ -146,7 +146,10 @@ void main() {
testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async { testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async {
const Key innerKey = const Key('inner'); const Key innerKey = const Key('inner');
final ScrollController primaryScrollController = new ScrollController(); final ScrollController primaryScrollController = new ScrollController();
await tester.pumpWidget(new PrimaryScrollController( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new PrimaryScrollController(
controller: primaryScrollController, controller: primaryScrollController,
child: new SingleChildScrollView( child: new SingleChildScrollView(
primary: true, primary: true,
...@@ -155,7 +158,9 @@ void main() { ...@@ -155,7 +158,9 @@ void main() {
child: new ListView(key: innerKey, primary: true), child: new ListView(key: innerKey, primary: true),
), ),
), ),
)); ),
),
);
final Scrollable innerScrollable = tester.widget( final Scrollable innerScrollable = tester.widget(
find.descendant( find.descendant(
......
...@@ -9,12 +9,15 @@ void main() { ...@@ -9,12 +9,15 @@ void main() {
testWidgets('SliverFillRemaining - no siblings', (WidgetTester tester) async { testWidgets('SliverFillRemaining - no siblings', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
controller: controller, controller: controller,
slivers: <Widget>[ slivers: <Widget>[
new SliverFillRemaining(child: new Container()), new SliverFillRemaining(child: new Container()),
], ],
), ),
),
); );
expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(600.0)); expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(600.0));
...@@ -34,13 +37,16 @@ void main() { ...@@ -34,13 +37,16 @@ void main() {
testWidgets('SliverFillRemaining - one sibling', (WidgetTester tester) async { testWidgets('SliverFillRemaining - one sibling', (WidgetTester tester) async {
final ScrollController controller = new ScrollController(); final ScrollController controller = new ScrollController();
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
controller: controller, controller: controller,
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter(child: const SizedBox(height: 100.0)), const SliverToBoxAdapter(child: const SizedBox(height: 100.0)),
new SliverFillRemaining(child: new Container()), new SliverFillRemaining(child: new Container()),
], ],
), ),
),
); );
expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(500.0)); expect(tester.renderObject<RenderBox>(find.byType(Container)).size.height, equals(500.0));
......
...@@ -12,13 +12,16 @@ void main() { ...@@ -12,13 +12,16 @@ void main() {
}); });
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new SliverFillViewport( new SliverFillViewport(
delegate: new SliverChildListDelegate(children, addAutomaticKeepAlives: false), delegate: new SliverChildListDelegate(children, addAutomaticKeepAlives: false),
), ),
], ],
), ),
),
); );
final RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).first); final RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).first);
...@@ -73,6 +76,7 @@ void main() { ...@@ -73,6 +76,7 @@ void main() {
' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
' │ crossAxisDirection: AxisDirection.right,\n'
' │ viewportMainAxisExtent: 600.0)\n' ' │ viewportMainAxisExtent: 600.0)\n'
' │ geometry: SliverGeometry(scrollExtent: 12000.0, paintExtent:\n' ' │ geometry: SliverGeometry(scrollExtent: 12000.0, paintExtent:\n'
' │ 600.0, maxPaintExtent: 12000.0, hasVisualOverflow: true)\n' ' │ 600.0, maxPaintExtent: 12000.0, hasVisualOverflow: true)\n'
...@@ -107,7 +111,7 @@ void main() { ...@@ -107,7 +111,7 @@ void main() {
' ║ TextSpan:\n' ' ║ TextSpan:\n'
' ║ <all styles inherited>\n' ' ║ <all styles inherited>\n'
' ║ "0"\n' ' ║ "0"\n'
' ╚═══════════\n', ' ╚═══════════\n'
), ),
); );
}); });
......
...@@ -114,7 +114,9 @@ void main() { ...@@ -114,7 +114,9 @@ void main() {
}).toList(); }).toList();
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new SliverPrototypeExtentList( new SliverPrototypeExtentList(
prototypeItem: items[0], prototypeItem: items[0],
...@@ -124,7 +126,8 @@ void main() { ...@@ -124,7 +126,8 @@ void main() {
), ),
), ),
], ],
) ),
),
); );
// Item 0 exists in the list and as the prototype item. // Item 0 exists in the list and as the prototype item.
......
...@@ -182,7 +182,9 @@ void main() { ...@@ -182,7 +182,9 @@ void main() {
); );
}); });
await tester.pumpWidget( await tester.pumpWidget(
new Center( new Directionality(
textDirection: TextDirection.ltr,
child: new Center(
child: new SizedBox( child: new SizedBox(
height: containerHeight, height: containerHeight,
child: new CustomScrollView( child: new CustomScrollView(
...@@ -191,6 +193,7 @@ void main() { ...@@ -191,6 +193,7 @@ void main() {
), ),
), ),
), ),
),
); );
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
...@@ -237,9 +240,12 @@ void main() { ...@@ -237,9 +240,12 @@ void main() {
); );
}); });
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: slivers, slivers: slivers,
), ),
),
); );
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
......
...@@ -26,13 +26,16 @@ void main() { ...@@ -26,13 +26,16 @@ 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 {
const double bigHeight = 1000.0; const double bigHeight = 1000.0;
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
const BigSliver(height: bigHeight), const BigSliver(height: bigHeight),
new SliverPersistentHeader(delegate: new TestDelegate(), floating: true), new SliverPersistentHeader(delegate: new TestDelegate(), floating: true),
const BigSliver(height: bigHeight), const BigSliver(height: bigHeight),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).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
...@@ -53,13 +56,16 @@ void main() { ...@@ -53,13 +56,16 @@ void main() {
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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true),
new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), new BigSliver(key: key3 = new GlobalKey(), height: bigHeight),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
...@@ -122,13 +128,16 @@ void main() { ...@@ -122,13 +128,16 @@ void main() {
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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true),
new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), new BigSliver(key: key3 = new GlobalKey(), height: bigHeight),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
...@@ -154,13 +163,16 @@ void main() { ...@@ -154,13 +163,16 @@ void main() {
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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true),
new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), new BigSliver(key: key3 = new GlobalKey(), height: bigHeight),
], ],
), ),
),
); );
final ScrollPositionWithSingleContext position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPositionWithSingleContext position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
...@@ -185,7 +197,9 @@ void main() { ...@@ -185,7 +197,9 @@ void main() {
testWidgets('Sliver appbars - floating - overscroll gap is below header', (WidgetTester tester) async { testWidgets('Sliver appbars - floating - overscroll gap is below header', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
slivers: <Widget>[ slivers: <Widget>[
new SliverPersistentHeader(delegate: new TestDelegate(), floating: true), new SliverPersistentHeader(delegate: new TestDelegate(), floating: true),
...@@ -199,6 +213,7 @@ void main() { ...@@ -199,6 +213,7 @@ void main() {
), ),
], ],
), ),
),
); );
expect(tester.getTopLeft(find.byType(Container)), Offset.zero); expect(tester.getTopLeft(find.byType(Container)), Offset.zero);
......
...@@ -27,7 +27,9 @@ void main() { ...@@ -27,7 +27,9 @@ void main() {
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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
...@@ -36,6 +38,7 @@ void main() { ...@@ -36,6 +38,7 @@ void main() {
new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), new BigSliver(key: key5 = new GlobalKey(), height: bigHeight),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).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
...@@ -60,11 +63,14 @@ void main() { ...@@ -60,11 +63,14 @@ void main() {
final TestDelegateThatCanThrow delegateThatCanThrow = new TestDelegateThatCanThrow(); final TestDelegateThatCanThrow delegateThatCanThrow = new TestDelegateThatCanThrow();
GlobalKey key; GlobalKey key;
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new SliverPersistentHeader(key: key = new GlobalKey(), delegate: delegateThatCanThrow, pinned: true), new SliverPersistentHeader(key: key = new GlobalKey(), delegate: delegateThatCanThrow, pinned: true),
], ],
), ),
),
); );
await tester.pumpAndSettle(const Duration(milliseconds: 10)); await tester.pumpAndSettle(const Duration(milliseconds: 10));
...@@ -90,6 +96,7 @@ void main() { ...@@ -90,6 +96,7 @@ void main() {
' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ constraints: SliverConstraints(AxisDirection.down,\n'
' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
' │ crossAxisDirection: AxisDirection.right,\n'
' │ viewportMainAxisExtent: 600.0)\n' ' │ viewportMainAxisExtent: 600.0)\n'
' │ geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 200.0,\n' ' │ geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 200.0,\n'
' │ maxPaintExtent: 200.0, hasVisualOverflow: true)\n' ' │ maxPaintExtent: 200.0, hasVisualOverflow: true)\n'
...@@ -135,7 +142,7 @@ void main() { ...@@ -135,7 +142,7 @@ void main() {
' parentData: <none> (can use size)\n' ' parentData: <none> (can use size)\n'
' constraints: BoxConstraints(w=800.0, 100.0<=h<=200.0)\n' ' constraints: BoxConstraints(w=800.0, 100.0<=h<=200.0)\n'
' size: Size(800.0, 200.0)\n' ' size: Size(800.0, 200.0)\n'
' additionalConstraints: BoxConstraints(biggest)\n', ' additionalConstraints: BoxConstraints(biggest)\n'
), ),
); );
}); });
...@@ -144,7 +151,9 @@ void main() { ...@@ -144,7 +151,9 @@ void main() {
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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
...@@ -153,6 +162,7 @@ void main() { ...@@ -153,6 +162,7 @@ void main() {
new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), new BigSliver(key: key5 = new GlobalKey(), height: bigHeight),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
...@@ -234,7 +244,9 @@ void main() { ...@@ -234,7 +244,9 @@ void main() {
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 CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), new BigSliver(key: key1 = new GlobalKey(), height: bigHeight),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true),
...@@ -243,6 +255,7 @@ void main() { ...@@ -243,6 +255,7 @@ void main() {
new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), new BigSliver(key: key5 = new GlobalKey(), height: bigHeight),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).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
...@@ -265,7 +278,9 @@ void main() { ...@@ -265,7 +278,9 @@ void main() {
testWidgets('Sliver appbars - overscroll gap is below header', (WidgetTester tester) async { testWidgets('Sliver appbars - overscroll gap is below header', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
slivers: <Widget>[ slivers: <Widget>[
new SliverPersistentHeader(delegate: new TestDelegate(), pinned: true), new SliverPersistentHeader(delegate: new TestDelegate(), pinned: true),
...@@ -279,6 +294,7 @@ void main() { ...@@ -279,6 +294,7 @@ void main() {
), ),
], ],
), ),
),
); );
expect(tester.getTopLeft(find.byType(Container)), Offset.zero); expect(tester.getTopLeft(find.byType(Container)), Offset.zero);
......
...@@ -18,7 +18,9 @@ void main() { ...@@ -18,7 +18,9 @@ void main() {
testWidgets('Sliver appbars - scrolling', (WidgetTester tester) async { testWidgets('Sliver appbars - scrolling', (WidgetTester tester) async {
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
new BigSliver(key: key1 = new GlobalKey()), new BigSliver(key: key1 = new GlobalKey()),
new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate()), new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate()),
...@@ -27,6 +29,7 @@ void main() { ...@@ -27,6 +29,7 @@ void main() {
new BigSliver(key: key5 = new GlobalKey()), new BigSliver(key: key5 = new GlobalKey()),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).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
...@@ -51,7 +54,9 @@ void main() { ...@@ -51,7 +54,9 @@ void main() {
final GlobalKey key = new GlobalKey(); final GlobalKey key = new GlobalKey();
final TestDelegate delegate = new TestDelegate(); final TestDelegate delegate = new TestDelegate();
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <Widget>[ slivers: <Widget>[
const BigSliver(), const BigSliver(),
new SliverPersistentHeader(key: key, delegate: delegate), new SliverPersistentHeader(key: key, delegate: delegate),
...@@ -59,6 +64,7 @@ void main() { ...@@ -59,6 +64,7 @@ void main() {
const BigSliver(), const BigSliver(),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
position.animateTo(RenderBigSliver.height + delegate.maxExtent - 5.0, curve: Curves.linear, duration: const Duration(minutes: 1)); position.animateTo(RenderBigSliver.height + delegate.maxExtent - 5.0, curve: Curves.linear, duration: const Duration(minutes: 1));
...@@ -70,7 +76,9 @@ void main() { ...@@ -70,7 +76,9 @@ void main() {
testWidgets('Sliver appbars - scrolling - overscroll gap is below header', (WidgetTester tester) async { testWidgets('Sliver appbars - scrolling - overscroll gap is below header', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
slivers: <Widget>[ slivers: <Widget>[
new SliverPersistentHeader(delegate: new TestDelegate()), new SliverPersistentHeader(delegate: new TestDelegate()),
...@@ -84,6 +92,7 @@ void main() { ...@@ -84,6 +92,7 @@ void main() {
), ),
], ],
), ),
),
); );
expect(tester.getTopLeft(find.byType(Container)), Offset.zero); expect(tester.getTopLeft(find.byType(Container)), Offset.zero);
......
...@@ -24,7 +24,10 @@ class _GenerationTextState extends State<GenerationText> { ...@@ -24,7 +24,10 @@ class _GenerationTextState extends State<GenerationText> {
Future<Null> test(WidgetTester tester, double offset, List<int> keys) { Future<Null> test(WidgetTester tester, double offset, List<int> keys) {
globalGeneration += 1; globalGeneration += 1;
return tester.pumpWidget(new Viewport( return tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -33,7 +36,9 @@ Future<Null> test(WidgetTester tester, double offset, List<int> keys) { ...@@ -33,7 +36,9 @@ Future<Null> test(WidgetTester tester, double offset, List<int> keys) {
}).toList()), }).toList()),
), ),
], ],
)); ),
),
);
} }
void verify(WidgetTester tester, List<Offset> answerKey, String text) { void verify(WidgetTester tester, List<Offset> answerKey, String text) {
......
...@@ -9,7 +9,10 @@ import 'package:flutter/widgets.dart'; ...@@ -9,7 +9,10 @@ import 'package:flutter/widgets.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
Future<Null> test(WidgetTester tester, double offset) { Future<Null> test(WidgetTester tester, double offset) {
return tester.pumpWidget(new Viewport( return tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -22,7 +25,9 @@ Future<Null> test(WidgetTester tester, double offset) { ...@@ -22,7 +25,9 @@ Future<Null> test(WidgetTester tester, double offset) {
]), ]),
), ),
], ],
)); ),
),
);
} }
void verify(WidgetTester tester, List<Offset> answerKey, String text) { void verify(WidgetTester tester, List<Offset> answerKey, String text) {
...@@ -74,7 +79,10 @@ void main() { ...@@ -74,7 +79,10 @@ void main() {
testWidgets('Viewport with GlobalKey reparenting', (WidgetTester tester) async { testWidgets('Viewport with GlobalKey reparenting', (WidgetTester tester) async {
final Key key1 = new GlobalKey(); final Key key1 = new GlobalKey();
final ViewportOffset offset = new ViewportOffset.zero(); final ViewportOffset offset = new ViewportOffset.zero();
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: offset, offset: offset,
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -85,13 +93,18 @@ void main() { ...@@ -85,13 +93,18 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
verify(tester, <Offset>[ verify(tester, <Offset>[
const Offset(0.0, 0.0), const Offset(0.0, 0.0),
const Offset(0.0, 251.0), const Offset(0.0, 251.0),
const Offset(0.0, 503.0), const Offset(0.0, 503.0),
], 'abc'); ], 'abc');
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: offset, offset: offset,
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -102,13 +115,18 @@ void main() { ...@@ -102,13 +115,18 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
verify(tester, <Offset>[ verify(tester, <Offset>[
const Offset(0.0, 0.0), const Offset(0.0, 0.0),
const Offset(0.0, 253.0), const Offset(0.0, 253.0),
const Offset(0.0, 504.0), const Offset(0.0, 504.0),
], 'cab'); ], 'cab');
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: offset, offset: offset,
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -119,13 +137,18 @@ void main() { ...@@ -119,13 +137,18 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
verify(tester, <Offset>[ verify(tester, <Offset>[
const Offset(0.0, 0.0), const Offset(0.0, 0.0),
const Offset(0.0, 251.0), const Offset(0.0, 251.0),
const Offset(0.0, 504.0), const Offset(0.0, 504.0),
], 'acb'); ], 'acb');
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: offset, offset: offset,
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -135,12 +158,17 @@ void main() { ...@@ -135,12 +158,17 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
verify(tester, <Offset>[ verify(tester, <Offset>[
const Offset(0.0, 0.0), const Offset(0.0, 0.0),
const Offset(0.0, 251.0), const Offset(0.0, 251.0),
], 'ab'); ], 'ab');
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: offset, offset: offset,
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -151,7 +179,9 @@ void main() { ...@@ -151,7 +179,9 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
verify(tester, <Offset>[ verify(tester, <Offset>[
const Offset(0.0, 0.0), const Offset(0.0, 0.0),
const Offset(0.0, 251.0), const Offset(0.0, 251.0),
...@@ -160,53 +190,76 @@ void main() { ...@@ -160,53 +190,76 @@ void main() {
}); });
testWidgets('Viewport overflow clipping of SliverToBoxAdapter', (WidgetTester tester) async { testWidgets('Viewport overflow clipping of SliverToBoxAdapter', (WidgetTester tester) async {
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter( const SliverToBoxAdapter(
child: const SizedBox(height: 400.0, child: const Text('a')), child: const SizedBox(height: 400.0, child: const Text('a')),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), isNot(paints..clipRect())); expect(find.byType(Viewport), isNot(paints..clipRect()));
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter( const SliverToBoxAdapter(
child: const SizedBox(height: 400.0, child: const Text('a')), child: const SizedBox(height: 400.0, child: const Text('a')),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), paints..clipRect()); expect(find.byType(Viewport), paints..clipRect());
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter( const SliverToBoxAdapter(
child: const SizedBox(height: 4000.0, child: const Text('a')), child: const SizedBox(height: 4000.0, child: const Text('a')),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), paints..clipRect()); expect(find.byType(Viewport), paints..clipRect());
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
slivers: <Widget>[ slivers: <Widget>[
const SliverToBoxAdapter( const SliverToBoxAdapter(
child: const SizedBox(height: 4000.0, child: const Text('a')), child: const SizedBox(height: 4000.0, child: const Text('a')),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), paints..clipRect()); expect(find.byType(Viewport), paints..clipRect());
}); });
testWidgets('Viewport overflow clipping of SliverBlock', (WidgetTester tester) async { testWidgets('Viewport overflow clipping of SliverBlock', (WidgetTester tester) async {
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -215,11 +268,16 @@ void main() { ...@@ -215,11 +268,16 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), isNot(paints..clipRect())); expect(find.byType(Viewport), isNot(paints..clipRect()));
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -228,11 +286,16 @@ void main() { ...@@ -228,11 +286,16 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), paints..clipRect()); expect(find.byType(Viewport), paints..clipRect());
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.fixed(100.0), offset: new ViewportOffset.fixed(100.0),
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -241,11 +304,16 @@ void main() { ...@@ -241,11 +304,16 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), paints..clipRect()); expect(find.byType(Viewport), paints..clipRect());
await tester.pumpWidget(new Viewport( await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
offset: new ViewportOffset.zero(), offset: new ViewportOffset.zero(),
slivers: <Widget>[ slivers: <Widget>[
new SliverList( new SliverList(
...@@ -254,7 +322,9 @@ void main() { ...@@ -254,7 +322,9 @@ void main() {
]), ]),
), ),
], ],
)); ),
),
);
expect(find.byType(Viewport), paints..clipRect()); expect(find.byType(Viewport), paints..clipRect());
}); });
......
...@@ -20,7 +20,9 @@ void main() { ...@@ -20,7 +20,9 @@ void main() {
testWidgets('Sliver protocol', (WidgetTester tester) async { testWidgets('Sliver protocol', (WidgetTester tester) async {
GlobalKey key1, key2, key3, key4, key5; GlobalKey key1, key2, key3, key4, key5;
await tester.pumpWidget( await tester.pumpWidget(
new CustomScrollView( new Directionality(
textDirection: TextDirection.ltr,
child: new CustomScrollView(
slivers: <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()),
...@@ -29,6 +31,7 @@ void main() { ...@@ -29,6 +31,7 @@ void main() {
new BigSliver(key: key5 = new GlobalKey()), new BigSliver(key: key5 = new GlobalKey()),
], ],
), ),
),
); );
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position; final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).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
......
...@@ -7,7 +7,10 @@ import 'package:flutter/widgets.dart'; ...@@ -7,7 +7,10 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
Future<Null> test(WidgetTester tester, double offset, { double anchor: 0.0 }) { Future<Null> test(WidgetTester tester, double offset, { double anchor: 0.0 }) {
return tester.pumpWidget(new Viewport( return tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Viewport(
anchor: anchor / 600.0, anchor: anchor / 600.0,
offset: new ViewportOffset.fixed(offset), offset: new ViewportOffset.fixed(offset),
slivers: <Widget>[ slivers: <Widget>[
...@@ -17,7 +20,9 @@ Future<Null> test(WidgetTester tester, double offset, { double anchor: 0.0 }) { ...@@ -17,7 +20,9 @@ Future<Null> test(WidgetTester tester, double offset, { double anchor: 0.0 }) {
const SliverToBoxAdapter(child: const SizedBox(height: 400.0)), const SliverToBoxAdapter(child: const SizedBox(height: 400.0)),
const SliverToBoxAdapter(child: const SizedBox(height: 400.0)), const SliverToBoxAdapter(child: const SizedBox(height: 400.0)),
], ],
)); ),
),
);
} }
void verify(WidgetTester tester, List<Offset> idealPositions, List<bool> idealVisibles) { void verify(WidgetTester tester, List<Offset> idealPositions, List<bool> idealVisibles) {
......
...@@ -79,7 +79,12 @@ class FooScrollBehavior extends ScrollBehavior { ...@@ -79,7 +79,12 @@ class FooScrollBehavior extends ScrollBehavior {
void main() { void main() {
testWidgets('Can animate scroll after setState', (WidgetTester tester) async { testWidgets('Can animate scroll after setState', (WidgetTester tester) async {
await tester.pumpWidget(new Foo()); await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Foo(),
),
);
expect(tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels, 0.0); expect(tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels, 0.0);
await tester.tap(find.byType(GestureDetector).first); await tester.tap(find.byType(GestureDetector).first);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
......
...@@ -50,7 +50,9 @@ void main() { ...@@ -50,7 +50,9 @@ void main() {
String paragraphText(RenderParagraph paragraph) => paragraph.text.text; String paragraphText(RenderParagraph paragraph) => paragraph.text.text;
await tester.pumpWidget( await tester.pumpWidget(
new WidgetInspector( new Directionality(
textDirection: TextDirection.ltr,
child: new WidgetInspector(
key: inspectorKey, key: inspectorKey,
selectButtonBuilder: selectButtonBuilder, selectButtonBuilder: selectButtonBuilder,
child: new Material( child: new Material(
...@@ -73,6 +75,7 @@ void main() { ...@@ -73,6 +75,7 @@ void main() {
), ),
), ),
), ),
),
); );
expect(getInspectorState().selection.current, isNull); expect(getInspectorState().selection.current, isNull);
...@@ -118,7 +121,9 @@ void main() { ...@@ -118,7 +121,9 @@ void main() {
dynamic getInspectorState() => inspectorKey.currentState; dynamic getInspectorState() => inspectorKey.currentState;
await tester.pumpWidget( await tester.pumpWidget(
new WidgetInspector( new Directionality(
textDirection: TextDirection.ltr,
child: new WidgetInspector(
key: inspectorKey, key: inspectorKey,
selectButtonBuilder: selectButtonBuilder, selectButtonBuilder: selectButtonBuilder,
child: new ListView( child: new ListView(
...@@ -130,6 +135,7 @@ void main() { ...@@ -130,6 +135,7 @@ void main() {
], ],
), ),
), ),
),
); );
expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.0)); expect(tester.getTopLeft(find.byKey(childKey)).dy, equals(0.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