From 8eb6ad27763f478abe70806bd1cdfbb12f39eeba Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 5 Sep 2017 11:29:20 -0700 Subject: [PATCH] Add RTL support to GridView (#11921) Fixes #11855 --- .../flutter/lib/src/material/date_picker.dart | 1 + .../lib/src/material/expansion_panel.dart | 2 +- .../flutter/lib/src/material/grid_tile.dart | 8 +- .../flutter/lib/src/rendering/sliver.dart | 57 ++- .../lib/src/rendering/sliver_grid.dart | 26 +- .../flutter/lib/src/rendering/viewport.dart | 28 +- .../flutter/lib/src/widgets/page_view.dart | 9 +- .../flutter/lib/src/widgets/scroll_view.dart | 9 +- .../src/widgets/single_child_scroll_view.dart | 9 +- .../flutter/lib/src/widgets/viewport.dart | 53 ++- .../flutter/test/material/ink_well_test.dart | 27 +- .../flutter/test/material/material_test.dart | 69 ++-- .../test/material/refresh_indicator_test.dart | 211 ++++++----- .../flutter/test/rendering/debug_test.dart | 2 + .../test/rendering/slivers_block_test.dart | 3 + .../test/rendering/slivers_helpers_test.dart | 2 + .../test/rendering/slivers_layout_test.dart | 1 + .../flutter/test/rendering/slivers_test.dart | 24 +- .../test/widgets/animated_list_test.dart | 71 ++-- .../widgets/automatic_keep_alive_test.dart | 179 +++++---- .../widgets/box_sliver_mismatch_test.dart | 13 +- .../flutter/test/widgets/center_test.dart | 7 +- .../flutter/test/widgets/container_test.dart | 7 +- .../test/widgets/date_picker_test.dart | 29 +- .../test/widgets/ensure_visible_test.dart | 106 +++--- packages/flutter/test/widgets/form_test.dart | 31 +- .../test/widgets/grid_view_layout_test.dart | 42 ++- .../flutter/test/widgets/grid_view_test.dart | 350 +++++++++++------- .../flutter/test/widgets/keep_alive_test.dart | 108 ++++-- .../test/widgets/linked_scroll_view_test.dart | 147 ++++---- .../test/widgets/list_view_builder_test.dart | 55 +-- .../widgets/list_view_correction_test.dart | 131 ++++--- .../test/widgets/list_view_fling_test.dart | 15 +- .../test/widgets/list_view_misc_test.dart | 174 +++++---- .../test/widgets/list_view_relayout_test.dart | 227 ++++++++---- .../flutter/test/widgets/list_view_test.dart | 154 +++++--- .../test/widgets/list_view_vertical_test.dart | 40 +- .../widgets/list_view_viewporting_test.dart | 93 +++-- .../list_view_with_inherited_test.dart | 7 +- .../widgets/listview_end_append_test.dart | 30 +- .../widgets/overscroll_indicator_test.dart | 144 ++++--- .../remember_scroll_position_test.dart | 43 ++- .../test/widgets/reparent_state_test.dart | 23 +- .../test/widgets/scroll_controller_test.dart | 277 ++++++++------ .../test/widgets/scroll_interaction_test.dart | 15 +- .../test/widgets/scroll_view_test.dart | 248 ++++++++----- .../widgets/scrollable_animations_test.dart | 39 +- .../test/widgets/scrollable_dispose_test.dart | 13 +- .../test/widgets/scrollable_fling_test.dart | 14 +- .../test/widgets/scrollable_grid_test.dart | 55 +-- .../scrollable_list_hit_testing_test.dart | 146 ++++---- .../widgets/scrollable_semantics_test.dart | 20 +- .../test/widgets/semantics_debugger_test.dart | 95 ++--- .../single_child_scroll_view_test.dart | 21 +- .../widgets/sliver_fill_remaining_test.dart | 28 +- .../widgets/sliver_fill_viewport_test.dart | 18 +- .../sliver_prototype_item_extent_test.dart | 23 +- .../test/widgets/sliver_semantics_test.dart | 22 +- .../widgets/slivers_appbar_floating_test.dart | 89 +++-- .../widgets/slivers_appbar_pinned_test.dart | 100 ++--- .../slivers_appbar_scrolling_test.dart | 65 ++-- .../slivers_block_global_key_test.dart | 23 +- .../test/widgets/slivers_block_test.dart | 332 ++++++++++------- .../test/widgets/slivers_padding_test.dart | 230 +++++++----- .../test/widgets/slivers_protocol_test.dart | 19 +- .../flutter/test/widgets/slivers_test.dart | 27 +- .../state_setting_in_scrollables_test.dart | 7 +- .../test/widgets/widget_inspector_test.dart | 66 ++-- 68 files changed, 2864 insertions(+), 1895 deletions(-) diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 451b4ab94ee..8e14f8ebd92 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -205,6 +205,7 @@ class _DayPickerGridDelegate extends SliverGridDelegate { crossAxisStride: tileWidth, childMainAxisExtent: tileHeight, childCrossAxisExtent: tileWidth, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), ); } diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index 39ace458818..612b8448116 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -80,7 +80,7 @@ class ExpansionPanelList extends StatelessWidget { assert(animationDuration != null), 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]. final List children; diff --git a/packages/flutter/lib/src/material/grid_tile.dart b/packages/flutter/lib/src/material/grid_tile.dart index ff2a060d0f6..4374f786a97 100644 --- a/packages/flutter/lib/src/material/grid_tile.dart +++ b/packages/flutter/lib/src/material/grid_tile.dart @@ -49,15 +49,15 @@ class GridTile extends StatelessWidget { final List children = [ new Positioned.fill( - child: child - ) + child: child, + ), ]; if (header != null) { children.add(new Positioned( top: 0.0, left: 0.0, right: 0.0, - child: header + child: header, )); } if (footer != null) { @@ -65,7 +65,7 @@ class GridTile extends StatelessWidget { left: 0.0, bottom: 0.0, right: 0.0, - child: footer + child: footer, )); } return new Stack(children: children); diff --git a/packages/flutter/lib/src/rendering/sliver.dart b/packages/flutter/lib/src/rendering/sliver.dart index 4889d8a6b87..9458897f43e 100644 --- a/packages/flutter/lib/src/rendering/sliver.dart +++ b/packages/flutter/lib/src/rendering/sliver.dart @@ -89,6 +89,21 @@ Axis axisDirectionToAxis(AxisDirection axisDirection) { 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]. /// /// Specifically, returns [AxisDirection.up] for [AxisDirection.down] (and @@ -192,6 +207,7 @@ class SliverConstraints extends Constraints { @required this.overlap, @required this.remainingPaintExtent, @required this.crossAxisExtent, + @required this.crossAxisDirection, @required this.viewportMainAxisExtent, }) : assert(axisDirection != null), assert(growthDirection != null), @@ -200,6 +216,7 @@ class SliverConstraints extends Constraints { assert(overlap != null), assert(remainingPaintExtent != null), assert(crossAxisExtent != null), + assert(crossAxisDirection != null), assert(viewportMainAxisExtent != null); /// Creates a copy of this object but with the given fields replaced with the @@ -212,6 +229,7 @@ class SliverConstraints extends Constraints { double overlap, double remainingPaintExtent, double crossAxisExtent, + AxisDirection crossAxisDirection, double viewportMainAxisExtent, }) { return new SliverConstraints( @@ -222,6 +240,7 @@ class SliverConstraints extends Constraints { overlap: overlap ?? this.overlap, remainingPaintExtent: remainingPaintExtent ?? this.remainingPaintExtent, crossAxisExtent: crossAxisExtent ?? this.crossAxisExtent, + crossAxisDirection: crossAxisDirection ?? this.crossAxisDirection, viewportMainAxisExtent: viewportMainAxisExtent ?? this.viewportMainAxisExtent, ); } @@ -315,9 +334,15 @@ class SliverConstraints extends Constraints { /// 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; + /// 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. /// /// For a vertical list, this is the height of the viewport. @@ -361,6 +386,7 @@ class SliverConstraints extends Constraints { bool get isNormalized { return scrollOffset >= 0.0 && crossAxisExtent >= 0.0 + && axisDirectionToAxis(axisDirection) != axisDirectionToAxis(crossAxisDirection) && viewportMainAxisExtent >= 0.0 && remainingPaintExtent >= 0.0; } @@ -421,6 +447,8 @@ class SliverConstraints extends Constraints { verify(viewportMainAxisExtent != null, 'The "viewportMainAxisExtent" is null.'); verify(scrollOffset >= 0.0, 'The "scrollOffset" 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(remainingPaintExtent >= 0.0, 'The "remainingPaintExtent" is negative.'); verify(isNormalized, 'The constraints are not normalized.'); // should be redundant with earlier checks @@ -437,18 +465,28 @@ class SliverConstraints extends Constraints { return false; final SliverConstraints typedOther = other; assert(typedOther.debugAssertIsValid()); - return axisDirection == typedOther.axisDirection && - growthDirection == typedOther.growthDirection && - scrollOffset == typedOther.scrollOffset && - overlap == typedOther.overlap && - remainingPaintExtent == typedOther.remainingPaintExtent && - crossAxisExtent == typedOther.crossAxisExtent && - viewportMainAxisExtent == typedOther.viewportMainAxisExtent; + return typedOther.axisDirection == axisDirection + && typedOther.growthDirection == growthDirection + && typedOther.scrollOffset == scrollOffset + && typedOther.overlap == overlap + && typedOther.remainingPaintExtent == remainingPaintExtent + && typedOther.crossAxisExtent == crossAxisExtent + && typedOther.crossAxisDirection == crossAxisDirection + && typedOther.viewportMainAxisExtent == viewportMainAxisExtent; } @override int get hashCode { - return hashValues(axisDirection, growthDirection, scrollOffset, overlap, remainingPaintExtent, crossAxisExtent, viewportMainAxisExtent); + return hashValues( + axisDirection, + growthDirection, + scrollOffset, + overlap, + remainingPaintExtent, + crossAxisExtent, + crossAxisDirection, + viewportMainAxisExtent, + ); } @override @@ -461,6 +499,7 @@ class SliverConstraints extends Constraints { 'remainingPaintExtent: ${remainingPaintExtent.toStringAsFixed(1)}, ' + (overlap != 0.0 ? 'overlap: ${overlap.toStringAsFixed(1)}, ' : '') + 'crossAxisExtent: ${crossAxisExtent.toStringAsFixed(1)}, ' + + 'crossAxisDirection: $crossAxisDirection, ' + 'viewportMainAxisExtent: ${viewportMainAxisExtent.toStringAsFixed(1)}' + ')'; } diff --git a/packages/flutter/lib/src/rendering/sliver_grid.dart b/packages/flutter/lib/src/rendering/sliver_grid.dart index 7fb0cd58d4c..de1f752b2e8 100644 --- a/packages/flutter/lib/src/rendering/sliver_grid.dart +++ b/packages/flutter/lib/src/rendering/sliver_grid.dart @@ -151,11 +151,13 @@ class SliverGridRegularTileLayout extends SliverGridLayout { @required this.crossAxisStride, @required this.childMainAxisExtent, @required this.childCrossAxisExtent, + @required this.reverseCrossAxis, }) : assert(crossAxisCount != null && crossAxisCount > 0), assert(mainAxisStride != null && mainAxisStride >= 0), assert(crossAxisStride != null && crossAxisStride >= 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. final int crossAxisCount; @@ -176,6 +178,17 @@ class SliverGridRegularTileLayout extends SliverGridLayout { /// edge of the same tile in the cross axis. 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 int getMinChildIndexForScrollOffset(double scrollOffset) { return mainAxisStride > 0.0 ? crossAxisCount * (scrollOffset ~/ mainAxisStride) : 0; @@ -190,11 +203,18 @@ class SliverGridRegularTileLayout extends SliverGridLayout { return 0; } + double _getOffsetFromStartInCrossAxis(double crossAxisStart) { + if (reverseCrossAxis) + return crossAxisCount * crossAxisStride - crossAxisStart - childCrossAxisExtent; + return crossAxisStart; + } + @override SliverGridGeometry getGeometryForChildIndex(int index) { + final double crossAxisStart = (index % crossAxisCount) * crossAxisStride; return new SliverGridGeometry( scrollOffset: (index ~/ crossAxisCount) * mainAxisStride, - crossAxisOffset: (index % crossAxisCount) * crossAxisStride, + crossAxisOffset: _getOffsetFromStartInCrossAxis(crossAxisStart), mainAxisExtent: childMainAxisExtent, crossAxisExtent: childCrossAxisExtent, ); @@ -313,6 +333,7 @@ class SliverGridDelegateWithFixedCrossAxisCount extends SliverGridDelegate { crossAxisStride: childCrossAxisExtent + crossAxisSpacing, childMainAxisExtent: childMainAxisExtent, childCrossAxisExtent: childCrossAxisExtent, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), ); } @@ -410,6 +431,7 @@ class SliverGridDelegateWithMaxCrossAxisExtent extends SliverGridDelegate { crossAxisStride: childCrossAxisExtent + crossAxisSpacing, childMainAxisExtent: childMainAxisExtent, childCrossAxisExtent: childCrossAxisExtent, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), ); } diff --git a/packages/flutter/lib/src/rendering/viewport.dart b/packages/flutter/lib/src/rendering/viewport.dart index 02f610813be..b2fc62a405d 100644 --- a/packages/flutter/lib/src/rendering/viewport.dart +++ b/packages/flutter/lib/src/rendering/viewport.dart @@ -81,10 +81,14 @@ abstract class RenderViewportBase _crossAxisDirection; + AxisDirection _crossAxisDirection; + set crossAxisDirection(AxisDirection value) { + assert(value != null); + if (value == _crossAxisDirection) + return; + _crossAxisDirection = value; + markNeedsLayout(); + } + /// The axis along which the viewport scrolls. /// /// For example, if the [axisDirection] is [AxisDirection.down], then the @@ -271,6 +291,7 @@ abstract class RenderViewportBase('axisDirection', axisDirection)); + description.add(new EnumProperty('crossAxisDirection', crossAxisDirection)); description.add(new DiagnosticsProperty('offset', offset)); } @@ -687,6 +709,7 @@ class RenderViewport extends RenderViewportBase children, @@ -695,7 +718,7 @@ class RenderViewport extends RenderViewportBase= 0.0 && anchor <= 1.0), _anchor = anchor, _center = center, - super(axisDirection: axisDirection, offset: offset) { + super(axisDirection: axisDirection, crossAxisDirection: crossAxisDirection, offset: offset) { addAll(children); if (center == null && firstChild != null) _center = firstChild; @@ -1120,9 +1143,10 @@ class RenderShrinkWrappingViewport extends RenderViewportBase children, - }) : super(axisDirection: axisDirection, offset: offset) { + }) : super(axisDirection: axisDirection, crossAxisDirection: crossAxisDirection, offset: offset) { addAll(children); } diff --git a/packages/flutter/lib/src/widgets/page_view.dart b/packages/flutter/lib/src/widgets/page_view.dart index 62fe9102ccf..6178694b302 100644 --- a/packages/flutter/lib/src/widgets/page_view.dart +++ b/packages/flutter/lib/src/widgets/page_view.dart @@ -453,13 +453,8 @@ class _PageViewState extends State { case Axis.horizontal: final TextDirection textDirection = Directionality.of(context); assert(textDirection != null); - switch (textDirection) { - case TextDirection.rtl: - return widget.reverse ? AxisDirection.right : AxisDirection.left; - case TextDirection.ltr: - return widget.reverse ? AxisDirection.left : AxisDirection.right; - } - return null; + final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection); + return widget.reverse ? flipAxisDirection(axisDirection) : axisDirection; case Axis.vertical: return widget.reverse ? AxisDirection.up : AxisDirection.down; } diff --git a/packages/flutter/lib/src/widgets/scroll_view.dart b/packages/flutter/lib/src/widgets/scroll_view.dart index ff4d0aef80e..05037708318 100644 --- a/packages/flutter/lib/src/widgets/scroll_view.dart +++ b/packages/flutter/lib/src/widgets/scroll_view.dart @@ -182,13 +182,8 @@ abstract class ScrollView extends StatelessWidget { case Axis.horizontal: final TextDirection textDirection = Directionality.of(context); assert(textDirection != null); - switch (textDirection) { - case TextDirection.rtl: - return reverse ? AxisDirection.right : AxisDirection.left; - case TextDirection.ltr: - return reverse ? AxisDirection.left : AxisDirection.right; - } - return null; + final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection); + return reverse ? flipAxisDirection(axisDirection) : axisDirection; case Axis.vertical: return reverse ? AxisDirection.up : AxisDirection.down; } diff --git a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart index f2da73dba6a..361a9736428 100644 --- a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart @@ -119,13 +119,8 @@ class SingleChildScrollView extends StatelessWidget { case Axis.horizontal: final TextDirection textDirection = Directionality.of(context); assert(textDirection != null); - switch (textDirection) { - case TextDirection.rtl: - return reverse ? AxisDirection.right : AxisDirection.left; - case TextDirection.ltr: - return reverse ? AxisDirection.left : AxisDirection.right; - } - return null; + final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection); + return reverse ? flipAxisDirection(axisDirection) : axisDirection; case Axis.vertical: return reverse ? AxisDirection.up : AxisDirection.down; } diff --git a/packages/flutter/lib/src/widgets/viewport.dart b/packages/flutter/lib/src/widgets/viewport.dart index 8873f5a4848..b7cdfb5cc2c 100644 --- a/packages/flutter/lib/src/widgets/viewport.dart +++ b/packages/flutter/lib/src/widgets/viewport.dart @@ -5,12 +5,28 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; +import 'basic.dart'; import 'framework.dart'; export 'package:flutter/rendering.dart' show AxisDirection, 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. /// /// [Viewport] is the visual workhorse of the scrolling machinery. It displays a @@ -52,6 +68,7 @@ class Viewport extends MultiChildRenderObjectWidget { Viewport({ Key key, this.axisDirection: AxisDirection.down, + this.crossAxisDirection, this.anchor: 0.0, @required this.offset, this.center, @@ -68,6 +85,17 @@ class Viewport extends MultiChildRenderObjectWidget { /// bottom of the viewport. 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. /// /// For example, if [anchor] is 0.5 and the [axisDirection] is @@ -100,6 +128,7 @@ class Viewport extends MultiChildRenderObjectWidget { RenderViewport createRenderObject(BuildContext context) { return new RenderViewport( axisDirection: axisDirection, + crossAxisDirection: crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection), anchor: anchor, offset: offset, ); @@ -107,9 +136,11 @@ class Viewport extends MultiChildRenderObjectWidget { @override void updateRenderObject(BuildContext context, RenderViewport renderObject) { - renderObject.axisDirection = axisDirection; - renderObject.anchor = anchor; - renderObject.offset = offset; + renderObject + ..axisDirection = axisDirection + ..crossAxisDirection = crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection) + ..anchor = anchor + ..offset = offset; } @override @@ -119,6 +150,7 @@ class Viewport extends MultiChildRenderObjectWidget { void debugFillProperties(DiagnosticPropertiesBuilder description) { super.debugFillProperties(description); description.add(new EnumProperty('axisDirection', axisDirection)); + description.add(new EnumProperty('crossAxisDirection', crossAxisDirection, defaultValue: null)); description.add(new DoubleProperty('anchor', anchor)); description.add(new DiagnosticsProperty('offset', offset)); if (center != null) { @@ -201,6 +233,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { ShrinkWrappingViewport({ Key key, this.axisDirection: AxisDirection.down, + this.crossAxisDirection, @required this.offset, List slivers: const [], }) : assert(offset != null), @@ -213,6 +246,17 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { /// bottom of the viewport. 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. /// /// The [ViewportOffset.pixels] value determines the scroll offset that the @@ -227,6 +271,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { RenderShrinkWrappingViewport createRenderObject(BuildContext context) { return new RenderShrinkWrappingViewport( axisDirection: axisDirection, + crossAxisDirection: crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection), offset: offset, ); } @@ -235,6 +280,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { void updateRenderObject(BuildContext context, RenderShrinkWrappingViewport renderObject) { renderObject ..axisDirection = axisDirection + ..crossAxisDirection = crossAxisDirection ?? _getDefaultCrossAxisDirection(context, axisDirection) ..offset = offset; } @@ -242,6 +288,7 @@ class ShrinkWrappingViewport extends MultiChildRenderObjectWidget { void debugFillProperties(DiagnosticPropertiesBuilder description) { super.debugFillProperties(description); description.add(new EnumProperty('axisDirection', axisDirection)); + description.add(new EnumProperty('crossAxisDirection', crossAxisDirection, defaultValue: null)); description.add(new DiagnosticsProperty('offset', offset)); } } diff --git a/packages/flutter/test/material/ink_well_test.dart b/packages/flutter/test/material/ink_well_test.dart index a7d9c57c854..f2d4c6a4781 100644 --- a/packages/flutter/test/material/ink_well_test.dart +++ b/packages/flutter/test/material/ink_well_test.dart @@ -121,19 +121,24 @@ void main() { testWidgets('splashing survives scrolling when keep-alive is enabled', (WidgetTester tester) async { Future runTest(bool keepAlive) async { - await tester.pumpWidget(new Material( - child: new CompositedTransformFollower( // forces a layer, which makes the paints easier to separate out - link: new LayerLink(), - child: new ListView( - addAutomaticKeepAlives: keepAlive, - children: [ - new Container(height: 500.0, child: new InkWell(onTap: () { }, child: const Placeholder())), - new Container(height: 500.0), - new Container(height: 500.0), - ], + 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 + link: new LayerLink(), + child: new ListView( + addAutomaticKeepAlives: keepAlive, + children: [ + new Container(height: 500.0, child: new InkWell(onTap: () { }, child: const Placeholder())), + new Container(height: 500.0), + new Container(height: 500.0), + ], + ), + ), ), ), - )); + ); expect(tester.renderObject(find.byType(PhysicalModel)).child, paintsNothing); await tester.tap(find.byType(InkWell)); await tester.pump(); diff --git a/packages/flutter/test/material/material_test.dart b/packages/flutter/test/material/material_test.dart index d4e0c29cd90..1be03128af5 100644 --- a/packages/flutter/test/material/material_test.dart +++ b/packages/flutter/test/material/material_test.dart @@ -60,41 +60,44 @@ void main() { final List log = []; await tester.pumpWidget( - new Column( - children: [ - new SizedBox( - width: 150.0, - height: 150.0, - child: new CustomPaint( - painter: new PaintRecorder(log), - ), - ), - new Expanded( - child: new Material( - child: new Column( - children: [ - new Expanded( - child: new ListView( - children: [ - new Container( - height: 2000.0, - color: const Color(0xFF00FF00), - ), - ], - ), - ), - new SizedBox( - width: 100.0, - height: 100.0, - child: new CustomPaint( - painter: new PaintRecorder(log), - ), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new Column( + children: [ + new SizedBox( + width: 150.0, + height: 150.0, + child: new CustomPaint( + painter: new PaintRecorder(log), ), ), - ), - ], + new Expanded( + child: new Material( + child: new Column( + children: [ + new Expanded( + child: new ListView( + children: [ + new Container( + height: 2000.0, + color: const Color(0xFF00FF00), + ), + ], + ), + ), + new SizedBox( + width: 100.0, + height: 100.0, + child: new CustomPaint( + painter: new PaintRecorder(log), + ), + ), + ], + ), + ), + ), + ], + ), ), ); diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index 32abf9f9ca5..b60a67fb1ad 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -23,16 +23,19 @@ void main() { testWidgets('RefreshIndicator', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: refresh, - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: ['A', 'B', 'C', 'D', 'E', 'F'].map((String item) { - return new SizedBox( - height: 200.0, - child: new Text(item), - ); - }).toList(), + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: refresh, + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: ['A', 'B', 'C', 'D', 'E', 'F'].map((String item) { + return new SizedBox( + height: 200.0, + child: new Text(item), + ); + }).toList(), + ), ), ), ); @@ -48,17 +51,20 @@ void main() { testWidgets('RefreshIndicator - bottom', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: refresh, - child: new ListView( - reverse: true, - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: refresh, + child: new ListView( + reverse: true, + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -74,16 +80,19 @@ void main() { testWidgets('RefreshIndicator - top - position', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: holdRefresh, - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: holdRefresh, + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -98,17 +107,20 @@ void main() { testWidgets('RefreshIndicator - bottom - position', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: holdRefresh, - child: new ListView( - reverse: true, - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: holdRefresh, + child: new ListView( + reverse: true, + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -123,16 +135,19 @@ void main() { testWidgets('RefreshIndicator - no movement', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: refresh, - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: refresh, + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -149,16 +164,19 @@ void main() { testWidgets('RefreshIndicator - not enough', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: refresh, - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: refresh, + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -174,16 +192,19 @@ void main() { testWidgets('RefreshIndicator - show - slow', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: holdRefresh, // this one never returns - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: holdRefresh, // this one never returns + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -215,16 +236,19 @@ void main() { testWidgets('RefreshIndicator - show - fast', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: refresh, - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: refresh, + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); @@ -257,16 +281,19 @@ void main() { testWidgets('RefreshIndicator - show - fast - twice', (WidgetTester tester) async { refreshCalled = false; await tester.pumpWidget( - new RefreshIndicator( - onRefresh: refresh, - child: new ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: [ - const SizedBox( - height: 200.0, - child: const Text('X'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new RefreshIndicator( + onRefresh: refresh, + child: new ListView( + physics: const AlwaysScrollableScrollPhysics(), + children: [ + const SizedBox( + height: 200.0, + child: const Text('X'), + ), + ], + ), ), ), ); diff --git a/packages/flutter/test/rendering/debug_test.dart b/packages/flutter/test/rendering/debug_test.dart index 726d27d21d6..20e8d26c436 100644 --- a/packages/flutter/test/rendering/debug_test.dart +++ b/packages/flutter/test/rendering/debug_test.dart @@ -79,6 +79,7 @@ void main() { RenderSliver s; RenderBox b; final RenderViewport root = new RenderViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ s = new RenderSliverPadding( @@ -106,6 +107,7 @@ void main() { final RenderBox b = new RenderPadding( padding: const EdgeInsets.all(10.0), child: new RenderViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ s = new RenderSliverPadding( diff --git a/packages/flutter/test/rendering/slivers_block_test.dart b/packages/flutter/test/rendering/slivers_block_test.dart index aee0b6521b3..1d3897b75ee 100644 --- a/packages/flutter/test/rendering/slivers_block_test.dart +++ b/packages/flutter/test/rendering/slivers_block_test.dart @@ -78,6 +78,7 @@ void main() { ); final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.down, + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ inner = childManager.createRenderObject(), @@ -152,6 +153,7 @@ void main() { ); final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.up, + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ inner = childManager.createRenderObject(), @@ -226,6 +228,7 @@ void main() { ); final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.down, + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ inner = childManager.createRenderObject(), diff --git a/packages/flutter/test/rendering/slivers_helpers_test.dart b/packages/flutter/test/rendering/slivers_helpers_test.dart index aa32367cf49..2725ccc93f5 100644 --- a/packages/flutter/test/rendering/slivers_helpers_test.dart +++ b/packages/flutter/test/rendering/slivers_helpers_test.dart @@ -25,6 +25,7 @@ void main() { overlap: 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 0.0, + crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 0.0, ); final SliverConstraints b = a.copyWith(); @@ -52,6 +53,7 @@ void main() { overlap: 20.0, remainingPaintExtent: 30.0, crossAxisExtent: 40.0, + crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 30.0, ); expect(c, equals(d)); diff --git a/packages/flutter/test/rendering/slivers_layout_test.dart b/packages/flutter/test/rendering/slivers_layout_test.dart index 2533a1f5d2c..00550c0afbc 100644 --- a/packages/flutter/test/rendering/slivers_layout_test.dart +++ b/packages/flutter/test/rendering/slivers_layout_test.dart @@ -25,6 +25,7 @@ void main() { RenderBox box; final RenderObject root = new RenderLayoutWatcher( viewport = new RenderViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ sliver = new RenderSliverToBoxAdapter(child: box = new RenderSizedBox(const Size(100.0, 400.0))), diff --git a/packages/flutter/test/rendering/slivers_test.dart b/packages/flutter/test/rendering/slivers_test.dart index 1fbfde0a1f9..91b05dca2aa 100644 --- a/packages/flutter/test/rendering/slivers_test.dart +++ b/packages/flutter/test/rendering/slivers_test.dart @@ -11,6 +11,7 @@ import 'rendering_tester.dart'; void main() { test('RenderViewport basic test - no children', () { final RenderViewport root = new RenderViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), ); expect(root, hasAGoodToStringDeep); @@ -22,6 +23,7 @@ void main() { ' constraints: null\n' ' size: MISSING\n' ' axisDirection: down\n' + ' crossAxisDirection: right\n' ' offset: _FixedViewportOffset#00000(offset: 0.0)\n' ' anchor: 0.0\n' ), @@ -37,6 +39,7 @@ void main() { ' constraints: BoxConstraints(w=800.0, h=600.0)\n' ' size: Size(800.0, 600.0)\n' ' axisDirection: down\n' + ' crossAxisDirection: right\n' ' offset: _FixedViewportOffset#00000(offset: 900.0)\n' ' anchor: 0.0\n', ), @@ -48,6 +51,7 @@ void main() { test('RenderViewport basic test - down', () { RenderBox a, b, c, d, e; final RenderViewport root = new RenderViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), @@ -72,6 +76,7 @@ void main() { ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' ' │ axisDirection: down\n' + ' │ crossAxisDirection: right\n' ' │ offset: _FixedViewportOffset#00000(offset: 0.0)\n' ' │ anchor: 0.0\n' ' │\n' @@ -80,6 +85,7 @@ void main() { ' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ │ crossAxisDirection: AxisDirection.right,\n' ' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, paintExtent: 400.0,\n' ' │ │ maxPaintExtent: 400.0)\n' @@ -94,6 +100,7 @@ void main() { ' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ 0.0, remainingPaintExtent: 200.0, crossAxisExtent: 800.0,\n' + ' │ │ crossAxisDirection: AxisDirection.right,\n' ' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, paintExtent: 200.0,\n' ' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' @@ -108,6 +115,7 @@ void main() { ' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n' + ' │ │ crossAxisDirection: AxisDirection.right,\n' ' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n' ' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' @@ -122,6 +130,7 @@ void main() { ' │ │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n' + ' │ │ crossAxisDirection: AxisDirection.right,\n' ' │ │ viewportMainAxisExtent: 600.0)\n' ' │ │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n' ' │ │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' @@ -136,6 +145,7 @@ void main() { ' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ 0.0, remainingPaintExtent: 0.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' ' │ viewportMainAxisExtent: 600.0)\n' ' │ geometry: SliverGeometry(scrollExtent: 400.0, hidden,\n' ' │ maxPaintExtent: 400.0, hasVisualOverflow: true)\n' @@ -143,7 +153,7 @@ void main() { ' └─child: RenderSizedBox#00000 NEEDS-PAINT\n' ' parentData: paintOffset=Offset(0.0, -0.0) (can use size)\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)); @@ -191,6 +201,7 @@ void main() { RenderBox a, b, c, d, e; final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.up, + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), @@ -249,6 +260,7 @@ void main() { RenderBox a, b, c, d, e; final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.right, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), @@ -332,6 +344,7 @@ void main() { RenderBox a, b, c, d, e; final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.left, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), @@ -387,6 +400,7 @@ void main() { test('RenderShrinkWrappingViewport basic test - no children', () { final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), ); expect(root, hasAGoodToStringDeep); @@ -398,6 +412,7 @@ void main() { test('RenderShrinkWrappingViewport basic test - down', () { RenderBox a, b, c, d, e; final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), @@ -457,6 +472,7 @@ void main() { RenderBox a, b, c, d, e; final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( axisDirection: AxisDirection.up, + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(100.0, 400.0))), @@ -510,6 +526,7 @@ void main() { RenderBox a, b, c, d, e; final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( axisDirection: AxisDirection.right, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), @@ -563,6 +580,7 @@ void main() { RenderBox a, b, c, d, e; final RenderShrinkWrappingViewport root = new RenderShrinkWrappingViewport( axisDirection: AxisDirection.left, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.zero(), children: [ new RenderSliverToBoxAdapter(child: a = new RenderSizedBox(const Size(400.0, 100.0))), @@ -617,6 +635,7 @@ void main() { final RenderBox root = new RenderPositionedBox( child: child = new RenderShrinkWrappingViewport( axisDirection: AxisDirection.left, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.fixed(200.0), children: [ new RenderSliverToBoxAdapter(child: new RenderSizedBox(const Size(400.0, 100.0))), @@ -636,6 +655,7 @@ void main() { final RenderBox root = new RenderPositionedBox( child: child = new RenderShrinkWrappingViewport( axisDirection: AxisDirection.right, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.fixed(200.0), children: [ new RenderSliverToBoxAdapter(child: new RenderSizedBox(const Size(300.0, 100.0))), @@ -687,6 +707,7 @@ void main() { ); final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.down, + crossAxisDirection: AxisDirection.right, offset: new ViewportOffset.zero(), children: [ sliver, @@ -708,6 +729,7 @@ void main() { ); final RenderViewport root = new RenderViewport( axisDirection: AxisDirection.right, + crossAxisDirection: AxisDirection.down, offset: new ViewportOffset.zero(), children: [ sliver, diff --git a/packages/flutter/test/widgets/animated_list_test.dart b/packages/flutter/test/widgets/animated_list_test.dart index 48805624d43..54e81672e00 100644 --- a/packages/flutter/test/widgets/animated_list_test.dart +++ b/packages/flutter/test/widgets/animated_list_test.dart @@ -10,17 +10,20 @@ void main() { final Map> animations = >{}; await tester.pumpWidget( - new AnimatedList( - initialItemCount: 2, - itemBuilder: (BuildContext context, int index, Animation animation) { - animations[index] = animation; - return new SizedBox( - height: 100.0, - child: new Center( - child: new Text('item $index'), - ), - ); - }, + new Directionality( + textDirection: TextDirection.ltr, + child: new AnimatedList( + initialItemCount: 2, + itemBuilder: (BuildContext context, int index, Animation animation) { + animations[index] = animation; + return new SizedBox( + height: 100.0, + child: new Center( + child: new Text('item $index'), + ), + ); + }, + ), ), ); @@ -36,21 +39,24 @@ void main() { final GlobalKey listKey = new GlobalKey(); await tester.pumpWidget( - new AnimatedList( - key: listKey, - itemBuilder: (BuildContext context, int index, Animation animation) { - return new SizeTransition( - key: new ValueKey(index), - axis: Axis.vertical, - sizeFactor: animation, - child: new SizedBox( - height: 100.0, - child: new Center( - child: new Text('item $index'), + new Directionality( + textDirection: TextDirection.ltr, + child: new AnimatedList( + key: listKey, + itemBuilder: (BuildContext context, int index, Animation animation) { + return new SizeTransition( + key: new ValueKey(index), + axis: Axis.vertical, + sizeFactor: animation, + child: new SizedBox( + height: 100.0, + child: new Center( + child: new Text('item $index'), + ), ), - ), - ); - }, + ); + }, + ), ), ); @@ -122,12 +128,15 @@ void main() { } await tester.pumpWidget( - new AnimatedList( - key: listKey, - initialItemCount: 3, - itemBuilder: (BuildContext context, int index, Animation animation) { - return buildItem(context, items[index], animation); - }, + new Directionality( + textDirection: TextDirection.ltr, + child: new AnimatedList( + key: listKey, + initialItemCount: 3, + itemBuilder: (BuildContext context, int index, Animation animation) { + return buildItem(context, items[index], animation); + }, + ), ), ); diff --git a/packages/flutter/test/widgets/automatic_keep_alive_test.dart b/packages/flutter/test/widgets/automatic_keep_alive_test.dart index 8b73f9fae56..40dbd8471a7 100644 --- a/packages/flutter/test/widgets/automatic_keep_alive_test.dart +++ b/packages/flutter/test/widgets/automatic_keep_alive_test.dart @@ -65,12 +65,17 @@ List generateList(Widget child, { @required bool impliedMode }) { void tests({ @required bool impliedMode }) { testWidgets('AutomaticKeepAlive with ListView with itemExtent', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - addAutomaticKeepAlives: impliedMode, - addRepaintBoundaries: impliedMode, - itemExtent: 12.3, // about 50 widgets visible - children: generateList(const Placeholder(), impliedMode: impliedMode), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: impliedMode, + addRepaintBoundaries: impliedMode, + itemExtent: 12.3, // about 50 widgets visible + children: generateList(const Placeholder(), impliedMode: impliedMode), + ), + ), + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); @@ -105,14 +110,19 @@ void tests({ @required bool impliedMode }) { }); testWidgets('AutomaticKeepAlive with ListView without itemExtent', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - addAutomaticKeepAlives: impliedMode, - addRepaintBoundaries: impliedMode, - children: generateList( - new Container(height: 12.3, child: const Placeholder()), // about 50 widgets visible - impliedMode: impliedMode, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: impliedMode, + addRepaintBoundaries: impliedMode, + children: generateList( + new Container(height: 12.3, child: const Placeholder()), // about 50 widgets visible + impliedMode: impliedMode, + ), + ), ), - )); + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); @@ -147,16 +157,21 @@ void tests({ @required bool impliedMode }) { }); testWidgets('AutomaticKeepAlive with GridView', (WidgetTester tester) async { - await tester.pumpWidget(new GridView.count( - addAutomaticKeepAlives: impliedMode, - addRepaintBoundaries: impliedMode, - crossAxisCount: 2, - childAspectRatio: 400.0 / 24.6, // about 50 widgets visible - children: generateList( - new Container(child: const Placeholder()), - impliedMode: impliedMode, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + addAutomaticKeepAlives: impliedMode, + addRepaintBoundaries: impliedMode, + crossAxisCount: 2, + childAspectRatio: 400.0 / 24.6, // about 50 widgets visible + children: generateList( + new Container(child: const Placeholder()), + impliedMode: impliedMode, + ), + ), ), - )); + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); @@ -196,36 +211,38 @@ void main() { group('Implied automatic keep-alive', () { tests(impliedMode: true); }); testWidgets('AutomaticKeepAlive double', (WidgetTester tester) async { - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new ListView( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - children: [ - new AutomaticKeepAlive( - child: new Container( - height: 400.0, - child: new Row(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + children: [ + new AutomaticKeepAlive( + child: new Container( + height: 400.0, + child: new Row(children: [ + new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), + new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), + ]), + ), ), - ), - new AutomaticKeepAlive( - child: new Container( - key: const GlobalObjectKey<_LeafState>(2), - height: 400.0, + new AutomaticKeepAlive( + child: new Container( + key: const GlobalObjectKey<_LeafState>(2), + height: 400.0, + ), ), - ), - new AutomaticKeepAlive( - child: new Container( - key: const GlobalObjectKey<_LeafState>(3), - height: 400.0, + new AutomaticKeepAlive( + child: new Container( + key: const GlobalObjectKey<_LeafState>(3), + height: 400.0, + ), ), - ), - ], + ], + ), ), - )); + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(0)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(1)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(2)), findsOneWidget); @@ -270,42 +287,44 @@ void main() { }); testWidgets('AutomaticKeepAlive double', (WidgetTester tester) async { - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new ListView( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - children: [ - new AutomaticKeepAlive( - child: new Container( - height: 400.0, - child: new Row(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + children: [ + new AutomaticKeepAlive( + child: new Container( + height: 400.0, + child: new Row(children: [ + new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), + new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), + ]), + ), ), - ), - new AutomaticKeepAlive( - child: new Container( - height: 400.0, - child: new Row(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), - ]), + new AutomaticKeepAlive( + child: new Container( + height: 400.0, + child: new Row(children: [ + new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), + new Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), + ]), + ), ), - ), - new AutomaticKeepAlive( - child: new Container( - height: 400.0, - child: new Row(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), - ]), + new AutomaticKeepAlive( + child: new Container( + height: 400.0, + child: new Row(children: [ + new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), + new Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), + ]), + ), ), - ), - ], + ], + ), ), - )); + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(0)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(1)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(2)), findsOneWidget); diff --git a/packages/flutter/test/widgets/box_sliver_mismatch_test.dart b/packages/flutter/test/widgets/box_sliver_mismatch_test.dart index 7fdd57b2cf2..98278719966 100644 --- a/packages/flutter/test/widgets/box_sliver_mismatch_test.dart +++ b/packages/flutter/test/widgets/box_sliver_mismatch_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; void main() { @@ -33,24 +34,28 @@ void main() { testWidgets('Box in a sliver', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( + new Viewport( + crossAxisDirection: AxisDirection.right, + offset: new ViewportOffset.zero(), slivers: [ const SizedBox(), ], - ) + ), ); expect(tester.takeException(), isFlutterError); await tester.pumpWidget( - new CustomScrollView( + new Viewport( + crossAxisDirection: AxisDirection.right, + offset: new ViewportOffset.zero(), slivers: [ const SliverPadding( padding: EdgeInsets.zero, sliver: const SizedBox(), ), ], - ) + ), ); expect(tester.takeException(), isFlutterError); diff --git a/packages/flutter/test/widgets/center_test.dart b/packages/flutter/test/widgets/center_test.dart index 4364f28a3b9..7daba7cb7e0 100644 --- a/packages/flutter/test/widgets/center_test.dart +++ b/packages/flutter/test/widgets/center_test.dart @@ -7,6 +7,11 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { - await tester.pumpWidget(new ListView(children: [const Center()])); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView(children: [const Center()]) + ), + ); }); } diff --git a/packages/flutter/test/widgets/container_test.dart b/packages/flutter/test/widgets/container_test.dart index e438a2f7874..f815c225298 100644 --- a/packages/flutter/test/widgets/container_test.dart +++ b/packages/flutter/test/widgets/container_test.dart @@ -135,6 +135,11 @@ void main() { }); testWidgets('Can be placed in an infinite box', (WidgetTester tester) async { - await tester.pumpWidget(new ListView(children: [new Container()])); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView(children: [new Container()]), + ), + ); }); } diff --git a/packages/flutter/test/widgets/date_picker_test.dart b/packages/flutter/test/widgets/date_picker_test.dart index b083ba37893..7416d300101 100644 --- a/packages/flutter/test/widgets/date_picker_test.dart +++ b/packages/flutter/test/widgets/date_picker_test.dart @@ -9,19 +9,22 @@ void main() { testWidgets('Can select a day', (WidgetTester tester) async { DateTime currentValue; - final Widget widget = new Material( - child: new ListView( - children: [ - new MonthPicker( - selectedDate: new DateTime.utc(2015, 6, 9, 7, 12), - firstDate: new DateTime.utc(2013), - lastDate: new DateTime.utc(2018), - onChanged: (DateTime dateTime) { - currentValue = dateTime; - } - ) - ] - ) + final Widget widget = new Directionality( + textDirection: TextDirection.ltr, + child: new Material( + child: new ListView( + children: [ + new MonthPicker( + selectedDate: new DateTime.utc(2015, 6, 9, 7, 12), + firstDate: new DateTime.utc(2013), + lastDate: new DateTime.utc(2018), + onChanged: (DateTime dateTime) { + currentValue = dateTime; + }, + ), + ], + ), + ), ); await tester.pumpWidget(widget); diff --git a/packages/flutter/test/widgets/ensure_visible_test.dart b/packages/flutter/test/widgets/ensure_visible_test.dart index 8b80ada17fa..bf2cf90c324 100644 --- a/packages/flutter/test/widgets/ensure_visible_test.dart +++ b/packages/flutter/test/widgets/ensure_visible_test.dart @@ -387,29 +387,34 @@ void main() { ); } - await tester.pumpWidget(new Center( - child: new SizedBox( - width: 600.0, - height: 400.0, - child: new Scrollable( - viewportBuilder: (BuildContext context, ViewportOffset offset) { - return new Viewport( - offset: offset, - center: const ValueKey(4), - slivers: [ - buildSliver(0), - buildSliver(1), - buildSliver(2), - buildSliver(3), - buildSliver(4), - buildSliver(5), - buildSliver(6), - ], - ); - }, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new SizedBox( + width: 600.0, + height: 400.0, + child: new Scrollable( + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return new Viewport( + offset: offset, + center: const ValueKey(4), + slivers: [ + buildSliver(0), + buildSliver(1), + buildSliver(2), + buildSliver(3), + buildSliver(4), + buildSliver(5), + buildSliver(6), + ], + ); + }, + ), + ), ), ), - )); + ); await prepare(-125.0); Scrollable.ensureVisible(findContext(3)); @@ -628,35 +633,40 @@ void main() { await tester.pump(); } - await tester.pumpWidget(new Center( - child: new SizedBox( - width: 600.0, - height: 400.0, - child: new Scrollable( - viewportBuilder: (BuildContext context, ViewportOffset offset) { - return new Viewport( - offset: offset, - center: const ValueKey('center'), - slivers: [ - new SliverToBoxAdapter(child: new Container(key: const ValueKey(-6), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(-5), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(-4), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(-3), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(-2), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(-1), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(0), width: 200.0, height: 200.0), key: const ValueKey('center')), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(1), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(2), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(3), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(4), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(5), width: 200.0, height: 200.0)), - new SliverToBoxAdapter(child: new Container(key: const ValueKey(6), width: 200.0, height: 200.0)), - ], - ); - }, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new SizedBox( + width: 600.0, + height: 400.0, + child: new Scrollable( + viewportBuilder: (BuildContext context, ViewportOffset offset) { + return new Viewport( + offset: offset, + center: const ValueKey('center'), + slivers: [ + new SliverToBoxAdapter(child: new Container(key: const ValueKey(-6), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(-5), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(-4), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(-3), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(-2), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(-1), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(0), width: 200.0, height: 200.0), key: const ValueKey('center')), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(1), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(2), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(3), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(4), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(5), width: 200.0, height: 200.0)), + new SliverToBoxAdapter(child: new Container(key: const ValueKey(6), width: 200.0, height: 200.0)), + ], + ); + }, + ), + ), ), ), - )); + ); await prepare(480.0); Scrollable.ensureVisible(findContext(3)); diff --git a/packages/flutter/test/widgets/form_test.dart b/packages/flutter/test/widgets/form_test.dart index 4b7cde472aa..2b83611ff59 100644 --- a/packages/flutter/test/widgets/form_test.dart +++ b/packages/flutter/test/widgets/form_test.dart @@ -118,20 +118,23 @@ void main() { String errorText(String input) => fieldKey.currentState.value?.toString() + '/error'; Widget builder() { - return new Center( - child: new Material( - child: new Form( - key: formKey, - autovalidate: true, - child: new ListView( - children: [ - new TextFormField( - key: fieldKey, - ), - new TextFormField( - validator: errorText, - ), - ], + return new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new Material( + child: new Form( + key: formKey, + autovalidate: true, + child: new ListView( + children: [ + new TextFormField( + key: fieldKey, + ), + new TextFormField( + validator: errorText, + ), + ], + ), ), ), ), diff --git a/packages/flutter/test/widgets/grid_view_layout_test.dart b/packages/flutter/test/widgets/grid_view_layout_test.dart index 4645ed1996b..e0aea01190a 100644 --- a/packages/flutter/test/widgets/grid_view_layout_test.dart +++ b/packages/flutter/test/widgets/grid_view_layout_test.dart @@ -14,16 +14,21 @@ void main() { const DecoratedBox(decoration: const BoxDecoration()), ]; - await tester.pumpWidget(new Center( - child: new Container( - width: 200.0, - child: new GridView.extent( - maxCrossAxisExtent: 100.0, - shrinkWrap: true, - children: children, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new Container( + width: 200.0, + child: new GridView.extent( + maxCrossAxisExtent: 100.0, + shrinkWrap: true, + children: children, + ), + ), ), ), - )); + ); expect(tester.renderObjectList(find.byType(DecoratedBox)), hasLength(4)); @@ -38,16 +43,21 @@ void main() { expect(grid.debugNeedsLayout, false); - await tester.pumpWidget(new Center( - child: new Container( - width: 200.0, - child: new GridView.extent( - maxCrossAxisExtent: 60.0, - shrinkWrap: true, - children: children, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new Container( + width: 200.0, + child: new GridView.extent( + maxCrossAxisExtent: 60.0, + shrinkWrap: true, + children: children, + ), + ), ), ), - )); + ); for (RenderBox box in tester.renderObjectList(find.byType(DecoratedBox))) { expect(box.size.width, equals(50.0), reason: "child width"); diff --git a/packages/flutter/test/widgets/grid_view_test.dart b/packages/flutter/test/widgets/grid_view_test.dart index ae08d9b5c5f..145e7ee162c 100644 --- a/packages/flutter/test/widgets/grid_view_test.dart +++ b/packages/flutter/test/widgets/grid_view_test.dart @@ -10,29 +10,39 @@ import 'states.dart'; void main() { testWidgets('Empty GridView', (WidgetTester tester) async { - await tester.pumpWidget(new GridView.count( - crossAxisCount: 4, - children: const [], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + crossAxisCount: 4, + children: const [], + ), + ), + ); }); testWidgets('GridView.count control test', (WidgetTester tester) async { final List log = []; - await tester.pumpWidget(new GridView.count( - crossAxisCount: 4, - children: kStates.map((String state) { - return new GestureDetector( - onTap: () { - log.add(state); - }, - child: new Container( - color: const Color(0xFF0000FF), - child: new Text(state), - ), - ); - }).toList(), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + crossAxisCount: 4, + children: kStates.map((String state) { + return new GestureDetector( + onTap: () { + log.add(state); + }, + child: new Container( + color: const Color(0xFF0000FF), + child: new Text(state), + ), + ); + }).toList(), + ), + ), + ); expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0))); @@ -85,20 +95,25 @@ void main() { testWidgets('GridView.extent control test', (WidgetTester tester) async { final List log = []; - await tester.pumpWidget(new GridView.extent( - maxCrossAxisExtent: 200.0, - children: kStates.map((String state) { - return new GestureDetector( - onTap: () { - log.add(state); - }, - child: new Container( - color: const Color(0xFF0000FF), - child: new Text(state), - ), - ); - }).toList(), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.extent( + maxCrossAxisExtent: 200.0, + children: kStates.map((String state) { + return new GestureDetector( + onTap: () { + log.add(state); + }, + child: new Container( + color: const Color(0xFF0000FF), + child: new Text(state), + ), + ); + }).toList(), + ), + ), + ); expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0))); @@ -126,24 +141,26 @@ void main() { testWidgets('GridView large scroll jump', (WidgetTester tester) async { final List log = []; - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new GridView.extent( - scrollDirection: Axis.horizontal, - maxCrossAxisExtent: 200.0, - childAspectRatio: 0.75, - children: new List.generate(80, (int i) { - return new Builder( - builder: (BuildContext context) { - log.add(i); - return new Container( - child: new Text('$i'), - ); - } - ); - }), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.extent( + scrollDirection: Axis.horizontal, + maxCrossAxisExtent: 200.0, + childAspectRatio: 0.75, + children: new List.generate(80, (int i) { + return new Builder( + builder: (BuildContext context) { + log.add(i); + return new Container( + child: new Text('$i'), + ); + } + ); + }), + ), ), - )); + ); expect(tester.getSize(find.text('4')), equals(const Size(200.0 / 0.75, 200.0))); @@ -154,7 +171,6 @@ void main() { ])); log.clear(); - final ScrollableState state = tester.state(find.byType(Scrollable)); final ScrollPosition position = state.position; position.jumpTo(3025.0); @@ -188,20 +204,23 @@ void main() { final List log = []; await tester.pumpWidget( - new GridView( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 4, + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, + ), + children: new List.generate(40, (int i) { + return new Builder( + builder: (BuildContext context) { + log.add(i); + return new Container( + child: new Text('$i'), + ); + } + ); + }), ), - children: new List.generate(40, (int i) { - return new Builder( - builder: (BuildContext context) { - log.add(i); - return new Container( - child: new Text('$i'), - ); - } - ); - }), ), ); @@ -215,20 +234,23 @@ void main() { log.clear(); await tester.pumpWidget( - new GridView( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + ), + children: new List.generate(40, (int i) { + return new Builder( + builder: (BuildContext context) { + log.add(i); + return new Container( + child: new Text('$i'), + ); + } + ); + }), ), - children: new List.generate(40, (int i) { - return new Builder( - builder: (BuildContext context) { - log.add(i); - return new Container( - child: new Text('$i'), - ); - } - ); - }), ), ); @@ -247,20 +269,23 @@ void main() { final List log = []; await tester.pumpWidget( - new GridView( - gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( - maxCrossAxisExtent: 200.0, + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView( + gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 200.0, + ), + children: new List.generate(40, (int i) { + return new Builder( + builder: (BuildContext context) { + log.add(i); + return new Container( + child: new Text('$i'), + ); + } + ); + }), ), - children: new List.generate(40, (int i) { - return new Builder( - builder: (BuildContext context) { - log.add(i); - return new Container( - child: new Text('$i'), - ); - } - ); - }), ), ); @@ -274,20 +299,23 @@ void main() { log.clear(); await tester.pumpWidget( - new GridView( - gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( - maxCrossAxisExtent: 400.0, + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView( + gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 400.0, + ), + children: new List.generate(40, (int i) { + return new Builder( + builder: (BuildContext context) { + log.add(i); + return new Container( + child: new Text('$i'), + ); + } + ); + }), ), - children: new List.generate(40, (int i) { - return new Builder( - builder: (BuildContext context) { - log.add(i); - return new Container( - child: new Text('$i'), - ); - } - ); - }), ), ); @@ -311,15 +339,20 @@ void main() { ), ); - await tester.pumpWidget(new Center( - child: new SizedBox( - height: 200.0, - child: new GridView.count( - crossAxisCount: 2, - children: [ container, container, container, container ], + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new SizedBox( + height: 200.0, + child: new GridView.count( + crossAxisCount: 2, + children: [ container, container, container, container ], + ), + ), ), ), - )); + ); 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))); @@ -327,17 +360,20 @@ void main() { testWidgets('GridView in zero context', (WidgetTester tester) async { await tester.pumpWidget( - new Center( - child: new SizedBox( - width: 0.0, - height: 0.0, - child: new GridView.count( - crossAxisCount: 4, - children: new List.generate(20, (int i) { - return new Container( - child: new Text('$i'), - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new SizedBox( + width: 0.0, + height: 0.0, + child: new GridView.count( + crossAxisCount: 4, + children: new List.generate(20, (int i) { + return new Container( + child: new Text('$i'), + ); + }), + ), ), ), ), @@ -349,15 +385,18 @@ void main() { testWidgets('GridView in unbounded context', (WidgetTester tester) async { await tester.pumpWidget( - new SingleChildScrollView( - child: new GridView.count( - crossAxisCount: 4, - shrinkWrap: true, - children: new List.generate(20, (int i) { - return new Container( - child: new Text('$i'), - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new SingleChildScrollView( + child: new GridView.count( + crossAxisCount: 4, + shrinkWrap: true, + children: new List.generate(20, (int i) { + return new Container( + child: new Text('$i'), + ); + }), + ), ), ), ); @@ -367,23 +406,54 @@ void main() { }); testWidgets('GridView.builder control test', (WidgetTester tester) async { - await tester.pumpWidget(new GridView.builder( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 4, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.builder( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, + ), + shrinkWrap: true, + itemCount: 20, + itemBuilder: (BuildContext context, int index) { + return new Container( + child: new Text('$index'), + ); + }, + ), ), - shrinkWrap: true, - itemCount: 20, - itemBuilder: (BuildContext context, int index) { - return new Container( - child: new Text('$index'), - ); - }, - )); + ); expect(find.text('0'), findsOneWidget); expect(find.text('11'), findsOneWidget); 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: [ + 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? // (try it with the flutter_gallery Grid demo) } diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart index f4eea83b9f4..813d9e579bf 100644 --- a/packages/flutter/test/widgets/keep_alive_test.dart +++ b/packages/flutter/test/widgets/keep_alive_test.dart @@ -43,12 +43,17 @@ List generateList(Widget child) { void main() { testWidgets('KeepAlive with ListView with itemExtent', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - itemExtent: 12.3, // about 50 widgets visible - children: generateList(const Placeholder()), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + itemExtent: 12.3, // about 50 widgets visible + children: generateList(const Placeholder()), + ), + ), + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); @@ -83,11 +88,16 @@ void main() { }); testWidgets('KeepAlive with ListView without itemExtent', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - children: generateList(new Container(height: 12.3, child: const Placeholder())), // about 50 widgets visible - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + children: generateList(new Container(height: 12.3, child: const Placeholder())), // about 50 widgets visible + ), + ), + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); @@ -122,13 +132,18 @@ void main() { }); testWidgets('KeepAlive with GridView', (WidgetTester tester) async { - await tester.pumpWidget(new GridView.count( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - crossAxisCount: 2, - childAspectRatio: 400.0 / 24.6, // about 50 widgets visible - children: generateList(new Container(child: const Placeholder())), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + crossAxisCount: 2, + childAspectRatio: 400.0 / 24.6, // about 50 widgets visible + children: generateList(new Container(child: const Placeholder())), + ), + ), + ); expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget); expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsNothing); @@ -163,12 +178,17 @@ void main() { }); testWidgets('KeepAlive render tree description', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - itemExtent: 400.0, // 2 visible children - children: generateList(const Placeholder()), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + itemExtent: 400.0, // 2 visible children + children: generateList(const Placeholder()), + ), + ), + ); // The important lines below are the ones marked with "<----" expect(tester.binding.renderView.toStringDeep(), equalsIgnoringHashCodes( 'RenderView#00000\n' @@ -180,7 +200,8 @@ void main() { ' └─child: RenderRepaintBoundary#00000\n' ' │ creator: RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: \n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ layer: OffsetLayer#00000\n' @@ -192,7 +213,8 @@ void main() { ' └─child: RenderCustomPaint#00000\n' ' │ creator: CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' @@ -200,7 +222,8 @@ void main() { ' └─child: RenderRepaintBoundary#00000\n' ' │ creator: RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ layer: OffsetLayer#00000\n' @@ -214,7 +237,8 @@ void main() { ' │ RawGestureDetector-[LabeledGlobalKey#00000]\n' ' │ ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ semantic boundary\n' @@ -226,7 +250,8 @@ void main() { ' │ RawGestureDetector-[LabeledGlobalKey#00000]\n' ' │ ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' @@ -239,7 +264,8 @@ void main() { ' │ RawGestureDetector-[LabeledGlobalKey#00000]\n' ' │ ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← ⋯\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' @@ -259,6 +285,7 @@ void main() { ' │ layer: OffsetLayer#00000\n' ' │ size: Size(800.0, 600.0)\n' ' │ axisDirection: down\n' + ' │ crossAxisDirection: right\n' ' │ offset: ScrollPositionWithSingleContext#00000(offset: 0.0, range:\n' ' │ 0.0..39400.0, viewport: 600.0, ScrollableState,\n' ' │ AlwaysScrollableScrollPhysics -> ClampingScrollPhysics,\n' @@ -277,6 +304,7 @@ void main() { ' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' ' │ viewportMainAxisExtent: 600.0)\n' ' │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n' ' │ 600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true)\n' @@ -350,7 +378,8 @@ void main() { ' └─child: RenderRepaintBoundary#00000\n' ' │ creator: RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: \n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ layer: OffsetLayer#00000\n' @@ -362,7 +391,8 @@ void main() { ' └─child: RenderCustomPaint#00000\n' ' │ creator: CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' @@ -370,7 +400,8 @@ void main() { ' └─child: RenderRepaintBoundary#00000\n' ' │ creator: RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ layer: OffsetLayer#00000\n' @@ -384,7 +415,8 @@ void main() { ' │ RawGestureDetector-[LabeledGlobalKey#00000]\n' ' │ ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ semantic boundary\n' @@ -396,7 +428,8 @@ void main() { ' │ RawGestureDetector-[LabeledGlobalKey#00000]\n' ' │ ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← [root]\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' @@ -409,7 +442,8 @@ void main() { ' │ RawGestureDetector-[LabeledGlobalKey#00000]\n' ' │ ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←\n' ' │ NotificationListener ←\n' - ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ← [root]\n' + ' │ GlowingOverscrollIndicator ← Scrollable ← ListView ←\n' + ' │ Directionality ← ⋯\n' ' │ parentData: (can use size)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ size: Size(800.0, 600.0)\n' @@ -429,6 +463,7 @@ void main() { ' │ layer: OffsetLayer#00000\n' ' │ size: Size(800.0, 600.0)\n' ' │ axisDirection: down\n' + ' │ crossAxisDirection: right\n' ' │ offset: ScrollPositionWithSingleContext#00000(offset: 2000.0,\n' ' │ range: 0.0..39400.0, viewport: 600.0, ScrollableState,\n' ' │ AlwaysScrollableScrollPhysics -> ClampingScrollPhysics,\n' @@ -447,6 +482,7 @@ void main() { ' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ 2000.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' ' │ viewportMainAxisExtent: 600.0)\n' ' │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n' ' │ 600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true)\n' diff --git a/packages/flutter/test/widgets/linked_scroll_view_test.dart b/packages/flutter/test/widgets/linked_scroll_view_test.dart index 05bd566dff0..c3673374e0a 100644 --- a/packages/flutter/test/widgets/linked_scroll_view_test.dart +++ b/packages/flutter/test/widgets/linked_scroll_view_test.dart @@ -282,80 +282,83 @@ class _TestState extends State { @override Widget build(BuildContext context) { - return new Column( - children: [ - new Expanded( - child: new ListView( - controller: _beforeController, - children: [ - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF90F090), - child: const Center(child: const Text('Hello A')), - ), - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF90F090), - child: const Center(child: const Text('Hello B')), - ), - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF90F090), - child: const Center(child: const Text('Hello C')), - ), - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF90F090), - child: const Center(child: const Text('Hello D')), - ), - ], + return new Directionality( + textDirection: TextDirection.ltr, + child: new Column( + children: [ + new Expanded( + child: new ListView( + controller: _beforeController, + children: [ + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF90F090), + child: const Center(child: const Text('Hello A')), + ), + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF90F090), + child: const Center(child: const Text('Hello B')), + ), + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF90F090), + child: const Center(child: const Text('Hello C')), + ), + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF90F090), + child: const Center(child: const Text('Hello D')), + ), + ], + ), ), - ), - const Divider(), - new Expanded( - child: new ListView( - controller: _afterController, - children: [ - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF9090F0), - child: const Center(child: const Text('Hello 1')), - ), - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF9090F0), - child: const Center(child: const Text('Hello 2')), - ), - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF9090F0), - child: const Center(child: const Text('Hello 3')), - ), - new Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(8.0), - height: 250.0, - color: const Color(0xFF9090F0), - child: const Center(child: const Text('Hello 4')), - ), - ], + const Divider(), + new Expanded( + child: new ListView( + controller: _afterController, + children: [ + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF9090F0), + child: const Center(child: const Text('Hello 1')), + ), + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF9090F0), + child: const Center(child: const Text('Hello 2')), + ), + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF9090F0), + child: const Center(child: const Text('Hello 3')), + ), + new Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + height: 250.0, + color: const Color(0xFF9090F0), + child: const Center(child: const Text('Hello 4')), + ), + ], + ), ), - ), - ], + ], + ), ); } } diff --git a/packages/flutter/test/widgets/list_view_builder_test.dart b/packages/flutter/test/widgets/list_view_builder_test.dart index ef96c6ebd9e..3ccfb611fba 100644 --- a/packages/flutter/test/widgets/list_view_builder_test.dart +++ b/packages/flutter/test/widgets/list_view_builder_test.dart @@ -15,19 +15,22 @@ void main() { // so if our widget is 100 pixels tall, it should fit exactly 6 times. Widget builder() { - return new FlipWidget( - left: new ListView.builder( - itemExtent: 100.0, - itemBuilder: (BuildContext context, int index) { - callbackTracker.add(index); - return new Container( - key: new ValueKey(index), - height: 100.0, - child: new Text('$index'), - ); - }, + return new Directionality( + textDirection: TextDirection.ltr, + child: new FlipWidget( + left: new ListView.builder( + itemExtent: 100.0, + itemBuilder: (BuildContext context, int index) { + callbackTracker.add(index); + return new Container( + key: new ValueKey(index), + height: 100.0, + child: new Text('$index'), + ); + }, + ), + right: const Text('Not Today'), ), - right: const Text('Not Today'), ); } @@ -67,14 +70,17 @@ void main() { ); }; - FlipWidget buildWidget() { - return new FlipWidget( - left: new ListView.builder( - controller: new ScrollController(initialScrollOffset: 300.0), - itemExtent: 200.0, - itemBuilder: itemBuilder, + Widget buildWidget() { + return new Directionality( + textDirection: TextDirection.ltr, + child: new FlipWidget( + left: new ListView.builder( + controller: new ScrollController(initialScrollOffset: 300.0), + itemExtent: 200.0, + itemBuilder: itemBuilder, + ), + right: const Text('Not Today') ), - right: const Text('Not Today') ); } @@ -187,10 +193,13 @@ void main() { return new Text('$index', key: new ValueKey(index)); }; - final Widget testWidget = new ListView.builder( - itemBuilder: itemBuilder, - itemExtent: 300.0, - itemCount: 10, + final Widget testWidget = new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + itemBuilder: itemBuilder, + itemExtent: 300.0, + itemCount: 10, + ), ); void jumpTo(double newScrollOffset) { diff --git a/packages/flutter/test/widgets/list_view_correction_test.dart b/packages/flutter/test/widgets/list_view_correction_test.dart index c1080943a55..7f9c239affa 100644 --- a/packages/flutter/test/widgets/list_view_correction_test.dart +++ b/packages/flutter/test/widgets/list_view_correction_test.dart @@ -8,34 +8,44 @@ import 'package:flutter/material.dart'; void main() { testWidgets('ListView can handle shrinking top elements', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - controller: controller, - children: [ - new Container(height: 400.0, child: const Text('1')), - 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('4')), - new Container(height: 400.0, child: const Text('5')), - new Container(height: 400.0, child: const Text('6')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [ + new Container(height: 400.0, child: const Text('1')), + 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('4')), + new Container(height: 400.0, child: const Text('5')), + new Container(height: 400.0, child: const Text('6')), + ], + ), + ), + ); controller.jumpTo(1000.0); await tester.pump(); expect(tester.getTopLeft(find.text('4')).dy, equals(200.0)); - await tester.pumpWidget(new ListView( - controller: controller, - children: [ - new Container(height: 200.0, child: const Text('1')), - 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('4')), - new Container(height: 400.0, child: const Text('5')), - new Container(height: 400.0, child: const Text('6')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [ + new Container(height: 200.0, child: const Text('1')), + 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('4')), + new Container(height: 400.0, child: const Text('5')), + new Container(height: 400.0, child: const Text('6')), + ], + ), + ), + ); expect(controller.offset, equals(1000.0)); expect(tester.getTopLeft(find.text('4')).dy, equals(200.0)); @@ -55,15 +65,20 @@ void main() { testWidgets('ListView can handle inserts at 0', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - controller: controller, - children: [ - new Container(height: 400.0, child: const Text('0')), - new Container(height: 400.0, child: const Text('1')), - new Container(height: 400.0, child: const Text('2')), - new Container(height: 400.0, child: const Text('3')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [ + new Container(height: 400.0, child: const Text('0')), + new Container(height: 400.0, child: const Text('1')), + new Container(height: 400.0, child: const Text('2')), + new Container(height: 400.0, child: const Text('3')), + ], + ), + ), + ); expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsOneWidget); expect(find.text('2'), findsNothing); @@ -71,17 +86,22 @@ void main() { 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')); - await tester.pumpWidget(new ListView( - controller: controller, - children: [ - new Container(height: 10.0, child: const Text('A')), - new Container(height: 10.0, child: const Text('B')), - new Container(height: 400.0, child: const Text('0')), - new Container(height: 400.0, child: const Text('1')), - new Container(height: 400.0, child: const Text('2')), - new Container(height: 400.0, child: const Text('3')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [ + new Container(height: 10.0, child: const Text('A')), + new Container(height: 10.0, child: const Text('B')), + new Container(height: 400.0, child: const Text('0')), + new Container(height: 400.0, child: const Text('1')), + new Container(height: 400.0, child: const Text('2')), + new Container(height: 400.0, child: const Text('3')), + ], + ), + ), + ); expect(find.text('A'), findsOneWidget); expect(find.text('B'), findsOneWidget); expect(tester.getTopLeft(findItemA).dy, 0.0); @@ -95,17 +115,22 @@ void main() { expect(find.text('A'), findsNothing); expect(find.text('B'), findsNothing); - await tester.pumpWidget(new ListView( - controller: controller, - children: [ - new Container(height: 200.0, child: const Text('A')), - new Container(height: 200.0, child: const Text('B')), - new Container(height: 400.0, child: const Text('0')), - new Container(height: 400.0, child: const Text('1')), - new Container(height: 400.0, child: const Text('2')), - new Container(height: 400.0, child: const Text('3')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [ + new Container(height: 200.0, child: const Text('A')), + new Container(height: 200.0, child: const Text('B')), + new Container(height: 400.0, child: const Text('0')), + new Container(height: 400.0, child: const Text('1')), + new Container(height: 400.0, child: const Text('2')), + new Container(height: 400.0, child: const Text('3')), + ], + ), + ), + ); expect(find.text('A'), findsNothing); expect(find.text('B'), findsNothing); diff --git a/packages/flutter/test/widgets/list_view_fling_test.dart b/packages/flutter/test/widgets/list_view_fling_test.dart index ff53af8bf1a..b56b571e575 100644 --- a/packages/flutter/test/widgets/list_view_fling_test.dart +++ b/packages/flutter/test/widgets/list_view_fling_test.dart @@ -10,11 +10,16 @@ const double kFlingOffset = kHeight * 20.0; void main() { testWidgets('Flings don\'t stutter', (WidgetTester tester) async { - await tester.pumpWidget(new ListView.builder( - itemBuilder: (BuildContext context, int index) { - return new Container(height: kHeight); - }, - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + itemBuilder: (BuildContext context, int index) { + return new Container(height: kHeight); + }, + ), + ), + ); double getCurrentOffset() { return tester.state(find.byType(Scrollable)).position.pixels; diff --git a/packages/flutter/test/widgets/list_view_misc_test.dart b/packages/flutter/test/widgets/list_view_misc_test.dart index 8762187d99c..298501c6fc1 100644 --- a/packages/flutter/test/widgets/list_view_misc_test.dart +++ b/packages/flutter/test/widgets/list_view_misc_test.dart @@ -11,15 +11,18 @@ final Key blockKey = const Key('test'); void main() { testWidgets('Cannot scroll a non-overflowing block', (WidgetTester tester) async { await tester.pumpWidget( - new ListView( - key: blockKey, - children: [ - new Container( - height: 200.0, // less than 600, the height of the test area - child: const Text('Hello') - ) - ] - ) + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + key: blockKey, + children: [ + new Container( + height: 200.0, // less than 600, the height of the test area + child: const Text('Hello'), + ), + ], + ), + ), ); final Offset middleOfContainer = tester.getCenter(find.text('Hello')); @@ -36,15 +39,18 @@ void main() { testWidgets('Can scroll an overflowing block', (WidgetTester tester) async { await tester.pumpWidget( - new ListView( - key: blockKey, - children: [ - new Container( - height: 2000.0, // more than 600, the height of the test area - child: const Text('Hello') - ) - ] - ) + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + key: blockKey, + children: [ + new Container( + height: 2000.0, // more than 600, the height of the test area + child: const Text('Hello'), + ), + ], + ), + ), ); final Offset middleOfContainer = tester.getCenter(find.text('Hello')); @@ -67,25 +73,28 @@ void main() { int second = 0; Widget buildBlock({ bool reverse: false }) { - return new ListView( - key: new UniqueKey(), - reverse: reverse, - children: [ - new GestureDetector( - onTap: () { first += 1; }, - child: new Container( - height: 350.0, // more than half the height of the test area - color: const Color(0xFF00FF00), - ) - ), - new GestureDetector( - onTap: () { second += 1; }, - child: new Container( - height: 350.0, // more than half the height of the test area - color: const Color(0xFF0000FF), - ) - ) - ] + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + key: new UniqueKey(), + reverse: reverse, + children: [ + new GestureDetector( + onTap: () { first += 1; }, + child: new Container( + height: 350.0, // more than half the height of the test area + color: const Color(0xFF00FF00), + ) + ), + new GestureDetector( + onTap: () { second += 1; }, + child: new Container( + height: 350.0, // more than half the height of the test area + color: const Color(0xFF0000FF), + ), + ), + ], + ), ); } @@ -107,9 +116,12 @@ void main() { final ScrollController controller = new ScrollController(); Widget buildBlock() { - return new ListView( - controller: controller, - children: [const Text("A"), const Text("B"), const Text("C")] + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [const Text("A"), const Text("B"), const Text("C")], + ), ); } await tester.pumpWidget(buildBlock()); @@ -125,13 +137,18 @@ void main() { new Container(), ]); - await tester.pumpWidget(new CustomScrollView( - slivers: [ - new SliverList( - delegate: delegate, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new SliverList( + delegate: delegate, + ), + ], ), - ], - )); + ), + ); final SliverMultiBoxAdaptorElement element = tester.element(find.byType(SliverList)); @@ -154,42 +171,45 @@ void main() { // The overall height of the frame is (as ever) 600 Widget buildFrame() { - return new Column( - children: [ - new Flexible( - // The overall height of the ListView's contents is 500 - child: new ListView( - children: [ - const SizedBox( - height: 150.0, - child: const Center( - child: const Text('top') + return new Directionality( + textDirection: TextDirection.ltr, + child: new Column( + children: [ + new Flexible( + // The overall height of the ListView's contents is 500 + child: new ListView( + children: [ + const SizedBox( + height: 150.0, + child: const Center( + child: const Text('top') + ), ), - ), - const SizedBox( - height: 200.0, - child: const Center( - child: const Text('middle') + const SizedBox( + height: 200.0, + child: const Center( + child: const Text('middle') + ), ), - ), - const SizedBox( - height: 150.0, - child: const Center( - child: const Text('bottom') + const SizedBox( + height: 150.0, + child: const Center( + child: const Text('bottom') + ), ), - ), - ], + ], + ), ), - ), - // If this widget's height is > 100 the ListView can scroll. - new SizeTransition( - sizeFactor: controller.view, - child: const SizedBox( - height: 300.0, - child: const Text('keyboard'), + // If this widget's height is > 100 the ListView can scroll. + new SizeTransition( + sizeFactor: controller.view, + child: const SizedBox( + height: 300.0, + child: const Text('keyboard'), + ), ), - ), - ], + ], + ), ); } diff --git a/packages/flutter/test/widgets/list_view_relayout_test.dart b/packages/flutter/test/widgets/list_view_relayout_test.dart index 4166d2a4d7b..d341e2cf201 100644 --- a/packages/flutter/test/widgets/list_view_relayout_test.dart +++ b/packages/flutter/test/widgets/list_view_relayout_test.dart @@ -8,118 +8,173 @@ import 'package:flutter/rendering.dart'; void main() { testWidgets('Nested ListView with shrinkWrap', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - shrinkWrap: true, - children: [ - new ListView( + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( shrinkWrap: true, children: [ - const Text('1'), - const Text('2'), - const Text('3'), + new ListView( + shrinkWrap: true, + children: [ + const Text('1'), + const Text('2'), + const Text('3'), + ], + ), + new ListView( + shrinkWrap: true, + children: [ + const Text('4'), + const Text('5'), + const Text('6'), + ], + ), ], ), - new ListView( - shrinkWrap: true, - children: [ - const Text('4'), - const Text('5'), - const Text('6'), - ], - ), - ], - )); + ), + ); }); testWidgets('Underflowing ListView should relayout for additional children', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/5950 - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 100.0, child: const Text('100')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 100.0, child: const Text('100')), + ], + ), + ), + ); - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 100.0, child: const Text('100')), - const SizedBox(height: 200.0, child: const Text('200')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 100.0, child: const Text('100')), + const SizedBox(height: 200.0, child: const Text('200')), + ], + ), + ), + ); expect(find.text('200'), findsOneWidget); }); testWidgets('Underflowing ListView contentExtent should track additional children', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 100.0, child: const Text('100')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 100.0, child: const Text('100')), + ], + ), + ), + ); final RenderSliverList list = tester.renderObject(find.byType(SliverList)); expect(list.geometry.scrollExtent, equals(100.0)); - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 100.0, child: const Text('100')), - const SizedBox(height: 200.0, child: const Text('200')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 100.0, child: const Text('100')), + const SizedBox(height: 200.0, child: const Text('200')), + ], + ), + ), + ); expect(list.geometry.scrollExtent, equals(300.0)); - await tester.pumpWidget(new ListView( - children: [] - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [] + ), + ), + ); expect(list.geometry.scrollExtent, equals(0.0)); }); testWidgets('Overflowing ListView should relayout for missing children', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 300.0, child: const Text('300')), - const SizedBox(height: 400.0, child: const Text('400')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 300.0, child: const Text('300')), + const SizedBox(height: 400.0, child: const Text('400')), + ], + ), + ), + ); expect(find.text('300'), findsOneWidget); expect(find.text('400'), findsOneWidget); - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 300.0, child: const Text('300')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 300.0, child: const Text('300')), + ], + ), + ), + ); expect(find.text('300'), findsOneWidget); expect(find.text('400'), findsNothing); - await tester.pumpWidget(new ListView( - children: [] - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [] + ), + ), + ); expect(find.text('300'), findsNothing); expect(find.text('400'), findsNothing); }); testWidgets('Overflowing ListView should not relayout for additional children', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 300.0, child: const Text('300')), - const SizedBox(height: 400.0, child: const Text('400')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 300.0, child: const Text('300')), + const SizedBox(height: 400.0, child: const Text('400')), + ], + ), + ), + ); expect(find.text('300'), findsOneWidget); expect(find.text('400'), findsOneWidget); - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 300.0, child: const Text('300')), - const SizedBox(height: 400.0, child: const Text('400')), - const SizedBox(height: 100.0, child: const Text('100')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 300.0, child: const Text('300')), + const SizedBox(height: 400.0, child: const Text('400')), + const SizedBox(height: 100.0, child: const Text('100')), + ], + ), + ), + ); expect(find.text('300'), findsOneWidget); expect(find.text('400'), findsOneWidget); @@ -132,22 +187,32 @@ void main() { // When children are added that cause it to overflow, scrolling should // be enabled. - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 100.0, child: const Text('100')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 100.0, child: const Text('100')), + ], + ), + ), + ); final ScrollableState scrollable = tester.state(find.byType(Scrollable)); expect(scrollable.position.maxScrollExtent, 0.0); - await tester.pumpWidget(new ListView( - children: [ - const SizedBox(height: 100.0, child: const Text('100')), - const SizedBox(height: 200.0, child: const Text('200')), - const SizedBox(height: 400.0, child: const Text('400')), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + const SizedBox(height: 100.0, child: const Text('100')), + const SizedBox(height: 200.0, child: const Text('200')), + const SizedBox(height: 400.0, child: const Text('400')), + ], + ), + ), + ); expect(scrollable.position.maxScrollExtent, 100.0); }); diff --git a/packages/flutter/test/widgets/list_view_test.dart b/packages/flutter/test/widgets/list_view_test.dart index 7ab3f1a3553..4e133714b48 100644 --- a/packages/flutter/test/widgets/list_view_test.dart +++ b/packages/flutter/test/widgets/list_view_test.dart @@ -18,18 +18,28 @@ class TestSliverChildListDelegate extends SliverChildListDelegate { void main() { 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 { await tester.pumpWidget( - new ListView( - itemExtent: 200.0, - children: new List.generate(20, (int i) { - return new Container( - child: new Text('$i'), - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 200.0, + children: new List.generate(20, (int i) { + return new Container( + child: new Text('$i'), + ); + }), + ), ), ); @@ -68,18 +78,21 @@ void main() { final List log = []; await tester.pumpWidget( - new ListView( - itemExtent: 200.0, - children: new List.generate(20, (int i) { - return new Builder( - builder: (BuildContext context) { - log.add(i); - return new Container( - child: new Text('$i'), - ); - } - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 200.0, + children: new List.generate(20, (int i) { + return new Builder( + builder: (BuildContext context) { + log.add(i); + return new Container( + child: new Text('$i'), + ); + } + ); + }), + ), ), ); @@ -107,8 +120,11 @@ void main() { testWidgets('ListView can build out of underflow', (WidgetTester tester) async { await tester.pumpWidget( - new ListView( - itemExtent: 100.0, + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 100.0, + ), ), ); @@ -120,13 +136,16 @@ void main() { expect(find.text('5'), findsNothing); await tester.pumpWidget( - new ListView( - itemExtent: 100.0, - children: new List.generate(2, (int i) { - return new Container( - child: new Text('$i'), - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 100.0, + children: new List.generate(2, (int i) { + return new Container( + child: new Text('$i'), + ); + }), + ), ), ); @@ -138,13 +157,16 @@ void main() { expect(find.text('5'), findsNothing); await tester.pumpWidget( - new ListView( - itemExtent: 100.0, - children: new List.generate(5, (int i) { - return new Container( - child: new Text('$i'), - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 100.0, + children: new List.generate(5, (int i) { + return new Container( + child: new Text('$i'), + ); + }), + ), ), ); @@ -158,15 +180,18 @@ void main() { testWidgets('ListView can build out of overflow padding', (WidgetTester tester) async { await tester.pumpWidget( - new Center( - child: new SizedBox( - width: 0.0, - height: 0.0, - child: new ListView( - padding: const EdgeInsets.all(8.0), - children: [ - const Text('padded'), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new SizedBox( + width: 0.0, + height: 0.0, + child: new ListView( + padding: const EdgeInsets.all(8.0), + children: [ + const Text('padded'), + ], + ), ), ), ), @@ -176,15 +201,18 @@ void main() { testWidgets('ListView with itemExtent in unbounded context', (WidgetTester tester) async { await tester.pumpWidget( - new SingleChildScrollView( - child: new ListView( - itemExtent: 100.0, - shrinkWrap: true, - children: new List.generate(20, (int i) { - return new Container( - child: new Text('$i'), - ); - }), + new Directionality( + textDirection: TextDirection.ltr, + child: new SingleChildScrollView( + child: new ListView( + itemExtent: 100.0, + shrinkWrap: true, + children: new List.generate(20, (int i) { + return new Container( + child: new Text('$i'), + ); + }), + ), ), ), ); @@ -203,9 +231,12 @@ void main() { ); await tester.pumpWidget( - new ListView.custom( - itemExtent: 110.0, - childrenDelegate: delegate, + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.custom( + itemExtent: 110.0, + childrenDelegate: delegate, + ), ), ); @@ -213,9 +244,12 @@ void main() { delegate.log.clear(); await tester.pumpWidget( - new ListView.custom( - itemExtent: 210.0, - childrenDelegate: delegate, + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.custom( + itemExtent: 210.0, + childrenDelegate: delegate, + ), ), ); diff --git a/packages/flutter/test/widgets/list_view_vertical_test.dart b/packages/flutter/test/widgets/list_view_vertical_test.dart index 1c6b1968014..8f44143c781 100644 --- a/packages/flutter/test/widgets/list_view_vertical_test.dart +++ b/packages/flutter/test/widgets/list_view_vertical_test.dart @@ -8,14 +8,17 @@ import 'package:flutter/widgets.dart'; const List items = const [0, 1, 2, 3, 4, 5]; Widget buildFrame() { - return new ListView( - itemExtent: 290.0, - scrollDirection: Axis.vertical, - children: items.map((int item) { - return new Container( - child: new Text('$item') - ); - }).toList(), + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 290.0, + scrollDirection: Axis.vertical, + children: items.map((int item) { + return new Container( + child: new Text('$item') + ); + }).toList(), + ), ); } @@ -65,15 +68,18 @@ void main() { testWidgets('Drag vertically', (WidgetTester tester) async { await tester.pumpWidget( - new ListView( - itemExtent: 290.0, - padding: const EdgeInsets.only(top: 250.0), - scrollDirection: Axis.vertical, - children: items.map((int item) { - return new Container( - child: new Text('$item') - ); - }).toList(), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 290.0, + padding: const EdgeInsets.only(top: 250.0), + scrollDirection: Axis.vertical, + children: items.map((int item) { + return new Container( + child: new Text('$item') + ); + }).toList(), + ), ), ); diff --git a/packages/flutter/test/widgets/list_view_viewporting_test.dart b/packages/flutter/test/widgets/list_view_viewporting_test.dart index e20c6e4af6c..b5107215518 100644 --- a/packages/flutter/test/widgets/list_view_viewporting_test.dart +++ b/packages/flutter/test/widgets/list_view_viewporting_test.dart @@ -16,18 +16,21 @@ void main() { // so if our widget is 100 pixels tall, it should fit exactly 6 times. Widget builder() { - return new FlipWidget( - left: new ListView.builder( - itemBuilder: (BuildContext context, int index) { - callbackTracker.add(index); - return new Container( - key: new ValueKey(index), - height: 100.0, - child: new Text("$index"), - ); - }, + return new Directionality( + textDirection: TextDirection.ltr, + child: new FlipWidget( + left: new ListView.builder( + itemBuilder: (BuildContext context, int index) { + callbackTracker.add(index); + return new Container( + key: new ValueKey(index), + height: 100.0, + child: new Text("$index"), + ); + }, + ), + right: const Text('Not Today'), ), - right: const Text('Not Today'), ); } @@ -68,12 +71,15 @@ void main() { }; Widget builder() { - return new FlipWidget( - left: new ListView.builder( - controller: new ScrollController(initialScrollOffset: 300.0), - itemBuilder: itemBuilder, + return new Directionality( + textDirection: TextDirection.ltr, + child: new FlipWidget( + left: new ListView.builder( + controller: new ScrollController(initialScrollOffset: 300.0), + itemBuilder: itemBuilder, + ), + right: const Text('Not Today'), ), - right: const Text('Not Today'), ); } @@ -173,8 +179,11 @@ void main() { } Widget builder() { - return new ListView.builder( - itemBuilder: itemBuilder, + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + itemBuilder: itemBuilder, + ), ); } @@ -214,12 +223,15 @@ void main() { ); await tester.pumpWidget( - new StatefulBuilder( - builder: (BuildContext context, StateSetter setter) { - setState = setter; - return new Theme(data: themeData, child: viewport); - } - ) + new Directionality( + textDirection: TextDirection.ltr, + child: new StatefulBuilder( + builder: (BuildContext context, StateSetter setter) { + setState = setter; + return new Theme(data: themeData, child: viewport); + }, + ), + ), ); DecoratedBox widget = tester.firstWidget(find.byType(DecoratedBox)); @@ -249,9 +261,12 @@ void main() { }; await tester.pumpWidget( - new ListView.builder( - padding: const EdgeInsets.fromLTRB(7.0, 3.0, 5.0, 11.0), - itemBuilder: itemBuilder, + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + padding: const EdgeInsets.fromLTRB(7.0, 3.0, 5.0, 11.0), + itemBuilder: itemBuilder, + ), ), ); @@ -262,14 +277,19 @@ void main() { }); testWidgets('ListView underflow extents', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - addAutomaticKeepAlives: false, - children: [ - new Container(height: 100.0), - new Container(height: 100.0), - new Container(height: 100.0), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + addAutomaticKeepAlives: false, + children: [ + new Container(height: 100.0), + new Container(height: 100.0), + new Container(height: 100.0), + ], + ), + ), + ); final RenderSliverList list = tester.renderObject(find.byType(SliverList)); @@ -294,6 +314,7 @@ void main() { ' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' ' │ viewportMainAxisExtent: 600.0)\n' ' │ geometry: SliverGeometry(scrollExtent: 300.0, paintExtent: 300.0,\n' ' │ maxPaintExtent: 300.0)\n' @@ -453,7 +474,7 @@ void main() { ' parentData: (can use size)\n' ' constraints: BoxConstraints(w=800.0, h=100.0)\n' ' size: Size(800.0, 100.0)\n' - ' additionalConstraints: BoxConstraints(biggest)\n', + ' additionalConstraints: BoxConstraints(biggest)\n' ), ); diff --git a/packages/flutter/test/widgets/list_view_with_inherited_test.dart b/packages/flutter/test/widgets/list_view_with_inherited_test.dart index d0b476642c5..9523ef24492 100644 --- a/packages/flutter/test/widgets/list_view_with_inherited_test.dart +++ b/packages/flutter/test/widgets/list_view_with_inherited_test.dart @@ -21,8 +21,11 @@ Widget buildCard(BuildContext context, int index) { } Widget buildFrame() { - return new ListView.builder( - itemBuilder: buildCard, + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + itemBuilder: buildCard, + ), ); } diff --git a/packages/flutter/test/widgets/listview_end_append_test.dart b/packages/flutter/test/widgets/listview_end_append_test.dart index 7715b8fd2f1..b2ecbfbf590 100644 --- a/packages/flutter/test/widgets/listview_end_append_test.dart +++ b/packages/flutter/test/widgets/listview_end_append_test.dart @@ -10,10 +10,13 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/9506 Widget buildFrame(int itemCount) { - return new ListView.builder( - itemExtent: 200.0, - itemCount: itemCount, - itemBuilder: (BuildContext context, int index) => new Text('item $index'), + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + itemExtent: 200.0, + itemCount: itemCount, + itemBuilder: (BuildContext context, int index) => new Text('item $index'), + ), ); } @@ -34,14 +37,17 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/9506 Widget buildFrame(int itemCount) { - return new ListView.builder( - itemCount: itemCount, - itemBuilder: (BuildContext context, int index) { - return new SizedBox( - height: 200.0, - child: new Text('item $index'), - ); - }, + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView.builder( + itemCount: itemCount, + itemBuilder: (BuildContext context, int index) { + return new SizedBox( + height: 200.0, + child: new Text('item $index'), + ); + }, + ), ); } diff --git a/packages/flutter/test/widgets/overscroll_indicator_test.dart b/packages/flutter/test/widgets/overscroll_indicator_test.dart index d324c3423c0..b81900a9bf7 100644 --- a/packages/flutter/test/widgets/overscroll_indicator_test.dart +++ b/packages/flutter/test/widgets/overscroll_indicator_test.dart @@ -24,10 +24,13 @@ Future slowDrag(WidgetTester tester, Offset start, Offset offset) async { void main() { testWidgets('Overscroll indicator color', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), + ], + ), ), ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); @@ -57,10 +60,13 @@ void main() { testWidgets('Overscroll indicator changes side when you drag on the other side', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), + ], + ), ), ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); @@ -92,10 +98,13 @@ void main() { testWidgets('Overscroll indicator changes side when you shift sides', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 2000.0)), + ], + ), ), ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); @@ -125,11 +134,14 @@ void main() { group('Flipping direction of scrollable doesn\'t change overscroll behavior', () { testWidgets('down', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), + ], + ), ), ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); @@ -142,12 +154,15 @@ void main() { testWidgets('up', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - reverse: true, - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + reverse: true, + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), + ], + ), ), ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); @@ -161,11 +176,14 @@ void main() { testWidgets('Overscroll in both directions', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), + ], + ), ), ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); @@ -180,16 +198,18 @@ void main() { }); testWidgets('Overscroll horizontally', (WidgetTester tester) async { - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new CustomScrollView( - scrollDirection: Axis.horizontal, - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), - ], + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + scrollDirection: Axis.horizontal, + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), + ], + ), ), - )); + ); final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); 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()); @@ -227,39 +247,43 @@ void main() { testWidgets('Changing settings', (WidgetTester tester) async { RenderObject painter; - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new ScrollConfiguration( - behavior: new TestScrollBehavior1(), - child: new CustomScrollView( - scrollDirection: Axis.horizontal, - physics: const AlwaysScrollableScrollPhysics(), - reverse: true, - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), - ], + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ScrollConfiguration( + behavior: new TestScrollBehavior1(), + child: new CustomScrollView( + scrollDirection: Axis.horizontal, + physics: const AlwaysScrollableScrollPhysics(), + reverse: true, + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), + ], + ), ), ), - )); + ); painter = tester.renderObject(find.byType(CustomPaint)); 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, isNot(paints..circle()..circle())); await tester.pumpAndSettle(const Duration(seconds: 1)); - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new ScrollConfiguration( - behavior: new TestScrollBehavior2(), - child: new CustomScrollView( - scrollDirection: Axis.horizontal, - physics: const AlwaysScrollableScrollPhysics(), - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), - ], + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ScrollConfiguration( + behavior: new TestScrollBehavior2(), + child: new CustomScrollView( + scrollDirection: Axis.horizontal, + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 20.0)), + ], + ), ), ), - )); + ); painter = tester.renderObject(find.byType(CustomPaint)); 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()); diff --git a/packages/flutter/test/widgets/remember_scroll_position_test.dart b/packages/flutter/test/widgets/remember_scroll_position_test.dart index 58f039c6ab6..1fd0568a3bd 100644 --- a/packages/flutter/test/widgets/remember_scroll_position_test.dart +++ b/packages/flutter/test/widgets/remember_scroll_position_test.dart @@ -30,25 +30,30 @@ class ThePositiveNumbers extends StatelessWidget { Future performTest(WidgetTester tester, bool maintainState) async { final GlobalKey navigatorKey = new GlobalKey(); - await tester.pumpWidget(new Navigator( - key: navigatorKey, - onGenerateRoute: (RouteSettings settings) { - if (settings.name == '/') { - return new MaterialPageRoute( - settings: settings, - builder: (_) => new Container(child: const ThePositiveNumbers(from: 0)), - maintainState: maintainState, - ); - } else if (settings.name == '/second') { - return new MaterialPageRoute( - settings: settings, - builder: (_) => new Container(child: const ThePositiveNumbers(from: 10000)), - maintainState: maintainState, - ); - } - return null; - } - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Navigator( + key: navigatorKey, + onGenerateRoute: (RouteSettings settings) { + if (settings.name == '/') { + return new MaterialPageRoute( + settings: settings, + builder: (_) => new Container(child: const ThePositiveNumbers(from: 0)), + maintainState: maintainState, + ); + } else if (settings.name == '/second') { + return new MaterialPageRoute( + settings: settings, + builder: (_) => new Container(child: const ThePositiveNumbers(from: 10000)), + maintainState: maintainState, + ); + } + return null; + } + ), + ), + ); // we're 600 pixels high, each item is 100 pixels high, scroll position is // 110.0, so we should have 7 items, 1..7. diff --git a/packages/flutter/test/widgets/reparent_state_test.dart b/packages/flutter/test/widgets/reparent_state_test.dart index b5cd71251c8..e02565e487b 100644 --- a/packages/flutter/test/widgets/reparent_state_test.dart +++ b/packages/flutter/test/widgets/reparent_state_test.dart @@ -195,16 +195,21 @@ void main() { final StateMarkerState keyState = key.currentState; keyState.marker = "marked"; - await tester.pumpWidget(new ListView( - itemExtent: 100.0, - children: [ - new Container( - key: const Key('container'), - height: 100.0, - child: new StateMarker(key: key), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 100.0, + children: [ + new Container( + key: const Key('container'), + height: 100.0, + child: new StateMarker(key: key), + ), + ], ), - ], - )); + ), + ); expect(key.currentState, equals(keyState)); expect(keyState.marker, equals("marked")); diff --git a/packages/flutter/test/widgets/scroll_controller_test.dart b/packages/flutter/test/widgets/scroll_controller_test.dart index 388e347707a..7a5bb5a1a9c 100644 --- a/packages/flutter/test/widgets/scroll_controller_test.dart +++ b/packages/flutter/test/widgets/scroll_controller_test.dart @@ -11,15 +11,20 @@ void main() { testWidgets('ScrollController control test', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container( - height: 200.0, - child: new Text(state), - ); - }).toList() - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container( + height: 200.0, + child: new Text(state), + ); + }).toList(), + ), + ), + ); double realOffset() { return tester.state(find.byType(Scrollable)).position.pixels; @@ -44,16 +49,21 @@ void main() { expect(controller.offset, equals(326.0)); expect(realOffset(), equals(controller.offset)); - await tester.pumpWidget(new ListView( - key: const Key('second'), - controller: controller, - children: kStates.map((String state) { - return new Container( - height: 200.0, - child: new Text(state), - ); - }).toList() - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + key: const Key('second'), + controller: controller, + children: kStates.map((String state) { + return new Container( + height: 200.0, + child: new Text(state), + ); + }).toList(), + ), + ), + ); expect(controller.offset, equals(0.0)); expect(realOffset(), equals(controller.offset)); @@ -65,16 +75,21 @@ void main() { final ScrollController controller2 = new ScrollController(); - await tester.pumpWidget(new ListView( - key: const Key('second'), - controller: controller2, - children: kStates.map((String state) { - return new Container( - height: 200.0, - child: new Text(state), - ); - }).toList() - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + key: const Key('second'), + controller: controller2, + children: kStates.map((String state) { + return new Container( + height: 200.0, + child: new Text(state), + ); + }).toList(), + ), + ), + ); expect(() => controller.offset, throwsAssertionError); expect(controller2.offset, equals(653.0)); @@ -83,17 +98,22 @@ void main() { expect(() => controller.jumpTo(120.0), throwsAssertionError); expect(() => controller.animateTo(132.0, duration: const Duration(milliseconds: 300), curve: Curves.ease), throwsAssertionError); - await tester.pumpWidget(new ListView( - key: const Key('second'), - controller: controller2, - physics: const BouncingScrollPhysics(), - children: kStates.map((String state) { - return new Container( - height: 200.0, - child: new Text(state), - ); - }).toList() - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + key: const Key('second'), + controller: controller2, + physics: const BouncingScrollPhysics(), + children: kStates.map((String state) { + return new Container( + height: 200.0, + child: new Text(state), + ); + }).toList(), + ), + ), + ); expect(controller2.offset, equals(653.0)); expect(realOffset(), equals(controller2.offset)); @@ -114,11 +134,16 @@ void main() { initialScrollOffset: 209.0, ); - await tester.pumpWidget(new GridView.count( - crossAxisCount: 4, - controller: controller, - children: kStates.map((String state) => new Text(state)).toList(), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + crossAxisCount: 4, + controller: controller, + children: kStates.map((String state) => new Text(state)).toList(), + ), + ), + ); double realOffset() { return tester.state(find.byType(Scrollable)).position.pixels; @@ -134,11 +159,16 @@ void main() { expect(controller.offset, equals(105.0)); expect(realOffset(), equals(controller.offset)); - await tester.pumpWidget(new GridView.count( - crossAxisCount: 2, - controller: controller, - children: kStates.map((String state) => new Text(state)).toList(), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + crossAxisCount: 2, + controller: controller, + children: kStates.map((String state) => new Text(state)).toList(), + ), + ), + ); expect(controller.offset, equals(105.0)); expect(realOffset(), equals(controller.offset)); @@ -147,10 +177,15 @@ void main() { testWidgets('DrivenScrollActivity ending after dispose', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - controller: controller, - children: [ new Container(height: 200000.0) ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: [ new Container(height: 200000.0) ], + ), + ), + ); controller.animateTo(1000.0, duration: const Duration(seconds: 1), curve: Curves.linear); @@ -168,28 +203,33 @@ void main() { testWidgets('Read operations on ScrollControllers with more than one position fail', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - children: [ - new Container( - constraints: const BoxConstraints(maxHeight: 500.0), - child: new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container(height: 200.0, child: new Text(state)); - }).toList(), - ), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + new Container( + constraints: const BoxConstraints(maxHeight: 500.0), + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container(height: 200.0, child: new Text(state)); + }).toList(), + ), + ), + new Container( + constraints: const BoxConstraints(maxHeight: 500.0), + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container(height: 200.0, child: new Text(state)); + }).toList(), + ), + ), + ], ), - new Container( - constraints: const BoxConstraints(maxHeight: 500.0), - child: new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container(height: 200.0, child: new Text(state)); - }).toList(), - ), - ), - ], - )); + ), + ); expect(() => controller.offset, throwsAssertionError); expect(() => controller.position, throwsAssertionError); @@ -203,28 +243,33 @@ void main() { testWidgets('Write operations on ScrollControllers with more than one position do not throw', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - children: [ - new Container( - constraints: const BoxConstraints(maxHeight: 500.0), - child: new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container(height: 200.0, child: new Text(state)); - }).toList(), - ), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + new Container( + constraints: const BoxConstraints(maxHeight: 500.0), + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container(height: 200.0, child: new Text(state)); + }).toList(), + ), + ), + new Container( + constraints: const BoxConstraints(maxHeight: 500.0), + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container(height: 200.0, child: new Text(state)); + }).toList(), + ), + ), + ], ), - new Container( - constraints: const BoxConstraints(maxHeight: 500.0), - child: new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container(height: 200.0, child: new Text(state)); - }).toList(), - ), - ), - ], - )); + ), + ); controller.jumpTo(1.0); controller.animateTo(1.0, duration: const Duration(seconds: 1), curve: Curves.linear); @@ -240,12 +285,17 @@ void main() { log.add(controller.offset); }); - await tester.pumpWidget(new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container(height: 200.0, child: new Text(state)); - }).toList(), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container(height: 200.0, child: new Text(state)); + }).toList(), + ), + ), + ); expect(log, isEmpty); @@ -264,16 +314,19 @@ void main() { final PageStorageBucket bucket = new PageStorageBucket(); Widget buildFrame(ScrollController controller) { - return new PageStorage( - bucket: bucket, - child: new KeyedSubtree( - key: const PageStorageKey('ListView'), - child: new ListView( - key: new UniqueKey(), // it's a different ListView every time - controller: controller, - children: new List.generate(50, (int index) { - return new Container(height: 100.0, child: new Text('Item $index')); - }).toList(), + return new Directionality( + textDirection: TextDirection.ltr, + child: new PageStorage( + bucket: bucket, + child: new KeyedSubtree( + key: const PageStorageKey('ListView'), + child: new ListView( + key: new UniqueKey(), // it's a different ListView every time + controller: controller, + children: new List.generate(50, (int index) { + return new Container(height: 100.0, child: new Text('Item $index')); + }).toList(), + ), ), ), ); diff --git a/packages/flutter/test/widgets/scroll_interaction_test.dart b/packages/flutter/test/widgets/scroll_interaction_test.dart index c1186e28b70..014f198554b 100644 --- a/packages/flutter/test/widgets/scroll_interaction_test.dart +++ b/packages/flutter/test/widgets/scroll_interaction_test.dart @@ -7,11 +7,16 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('Scroll flings twice in a row does not crash', (WidgetTester tester) async { - await tester.pumpWidget(new ListView( - children: [ - new Container(height: 100000.0) - ] - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: [ + new Container(height: 100000.0) + ], + ), + ), + ); final ScrollableState scrollable = tester.state(find.byType(Scrollable)); diff --git a/packages/flutter/test/widgets/scroll_view_test.dart b/packages/flutter/test/widgets/scroll_view_test.dart index 84cbc0a2847..3d762d2d995 100644 --- a/packages/flutter/test/widgets/scroll_view_test.dart +++ b/packages/flutter/test/widgets/scroll_view_test.dart @@ -11,20 +11,25 @@ void main() { testWidgets('ListView control test', (WidgetTester tester) async { final List log = []; - await tester.pumpWidget(new ListView( - children: kStates.map((String state) { - return new GestureDetector( - onTap: () { - log.add(state); - }, - child: new Container( - height: 200.0, - color: const Color(0xFF0000FF), - child: new Text(state), - ), - ); - }).toList() - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: kStates.map((String state) { + return new GestureDetector( + onTap: () { + log.add(state); + }, + child: new Container( + height: 200.0, + color: const Color(0xFF0000FF), + child: new Text(state), + ), + ); + }).toList(), + ), + ), + ); await tester.tap(find.text('Alabama')); expect(log, equals(['Alabama'])); @@ -45,14 +50,17 @@ void main() { testWidgets('ListView restart ballistic activity out of range', (WidgetTester tester) async { Widget buildListView(int n) { - return new ListView( - children: kStates.take(n).map((String state) { - return new Container( - height: 200.0, - color: const Color(0xFF0000FF), - child: new Text(state), - ); - }).toList() + return new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: kStates.take(n).map((String state) { + return new Container( + height: 200.0, + color: const Color(0xFF0000FF), + child: new Text(state), + ); + }).toList(), + ), ); } @@ -72,26 +80,31 @@ void main() { testWidgets('CustomScrollView control test', (WidgetTester tester) async { final List log = []; - await tester.pumpWidget(new CustomScrollView( - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate( - kStates.map((String state) { - return new GestureDetector( - onTap: () { - log.add(state); - }, - child: new Container( - height: 200.0, - color: const Color(0xFF0000FF), - child: new Text(state), - ), - ); - }).toList(), - ), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate( + kStates.map((String state) { + return new GestureDetector( + onTap: () { + log.add(state); + }, + child: new Container( + height: 200.0, + color: const Color(0xFF0000FF), + child: new Text(state), + ), + ); + }).toList(), + ), + ), + ], ), - ], - )); + ), + ); await tester.tap(find.text('Alabama')); expect(log, equals(['Alabama'])); @@ -114,21 +127,26 @@ void main() { final List log = []; final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new NotificationListener( - onNotification: (ScrollNotification notification) { - log.add(notification.runtimeType); - return false; - }, - child: new ListView( - controller: controller, - children: kStates.map((String state) { - return new Container( - height: 200.0, - child: new Text(state), - ); - }).toList(), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new NotificationListener( + onNotification: (ScrollNotification notification) { + log.add(notification.runtimeType); + return false; + }, + child: new ListView( + controller: controller, + children: kStates.map((String state) { + return new Container( + height: 200.0, + child: new Text(state), + ); + }).toList(), + ), + ), ), - )); + ); expect(log, isEmpty); @@ -226,30 +244,45 @@ void main() { testWidgets('CustomScrollView sets PrimaryScrollController when primary', (WidgetTester tester) async { final ScrollController primaryScrollController = new ScrollController(); - await tester.pumpWidget(new PrimaryScrollController( - controller: primaryScrollController, - child: new CustomScrollView(primary: true), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new PrimaryScrollController( + controller: primaryScrollController, + child: new CustomScrollView(primary: true), + ), + ), + ); final Scrollable scrollable = tester.widget(find.byType(Scrollable)); expect(scrollable.controller, primaryScrollController); }); testWidgets('ListView sets PrimaryScrollController when primary', (WidgetTester tester) async { final ScrollController primaryScrollController = new ScrollController(); - await tester.pumpWidget(new PrimaryScrollController( - controller: primaryScrollController, - child: new ListView(primary: true), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new PrimaryScrollController( + controller: primaryScrollController, + child: new ListView(primary: true), + ), + ), + ); final Scrollable scrollable = tester.widget(find.byType(Scrollable)); expect(scrollable.controller, primaryScrollController); }); testWidgets('GridView sets PrimaryScrollController when primary', (WidgetTester tester) async { final ScrollController primaryScrollController = new ScrollController(); - await tester.pumpWidget(new PrimaryScrollController( - controller: primaryScrollController, - child: new GridView.count(primary: true, crossAxisCount: 1), - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new PrimaryScrollController( + controller: primaryScrollController, + child: new GridView.count(primary: true, crossAxisCount: 1), + ), + ), + ); final Scrollable scrollable = tester.widget(find.byType(Scrollable)); expect(scrollable.controller, primaryScrollController); }); @@ -257,18 +290,23 @@ void main() { testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async { const Key innerKey = const Key('inner'); final ScrollController primaryScrollController = new ScrollController(); - await tester.pumpWidget(new PrimaryScrollController( - controller: primaryScrollController, - child: new ListView( - primary: true, - children: [ - new Container( - constraints: const BoxConstraints(maxHeight: 200.0), - child: new ListView(key: innerKey, primary: true), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new PrimaryScrollController( + controller: primaryScrollController, + child: new ListView( + primary: true, + children: [ + new Container( + constraints: const BoxConstraints(maxHeight: 200.0), + child: new ListView(key: innerKey, primary: true), + ), + ], ), - ], + ), ), - )); + ); final Scrollable innerScrollable = tester.widget( find.descendant( @@ -302,11 +340,14 @@ void main() { testWidgets('primary:true leads to scrolling', (WidgetTester tester) async { bool scrolled = false; await tester.pumpWidget( - new NotificationListener( - onNotification: (OverscrollNotification message) { scrolled = true; return false; }, - child: new ListView( - primary: true, - children: [], + new Directionality( + textDirection: TextDirection.ltr, + child: new NotificationListener( + onNotification: (OverscrollNotification message) { scrolled = true; return false; }, + child: new ListView( + primary: true, + children: [], + ), ), ), ); @@ -317,11 +358,14 @@ void main() { testWidgets('primary:false leads to no scrolling', (WidgetTester tester) async { bool scrolled = false; await tester.pumpWidget( - new NotificationListener( - onNotification: (OverscrollNotification message) { scrolled = true; return false; }, - child: new ListView( - primary: false, - children: [], + new Directionality( + textDirection: TextDirection.ltr, + child: new NotificationListener( + onNotification: (OverscrollNotification message) { scrolled = true; return false; }, + child: new ListView( + primary: false, + children: [], + ), ), ), ); @@ -332,12 +376,15 @@ void main() { testWidgets('physics:AlwaysScrollableScrollPhysics actually overrides primary:false default behaviour', (WidgetTester tester) async { bool scrolled = false; await tester.pumpWidget( - new NotificationListener( - onNotification: (OverscrollNotification message) { scrolled = true; return false; }, - child: new ListView( - primary: false, - physics: const AlwaysScrollableScrollPhysics(), - children: [], + new Directionality( + textDirection: TextDirection.ltr, + child: new NotificationListener( + onNotification: (OverscrollNotification message) { scrolled = true; return false; }, + child: new ListView( + primary: false, + physics: const AlwaysScrollableScrollPhysics(), + children: [], + ), ), ), ); @@ -348,12 +395,15 @@ void main() { testWidgets('physics:ScrollPhysics actually overrides primary:true default behaviour', (WidgetTester tester) async { bool scrolled = false; await tester.pumpWidget( - new NotificationListener( - onNotification: (OverscrollNotification message) { scrolled = true; return false; }, - child: new ListView( - primary: true, - physics: const ScrollPhysics(), - children: [], + new Directionality( + textDirection: TextDirection.ltr, + child: new NotificationListener( + onNotification: (OverscrollNotification message) { scrolled = true; return false; }, + child: new ListView( + primary: true, + physics: const ScrollPhysics(), + children: [], + ), ), ), ); diff --git a/packages/flutter/test/widgets/scrollable_animations_test.dart b/packages/flutter/test/widgets/scrollable_animations_test.dart index 352212da1f3..ffb75810031 100644 --- a/packages/flutter/test/widgets/scrollable_animations_test.dart +++ b/packages/flutter/test/widgets/scrollable_animations_test.dart @@ -12,10 +12,15 @@ void main() { for (int i = 0; i < 80; i++) textWidgets.add(new Text('$i')); final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - children: textWidgets, - controller: controller, - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: textWidgets, + controller: controller, + ), + ), + ); expectNoAnimation(); final double currentPosition = controller.position.pixels; @@ -30,10 +35,15 @@ void main() { for (int i = 0; i < 80; i++) textWidgets.add(new Text('$i')); final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - children: textWidgets, - controller: controller, - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: textWidgets, + controller: controller, + ), + ), + ); expectNoAnimation(); @@ -51,10 +61,15 @@ void main() { for (int i = 0; i < 80; i++) textWidgets.add(new Text('$i')); final ScrollController controller = new ScrollController(); - await tester.pumpWidget(new ListView( - children: textWidgets, - controller: controller, - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + children: textWidgets, + controller: controller, + ), + ), + ); expectNoAnimation(); diff --git a/packages/flutter/test/widgets/scrollable_dispose_test.dart b/packages/flutter/test/widgets/scrollable_dispose_test.dart index 48e5fa53530..c414841c2d1 100644 --- a/packages/flutter/test/widgets/scrollable_dispose_test.dart +++ b/packages/flutter/test/widgets/scrollable_dispose_test.dart @@ -12,10 +12,15 @@ void main() { final List textWidgets = []; for (int i = 0; i < 250; i++) textWidgets.add(new Text('$i')); - await tester.pumpWidget(new FlipWidget( - left: new ListView(children: textWidgets), - right: new Container() - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new FlipWidget( + left: new ListView(children: textWidgets), + right: new Container() + ), + ), + ); await tester.fling(find.byType(ListView), const Offset(0.0, -200.0), 1000.0); await tester.pump(); diff --git a/packages/flutter/test/widgets/scrollable_fling_test.dart b/packages/flutter/test/widgets/scrollable_fling_test.dart index fb788cfa2c2..fed2bcf6636 100644 --- a/packages/flutter/test/widgets/scrollable_fling_test.dart +++ b/packages/flutter/test/widgets/scrollable_fling_test.dart @@ -61,7 +61,12 @@ void main() { final List textWidgets = []; for (int i = 0; i < 250; i += 1) 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([])); await tester.tap(find.byType(Scrollable)); @@ -84,7 +89,12 @@ void main() { final List textWidgets = []; for (int i = 0; i < 250; i += 1) 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([])); await tester.tap(find.byType(Scrollable)); diff --git a/packages/flutter/test/widgets/scrollable_grid_test.dart b/packages/flutter/test/widgets/scrollable_grid_test.dart index f39f60ed720..b5beb7bbe6f 100644 --- a/packages/flutter/test/widgets/scrollable_grid_test.dart +++ b/packages/flutter/test/widgets/scrollable_grid_test.dart @@ -8,27 +8,35 @@ import 'package:flutter/rendering.dart'; void main() { testWidgets('GridView default control', (WidgetTester tester) async { - await tester.pumpWidget(new Center( - child: new GridView.count( - crossAxisCount: 1, + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new GridView.count( + crossAxisCount: 1, + ), + ), ), - )); + ); }); // Tests https://github.com/flutter/flutter/issues/5522 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 Widget testWidget = new Align( - child: new SizedBox( - height: 800.0, - width: 300.0, // forces the grid children to be 300..300 - child: new GridView.count( - crossAxisCount: 1, - padding: padding, - children: new List.generate(10, (int index) { - return new Text('$index', key: new ValueKey(index)); - }).toList(), + final Widget testWidget = new Directionality( + textDirection: TextDirection.ltr, + child: new Align( + child: new SizedBox( + height: 800.0, + width: 300.0, // forces the grid children to be 300..300 + child: new GridView.count( + crossAxisCount: 1, + padding: padding, + children: new List.generate(10, (int index) { + return new Text('$index', key: new ValueKey(index)); + }).toList(), + ), ), ), ); @@ -72,14 +80,17 @@ void main() { testWidgets('GridView.count() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/9506 Widget buildFrame(int itemCount) { - return new GridView.count( - crossAxisCount: itemCount, - children: new List.generate(itemCount, (int index) { - return new SizedBox( - height: 200.0, - child: new Text('item $index'), - ); - }), + return new Directionality( + textDirection: TextDirection.ltr, + child: new GridView.count( + crossAxisCount: itemCount, + children: new List.generate(itemCount, (int index) { + return new SizedBox( + height: 200.0, + child: new Text('item $index'), + ); + }), + ), ); } diff --git a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart index dfa081b25ed..897f40f847b 100644 --- a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart +++ b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart @@ -11,26 +11,28 @@ const List items = const [0, 1, 2, 3, 4, 5]; void main() { testWidgets('Tap item after scroll - horizontal', (WidgetTester tester) async { final List tapped = []; - await tester.pumpWidget(new Directionality( - textDirection: TextDirection.ltr, - child: new Center( - child: new Container( - height: 50.0, - child: new ListView( - itemExtent: 290.0, - scrollDirection: Axis.horizontal, - children: items.map((int item) { - return new Container( - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item'), - ), - ); - }).toList(), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new Container( + height: 50.0, + child: new ListView( + itemExtent: 290.0, + scrollDirection: Axis.horizontal, + children: items.map((int item) { + return new Container( + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item'), + ), + ); + }).toList(), + ), ), ), ), - )); + ); await tester.drag(find.text('2'), const Offset(-280.0, 0.0)); await tester.pump(const Duration(seconds: 1)); // screen is 800px wide, and has the following items: @@ -51,23 +53,28 @@ void main() { testWidgets('Tap item after scroll - vertical', (WidgetTester tester) async { final List tapped = []; - await tester.pumpWidget(new Center( - child: new Container( - width: 50.0, - child: new ListView( - itemExtent: 290.0, - scrollDirection: Axis.vertical, - children: items.map((int item) { - return new Container( - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item'), - ), - ); - }).toList(), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new Container( + width: 50.0, + child: new ListView( + itemExtent: 290.0, + scrollDirection: Axis.vertical, + children: items.map((int item) { + return new Container( + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item'), + ), + ); + }).toList(), + ), + ), ), ), - )); + ); await tester.drag(find.text('1'), const Offset(0.0, -280.0)); await tester.pump(const Duration(seconds: 1)); // screen is 600px tall, and has the following items: @@ -92,17 +99,20 @@ void main() { final List tapped = []; await tester.pumpWidget( - new ListView( - itemExtent: 290.0, - padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), - children: items.map((int item) { - return new Container( - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item'), - ), - ); - }).toList(), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 290.0, + padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), + children: items.map((int item) { + return new Container( + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item'), + ), + ); + }).toList(), + ), ), ); await tester.tapAt(const Offset(200.0, 19.0)); @@ -123,18 +133,21 @@ void main() { final List tapped = []; await tester.pumpWidget( - new ListView( - itemExtent: 290.0, - reverse: true, - padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), - children: items.map((int item) { - return new Container( - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item'), - ), - ); - }).toList(), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 290.0, + reverse: true, + padding: const EdgeInsets.fromLTRB(5.0, 20.0, 15.0, 10.0), + children: items.map((int item) { + return new Container( + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item'), + ), + ); + }).toList(), + ), ), ); await tester.tapAt(const Offset(200.0, 600.0 - 9.0)); @@ -156,16 +169,19 @@ void main() { final List tapped = []; await tester.pumpWidget( - new ListView( - itemExtent: 200.0, - children: items.map((int item) { - return new Container( - child: new GestureDetector( - onTap: () { tapped.add(item); }, - child: new Text('$item'), - ), - ); - }).toList(), + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + itemExtent: 200.0, + children: items.map((int item) { + return new Container( + child: new GestureDetector( + onTap: () { tapped.add(item); }, + child: new Text('$item'), + ), + ); + }).toList(), + ), ), ); diff --git a/packages/flutter/test/widgets/scrollable_semantics_test.dart b/packages/flutter/test/widgets/scrollable_semantics_test.dart index d59adc53f56..415b9f305cc 100644 --- a/packages/flutter/test/widgets/scrollable_semantics_test.dart +++ b/packages/flutter/test/widgets/scrollable_semantics_test.dart @@ -15,7 +15,12 @@ void main() { final List textWidgets = []; for (int i = 0; i < 80; 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.scrollUp])); @@ -48,10 +53,15 @@ void main() { initialScrollOffset: kItemHeight / 2, ); - await tester.pumpWidget(new ListView( - controller: scrollController, - children: containers - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new ListView( + controller: scrollController, + children: containers, + ), + ), + ); expect(scrollController.offset, kItemHeight / 2); diff --git a/packages/flutter/test/widgets/semantics_debugger_test.dart b/packages/flutter/test/widgets/semantics_debugger_test.dart index 51aedb3ca6f..67ddbe513a4 100644 --- a/packages/flutter/test/widgets/semantics_debugger_test.dart +++ b/packages/flutter/test/widgets/semantics_debugger_test.dart @@ -124,23 +124,26 @@ void main() { final List log = []; await tester.pumpWidget( - new SemanticsDebugger( - child: new Material( - child: new ListView( - children: [ - new RaisedButton( - onPressed: () { - log.add('top'); - }, - child: const Text('TOP'), - ), - new RaisedButton( - onPressed: () { - log.add('bottom'); - }, - child: const Text('BOTTOM'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new SemanticsDebugger( + child: new Material( + child: new ListView( + children: [ + new RaisedButton( + onPressed: () { + log.add('top'); + }, + child: const Text('TOP'), + ), + new RaisedButton( + onPressed: () { + log.add('bottom'); + }, + child: const Text('BOTTOM'), + ), + ], + ), ), ), ), @@ -159,15 +162,18 @@ void main() { final Key childKey = new UniqueKey(); await tester.pumpWidget( - new SemanticsDebugger( - child: new ListView( - children: [ - new Container( - key: childKey, - height: 5000.0, - color: Colors.green[500], - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new SemanticsDebugger( + child: new ListView( + children: [ + new Container( + key: childKey, + height: 5000.0, + color: Colors.green[500], + ), + ], + ), ), ), ); @@ -252,23 +258,26 @@ void main() { final bool valueBottom = true; await tester.pumpWidget( - new SemanticsDebugger( - child: new Material( - child: new ListView( - children: [ - new Checkbox( - key: keyTop, - value: valueTop, - onChanged: (bool newValue) { - valueTop = newValue; - }, - ), - new Checkbox( - key: keyBottom, - value: valueBottom, - onChanged: null, - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new SemanticsDebugger( + child: new Material( + child: new ListView( + children: [ + new Checkbox( + key: keyTop, + value: valueTop, + onChanged: (bool newValue) { + valueTop = newValue; + }, + ), + new Checkbox( + key: keyBottom, + value: valueBottom, + onChanged: null, + ), + ], + ), ), ), ), diff --git a/packages/flutter/test/widgets/single_child_scroll_view_test.dart b/packages/flutter/test/widgets/single_child_scroll_view_test.dart index 716f635a76e..f3d937b332d 100644 --- a/packages/flutter/test/widgets/single_child_scroll_view_test.dart +++ b/packages/flutter/test/widgets/single_child_scroll_view_test.dart @@ -146,16 +146,21 @@ void main() { testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async { const Key innerKey = const Key('inner'); final ScrollController primaryScrollController = new ScrollController(); - await tester.pumpWidget(new PrimaryScrollController( - controller: primaryScrollController, - child: new SingleChildScrollView( - primary: true, - child: new Container( - constraints: const BoxConstraints(maxHeight: 200.0), - child: new ListView(key: innerKey, primary: true), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new PrimaryScrollController( + controller: primaryScrollController, + child: new SingleChildScrollView( + primary: true, + child: new Container( + constraints: const BoxConstraints(maxHeight: 200.0), + child: new ListView(key: innerKey, primary: true), + ), + ), ), ), - )); + ); final Scrollable innerScrollable = tester.widget( find.descendant( diff --git a/packages/flutter/test/widgets/sliver_fill_remaining_test.dart b/packages/flutter/test/widgets/sliver_fill_remaining_test.dart index 214efd266cf..74f89650cb2 100644 --- a/packages/flutter/test/widgets/sliver_fill_remaining_test.dart +++ b/packages/flutter/test/widgets/sliver_fill_remaining_test.dart @@ -9,11 +9,14 @@ void main() { testWidgets('SliverFillRemaining - no siblings', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); await tester.pumpWidget( - new CustomScrollView( - controller: controller, - slivers: [ - new SliverFillRemaining(child: new Container()), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + controller: controller, + slivers: [ + new SliverFillRemaining(child: new Container()), + ], + ), ), ); expect(tester.renderObject(find.byType(Container)).size.height, equals(600.0)); @@ -34,12 +37,15 @@ void main() { testWidgets('SliverFillRemaining - one sibling', (WidgetTester tester) async { final ScrollController controller = new ScrollController(); await tester.pumpWidget( - new CustomScrollView( - controller: controller, - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(height: 100.0)), - new SliverFillRemaining(child: new Container()), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + controller: controller, + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(height: 100.0)), + new SliverFillRemaining(child: new Container()), + ], + ), ), ); expect(tester.renderObject(find.byType(Container)).size.height, equals(500.0)); diff --git a/packages/flutter/test/widgets/sliver_fill_viewport_test.dart b/packages/flutter/test/widgets/sliver_fill_viewport_test.dart index 79b5d4ecb6f..a2990b3cedb 100644 --- a/packages/flutter/test/widgets/sliver_fill_viewport_test.dart +++ b/packages/flutter/test/widgets/sliver_fill_viewport_test.dart @@ -12,12 +12,15 @@ void main() { }); await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new SliverFillViewport( - delegate: new SliverChildListDelegate(children, addAutomaticKeepAlives: false), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new SliverFillViewport( + delegate: new SliverChildListDelegate(children, addAutomaticKeepAlives: false), + ), + ], + ), ), ); @@ -73,6 +76,7 @@ void main() { ' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' ' │ viewportMainAxisExtent: 600.0)\n' ' │ geometry: SliverGeometry(scrollExtent: 12000.0, paintExtent:\n' ' │ 600.0, maxPaintExtent: 12000.0, hasVisualOverflow: true)\n' @@ -107,7 +111,7 @@ void main() { ' ║ TextSpan:\n' ' ║ \n' ' ║ "0"\n' - ' ╚═══════════\n', + ' ╚═══════════\n' ), ); }); diff --git a/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart b/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart index 52d90c8d3fc..b2bad6a88ab 100644 --- a/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart +++ b/packages/flutter/test/widgets/sliver_prototype_item_extent_test.dart @@ -114,17 +114,20 @@ void main() { }).toList(); await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new SliverPrototypeExtentList( - prototypeItem: items[0], - delegate: new SliverChildBuilderDelegate( - (BuildContext context, int index) => items[index], - childCount: 10, + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new SliverPrototypeExtentList( + prototypeItem: items[0], + delegate: new SliverChildBuilderDelegate( + (BuildContext context, int index) => items[index], + childCount: 10, + ), ), - ), - ], - ) + ], + ), + ), ); // Item 0 exists in the list and as the prototype item. diff --git a/packages/flutter/test/widgets/sliver_semantics_test.dart b/packages/flutter/test/widgets/sliver_semantics_test.dart index 56ca149d35b..2057e820d83 100644 --- a/packages/flutter/test/widgets/sliver_semantics_test.dart +++ b/packages/flutter/test/widgets/sliver_semantics_test.dart @@ -182,12 +182,15 @@ void main() { ); }); await tester.pumpWidget( - new Center( - child: new SizedBox( - height: containerHeight, - child: new CustomScrollView( - controller: scrollController, - slivers: slivers, + new Directionality( + textDirection: TextDirection.ltr, + child: new Center( + child: new SizedBox( + height: containerHeight, + child: new CustomScrollView( + controller: scrollController, + slivers: slivers, + ), ), ), ), @@ -237,8 +240,11 @@ void main() { ); }); await tester.pumpWidget( - new CustomScrollView( - slivers: slivers, + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: slivers, + ), ), ); diff --git a/packages/flutter/test/widgets/slivers_appbar_floating_test.dart b/packages/flutter/test/widgets/slivers_appbar_floating_test.dart index a89e1d3d7db..04b10e8f5c6 100644 --- a/packages/flutter/test/widgets/slivers_appbar_floating_test.dart +++ b/packages/flutter/test/widgets/slivers_appbar_floating_test.dart @@ -26,12 +26,15 @@ void main() { testWidgets('Sliver appbars - floating - scroll offset doesn\'t change', (WidgetTester tester) async { const double bigHeight = 1000.0; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - const BigSliver(height: bigHeight), - new SliverPersistentHeader(delegate: new TestDelegate(), floating: true), - const BigSliver(height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + const BigSliver(height: bigHeight), + new SliverPersistentHeader(delegate: new TestDelegate(), floating: true), + const BigSliver(height: bigHeight), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -53,12 +56,15 @@ void main() { const double bigHeight = 1000.0; GlobalKey key1, key2, key3; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), - new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), + new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -122,12 +128,15 @@ void main() { const double bigHeight = 1000.0; GlobalKey key1, key2, key3; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), - new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), + new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -154,12 +163,15 @@ void main() { const double bigHeight = 1000.0; GlobalKey key1, key2, key3; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), - new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: delegate, floating: true), + new BigSliver(key: key3 = new GlobalKey(), height: bigHeight), + ], + ), ), ); final ScrollPositionWithSingleContext position = tester.state(find.byType(Scrollable)).position; @@ -185,19 +197,22 @@ void main() { testWidgets('Sliver appbars - floating - overscroll gap is below header', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - physics: const BouncingScrollPhysics(), - slivers: [ - new SliverPersistentHeader(delegate: new TestDelegate(), floating: true), - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox( - height: 300.0, - child: const Text('X'), - ), - ]), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + physics: const BouncingScrollPhysics(), + slivers: [ + new SliverPersistentHeader(delegate: new TestDelegate(), floating: true), + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox( + height: 300.0, + child: const Text('X'), + ), + ]), + ), + ], + ), ), ); diff --git a/packages/flutter/test/widgets/slivers_appbar_pinned_test.dart b/packages/flutter/test/widgets/slivers_appbar_pinned_test.dart index 9ffd4063179..3a0f50af587 100644 --- a/packages/flutter/test/widgets/slivers_appbar_pinned_test.dart +++ b/packages/flutter/test/widgets/slivers_appbar_pinned_test.dart @@ -27,14 +27,17 @@ void main() { const double bigHeight = 550.0; GlobalKey key1, key2, key3, key4, key5; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), - new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), - new BigSliver(key: key4 = new GlobalKey(), height: bigHeight), - new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), + new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), + new BigSliver(key: key4 = new GlobalKey(), height: bigHeight), + new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -60,10 +63,13 @@ void main() { final TestDelegateThatCanThrow delegateThatCanThrow = new TestDelegateThatCanThrow(); GlobalKey key; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new SliverPersistentHeader(key: key = new GlobalKey(), delegate: delegateThatCanThrow, pinned: true), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new SliverPersistentHeader(key: key = new GlobalKey(), delegate: delegateThatCanThrow, pinned: true), + ], + ), ), ); await tester.pumpAndSettle(const Duration(milliseconds: 10)); @@ -90,6 +96,7 @@ void main() { ' │ constraints: SliverConstraints(AxisDirection.down,\n' ' │ GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n' ' │ 0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n' + ' │ crossAxisDirection: AxisDirection.right,\n' ' │ viewportMainAxisExtent: 600.0)\n' ' │ geometry: SliverGeometry(scrollExtent: 200.0, paintExtent: 200.0,\n' ' │ maxPaintExtent: 200.0, hasVisualOverflow: true)\n' @@ -135,7 +142,7 @@ void main() { ' parentData: (can use size)\n' ' constraints: BoxConstraints(w=800.0, 100.0<=h<=200.0)\n' ' size: Size(800.0, 200.0)\n' - ' additionalConstraints: BoxConstraints(biggest)\n', + ' additionalConstraints: BoxConstraints(biggest)\n' ), ); }); @@ -144,14 +151,17 @@ void main() { const double bigHeight = 550.0; GlobalKey key1, key2, key3, key4, key5; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), - new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), - new BigSliver(key: key4 = new GlobalKey(), height: bigHeight), - new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), + new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), + new BigSliver(key: key4 = new GlobalKey(), height: bigHeight), + new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), + ], + ), ), ); @@ -234,14 +244,17 @@ void main() { const double bigHeight = 650.0; GlobalKey key1, key2, key3, key4, key5; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), - new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), - new BigSliver(key: key4 = new GlobalKey(), height: bigHeight), - new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey(), height: bigHeight), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), + new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate(), pinned: true), + new BigSliver(key: key4 = new GlobalKey(), height: bigHeight), + new BigSliver(key: key5 = new GlobalKey(), height: bigHeight), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -265,19 +278,22 @@ void main() { testWidgets('Sliver appbars - overscroll gap is below header', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - physics: const BouncingScrollPhysics(), - slivers: [ - new SliverPersistentHeader(delegate: new TestDelegate(), pinned: true), - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox( - height: 300.0, - child: const Text('X'), - ), - ]), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + physics: const BouncingScrollPhysics(), + slivers: [ + new SliverPersistentHeader(delegate: new TestDelegate(), pinned: true), + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox( + height: 300.0, + child: const Text('X'), + ), + ]), + ), + ], + ), ), ); diff --git a/packages/flutter/test/widgets/slivers_appbar_scrolling_test.dart b/packages/flutter/test/widgets/slivers_appbar_scrolling_test.dart index 346a8a181e5..fc5339202e9 100644 --- a/packages/flutter/test/widgets/slivers_appbar_scrolling_test.dart +++ b/packages/flutter/test/widgets/slivers_appbar_scrolling_test.dart @@ -18,14 +18,17 @@ void main() { testWidgets('Sliver appbars - scrolling', (WidgetTester tester) async { GlobalKey key1, key2, key3, key4, key5; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey()), - new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate()), - new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate()), - new BigSliver(key: key4 = new GlobalKey()), - new BigSliver(key: key5 = new GlobalKey()), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey()), + new SliverPersistentHeader(key: key2 = new GlobalKey(), delegate: new TestDelegate()), + new SliverPersistentHeader(key: key3 = new GlobalKey(), delegate: new TestDelegate()), + new BigSliver(key: key4 = new GlobalKey()), + new BigSliver(key: key5 = new GlobalKey()), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -51,13 +54,16 @@ void main() { final GlobalKey key = new GlobalKey(); final TestDelegate delegate = new TestDelegate(); await tester.pumpWidget( - new CustomScrollView( - slivers: [ - const BigSliver(), - new SliverPersistentHeader(key: key, delegate: delegate), - const BigSliver(), - const BigSliver(), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + const BigSliver(), + new SliverPersistentHeader(key: key, delegate: delegate), + const BigSliver(), + const BigSliver(), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; @@ -70,19 +76,22 @@ void main() { testWidgets('Sliver appbars - scrolling - overscroll gap is below header', (WidgetTester tester) async { await tester.pumpWidget( - new CustomScrollView( - physics: const BouncingScrollPhysics(), - slivers: [ - new SliverPersistentHeader(delegate: new TestDelegate()), - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox( - height: 300.0, - child: const Text('X'), - ), - ]), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + physics: const BouncingScrollPhysics(), + slivers: [ + new SliverPersistentHeader(delegate: new TestDelegate()), + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox( + height: 300.0, + child: const Text('X'), + ), + ]), + ), + ], + ), ), ); diff --git a/packages/flutter/test/widgets/slivers_block_global_key_test.dart b/packages/flutter/test/widgets/slivers_block_global_key_test.dart index ce561f2bc76..b1df7cdca26 100644 --- a/packages/flutter/test/widgets/slivers_block_global_key_test.dart +++ b/packages/flutter/test/widgets/slivers_block_global_key_test.dart @@ -24,16 +24,21 @@ class _GenerationTextState extends State { Future test(WidgetTester tester, double offset, List keys) { globalGeneration += 1; - return tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(offset), - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate(keys.map((int key) { - return new SizedBox(key: new GlobalObjectKey(key), height: 100.0, child: new GenerationText(key)); - }).toList()), + return tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(offset), + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate(keys.map((int key) { + return new SizedBox(key: new GlobalObjectKey(key), height: 100.0, child: new GenerationText(key)); + }).toList()), + ), + ], ), - ], - )); + ), + ); } void verify(WidgetTester tester, List answerKey, String text) { diff --git a/packages/flutter/test/widgets/slivers_block_test.dart b/packages/flutter/test/widgets/slivers_block_test.dart index 7e2b67fc9c7..2d0556ab31f 100644 --- a/packages/flutter/test/widgets/slivers_block_test.dart +++ b/packages/flutter/test/widgets/slivers_block_test.dart @@ -9,20 +9,25 @@ import 'package:flutter/widgets.dart'; import '../rendering/mock_canvas.dart'; Future test(WidgetTester tester, double offset) { - return tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(offset), - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 400.0, child: const Text('a')), - const SizedBox(height: 400.0, child: const Text('b')), - const SizedBox(height: 400.0, child: const Text('c')), - const SizedBox(height: 400.0, child: const Text('d')), - const SizedBox(height: 400.0, child: const Text('e')), - ]), + return tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(offset), + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 400.0, child: const Text('a')), + const SizedBox(height: 400.0, child: const Text('b')), + const SizedBox(height: 400.0, child: const Text('c')), + const SizedBox(height: 400.0, child: const Text('d')), + const SizedBox(height: 400.0, child: const Text('e')), + ]), + ), + ], ), - ], - )); + ), + ); } void verify(WidgetTester tester, List answerKey, String text) { @@ -74,84 +79,109 @@ void main() { testWidgets('Viewport with GlobalKey reparenting', (WidgetTester tester) async { final Key key1 = new GlobalKey(); final ViewportOffset offset = new ViewportOffset.zero(); - await tester.pumpWidget(new Viewport( - offset: offset, - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 251.0, child: const Text('a')), - const SizedBox(height: 252.0, child: const Text('b')), - new SizedBox(key: key1, height: 253.0, child: const Text('c')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: offset, + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 251.0, child: const Text('a')), + const SizedBox(height: 252.0, child: const Text('b')), + new SizedBox(key: key1, height: 253.0, child: const Text('c')), + ]), + ), + ], ), - ], - )); + ), + ); verify(tester, [ const Offset(0.0, 0.0), const Offset(0.0, 251.0), const Offset(0.0, 503.0), ], 'abc'); - await tester.pumpWidget(new Viewport( - offset: offset, - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - new SizedBox(key: key1, height: 253.0, child: const Text('c')), - const SizedBox(height: 251.0, child: const Text('a')), - const SizedBox(height: 252.0, child: const Text('b')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: offset, + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + new SizedBox(key: key1, height: 253.0, child: const Text('c')), + const SizedBox(height: 251.0, child: const Text('a')), + const SizedBox(height: 252.0, child: const Text('b')), + ]), + ), + ], ), - ], - )); + ), + ); verify(tester, [ const Offset(0.0, 0.0), const Offset(0.0, 253.0), const Offset(0.0, 504.0), ], 'cab'); - await tester.pumpWidget(new Viewport( - offset: offset, - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 251.0, child: const Text('a')), - new SizedBox(key: key1, height: 253.0, child: const Text('c')), - const SizedBox(height: 252.0, child: const Text('b')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: offset, + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 251.0, child: const Text('a')), + new SizedBox(key: key1, height: 253.0, child: const Text('c')), + const SizedBox(height: 252.0, child: const Text('b')), + ]), + ), + ], ), - ], - )); + ), + ); verify(tester, [ const Offset(0.0, 0.0), const Offset(0.0, 251.0), const Offset(0.0, 504.0), ], 'acb'); - await tester.pumpWidget(new Viewport( - offset: offset, - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 251.0, child: const Text('a')), - const SizedBox(height: 252.0, child: const Text('b')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: offset, + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 251.0, child: const Text('a')), + const SizedBox(height: 252.0, child: const Text('b')), + ]), + ), + ], ), - ], - )); + ), + ); verify(tester, [ const Offset(0.0, 0.0), const Offset(0.0, 251.0), ], 'ab'); - await tester.pumpWidget(new Viewport( - offset: offset, - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 251.0, child: const Text('a')), - new SizedBox(key: key1, height: 253.0, child: const Text('c')), - const SizedBox(height: 252.0, child: const Text('b')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: offset, + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 251.0, child: const Text('a')), + new SizedBox(key: key1, height: 253.0, child: const Text('c')), + const SizedBox(height: 252.0, child: const Text('b')), + ]), + ), + ], ), - ], - )); + ), + ); verify(tester, [ const Offset(0.0, 0.0), const Offset(0.0, 251.0), @@ -160,101 +190,141 @@ void main() { }); testWidgets('Viewport overflow clipping of SliverToBoxAdapter', (WidgetTester tester) async { - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.zero(), - slivers: [ - const SliverToBoxAdapter( - child: const SizedBox(height: 400.0, child: const Text('a')), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.zero(), + slivers: [ + const SliverToBoxAdapter( + child: const SizedBox(height: 400.0, child: const Text('a')), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), isNot(paints..clipRect())); - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(100.0), - slivers: [ - const SliverToBoxAdapter( - child: const SizedBox(height: 400.0, child: const Text('a')), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(100.0), + slivers: [ + const SliverToBoxAdapter( + child: const SizedBox(height: 400.0, child: const Text('a')), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), paints..clipRect()); - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(100.0), - slivers: [ - const SliverToBoxAdapter( - child: const SizedBox(height: 4000.0, child: const Text('a')), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(100.0), + slivers: [ + const SliverToBoxAdapter( + child: const SizedBox(height: 4000.0, child: const Text('a')), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), paints..clipRect()); - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.zero(), - slivers: [ - const SliverToBoxAdapter( - child: const SizedBox(height: 4000.0, child: const Text('a')), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.zero(), + slivers: [ + const SliverToBoxAdapter( + child: const SizedBox(height: 4000.0, child: const Text('a')), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), paints..clipRect()); }); testWidgets('Viewport overflow clipping of SliverBlock', (WidgetTester tester) async { - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.zero(), - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 400.0, child: const Text('a')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.zero(), + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 400.0, child: const Text('a')), + ]), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), isNot(paints..clipRect())); - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(100.0), - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 400.0, child: const Text('a')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(100.0), + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 400.0, child: const Text('a')), + ]), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), paints..clipRect()); - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(100.0), - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 4000.0, child: const Text('a')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(100.0), + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 4000.0, child: const Text('a')), + ]), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), paints..clipRect()); - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.zero(), - slivers: [ - new SliverList( - delegate: new SliverChildListDelegate([ - const SizedBox(height: 4000.0, child: const Text('a')), - ]), + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.zero(), + slivers: [ + new SliverList( + delegate: new SliverChildListDelegate([ + const SizedBox(height: 4000.0, child: const Text('a')), + ]), + ), + ], ), - ], - )); + ), + ); expect(find.byType(Viewport), paints..clipRect()); }); diff --git a/packages/flutter/test/widgets/slivers_padding_test.dart b/packages/flutter/test/widgets/slivers_padding_test.dart index faa2681df42..d40be985d38 100644 --- a/packages/flutter/test/widgets/slivers_padding_test.dart +++ b/packages/flutter/test/widgets/slivers_padding_test.dart @@ -6,26 +6,24 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; -Future test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, { TextDirection textDirection }) { - Widget widget = new Viewport( - offset: new ViewportOffset.fixed(offset), - axisDirection: axisDirection, - slivers: [ - const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('before'))), - new SliverPadding( - padding: padding, - sliver: const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('padded'))), - ), - const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('after'))), - ], - ); - if (textDirection != null) { - widget = new Directionality( +Future test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) { + return tester.pumpWidget( + new Directionality( textDirection: textDirection, - child: widget, - ); - } - return tester.pumpWidget(widget); + child: new Viewport( + offset: new ViewportOffset.fixed(offset), + axisDirection: axisDirection, + slivers: [ + const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('before'))), + new SliverPadding( + padding: padding, + sliver: const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('padded'))), + ), + const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('after'))), + ], + ), + ), + ); } void verify(WidgetTester tester, List answerKey) { @@ -42,7 +40,7 @@ void verify(WidgetTester tester, List answerKey) { void main() { testWidgets('Viewport+SliverPadding basic test (VISUAL)', (WidgetTester tester) async { final EdgeInsets padding = const EdgeInsets.fromLTRB(25.0, 20.0, 15.0, 35.0); - await test(tester, 0.0, padding, AxisDirection.down); + await test(tester, 0.0, padding, AxisDirection.down, TextDirection.ltr); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(0.0, 0.0, 800.0, 400.0), @@ -50,28 +48,28 @@ void main() { new Rect.fromLTWH(0.0, 600.0, 800.0, 400.0), ]); - await test(tester, 200.0, padding, AxisDirection.down); + await test(tester, 200.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -200.0, 800.0, 400.0), new Rect.fromLTWH(25.0, 220.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 600.0, 800.0, 400.0), ]); - await test(tester, 390.0, padding, AxisDirection.down); + await test(tester, 390.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -390.0, 800.0, 400.0), new Rect.fromLTWH(25.0, 30.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 465.0, 800.0, 400.0), ]); - await test(tester, 490.0, padding, AxisDirection.down); + await test(tester, 490.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -490.0, 800.0, 400.0), new Rect.fromLTWH(25.0, -70.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 365.0, 800.0, 400.0), ]); - await test(tester, 10000.0, padding, AxisDirection.down); + await test(tester, 10000.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -10000.0, 800.0, 400.0), new Rect.fromLTWH(25.0, -9580.0, 760.0, 400.0), @@ -81,7 +79,7 @@ void main() { testWidgets('Viewport+SliverPadding basic test (LTR)', (WidgetTester tester) async { final EdgeInsetsDirectional padding = const EdgeInsetsDirectional.fromSTEB(25.0, 20.0, 15.0, 35.0); - await test(tester, 0.0, padding, AxisDirection.down, textDirection: TextDirection.ltr); + await test(tester, 0.0, padding, AxisDirection.down, TextDirection.ltr); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(0.0, 0.0, 800.0, 400.0), @@ -89,28 +87,28 @@ void main() { new Rect.fromLTWH(0.0, 600.0, 800.0, 400.0), ]); - await test(tester, 200.0, padding, AxisDirection.down, textDirection: TextDirection.ltr); + await test(tester, 200.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -200.0, 800.0, 400.0), new Rect.fromLTWH(25.0, 220.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 600.0, 800.0, 400.0), ]); - await test(tester, 390.0, padding, AxisDirection.down, textDirection: TextDirection.ltr); + await test(tester, 390.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -390.0, 800.0, 400.0), new Rect.fromLTWH(25.0, 30.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 465.0, 800.0, 400.0), ]); - await test(tester, 490.0, padding, AxisDirection.down, textDirection: TextDirection.ltr); + await test(tester, 490.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -490.0, 800.0, 400.0), new Rect.fromLTWH(25.0, -70.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 365.0, 800.0, 400.0), ]); - await test(tester, 10000.0, padding, AxisDirection.down, textDirection: TextDirection.ltr); + await test(tester, 10000.0, padding, AxisDirection.down, TextDirection.ltr); verify(tester, [ new Rect.fromLTWH(0.0, -10000.0, 800.0, 400.0), new Rect.fromLTWH(25.0, -9580.0, 760.0, 400.0), @@ -120,7 +118,7 @@ void main() { testWidgets('Viewport+SliverPadding basic test (RTL)', (WidgetTester tester) async { final EdgeInsetsDirectional padding = const EdgeInsetsDirectional.fromSTEB(25.0, 20.0, 15.0, 35.0); - await test(tester, 0.0, padding, AxisDirection.down, textDirection: TextDirection.rtl); + await test(tester, 0.0, padding, AxisDirection.down, TextDirection.rtl); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(0.0, 0.0, 800.0, 400.0), @@ -128,28 +126,28 @@ void main() { new Rect.fromLTWH(0.0, 600.0, 800.0, 400.0), ]); - await test(tester, 200.0, padding, AxisDirection.down, textDirection: TextDirection.rtl); + await test(tester, 200.0, padding, AxisDirection.down, TextDirection.rtl); verify(tester, [ new Rect.fromLTWH(0.0, -200.0, 800.0, 400.0), new Rect.fromLTWH(15.0, 220.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 600.0, 800.0, 400.0), ]); - await test(tester, 390.0, padding, AxisDirection.down, textDirection: TextDirection.rtl); + await test(tester, 390.0, padding, AxisDirection.down, TextDirection.rtl); verify(tester, [ new Rect.fromLTWH(0.0, -390.0, 800.0, 400.0), new Rect.fromLTWH(15.0, 30.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 465.0, 800.0, 400.0), ]); - await test(tester, 490.0, padding, AxisDirection.down, textDirection: TextDirection.rtl); + await test(tester, 490.0, padding, AxisDirection.down, TextDirection.rtl); verify(tester, [ new Rect.fromLTWH(0.0, -490.0, 800.0, 400.0), new Rect.fromLTWH(15.0, -70.0, 760.0, 400.0), new Rect.fromLTWH(0.0, 365.0, 800.0, 400.0), ]); - await test(tester, 10000.0, padding, AxisDirection.down, textDirection: TextDirection.rtl); + await test(tester, 10000.0, padding, AxisDirection.down, TextDirection.rtl); verify(tester, [ new Rect.fromLTWH(0.0, -10000.0, 800.0, 400.0), new Rect.fromLTWH(15.0, -9580.0, 760.0, 400.0), @@ -159,7 +157,7 @@ void main() { testWidgets('Viewport+SliverPadding hit testing', (WidgetTester tester) async { final EdgeInsets padding = const EdgeInsets.all(30.0); - await test(tester, 350.0, padding, AxisDirection.down); + await test(tester, 350.0, padding, AxisDirection.down, TextDirection.ltr); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(0.0, -350.0, 800.0, 400.0), @@ -181,7 +179,7 @@ void main() { testWidgets('Viewport+SliverPadding hit testing up', (WidgetTester tester) async { final EdgeInsets padding = const EdgeInsets.all(30.0); - await test(tester, 350.0, padding, AxisDirection.up); + await test(tester, 350.0, padding, AxisDirection.up, TextDirection.ltr); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(0.0, 600.0+350.0-400.0, 800.0, 400.0), @@ -203,7 +201,7 @@ void main() { testWidgets('Viewport+SliverPadding hit testing left', (WidgetTester tester) async { final EdgeInsets padding = const EdgeInsets.all(30.0); - await test(tester, 350.0, padding, AxisDirection.left); + await test(tester, 350.0, padding, AxisDirection.left, TextDirection.ltr); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(800.0+350.0-400.0, 0.0, 400.0, 600.0), @@ -225,7 +223,7 @@ void main() { testWidgets('Viewport+SliverPadding hit testing right', (WidgetTester tester) async { final EdgeInsets padding = const EdgeInsets.all(30.0); - await test(tester, 350.0, padding, AxisDirection.right); + await test(tester, 350.0, padding, AxisDirection.right, TextDirection.ltr); expect(tester.renderObject(find.byType(Viewport)).size, equals(const Size(800.0, 600.0))); verify(tester, [ new Rect.fromLTWH(-350.0, 0.0, 400.0, 600.0), @@ -246,77 +244,117 @@ void main() { }); testWidgets('Viewport+SliverPadding no child', (WidgetTester tester) async { - await tester.pumpWidget(new Viewport( - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.all(100.0)), - const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('x'))), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.all(100.0)), + const SliverToBoxAdapter(child: const SizedBox(width: 400.0, height: 400.0, child: const Text('x'))), + ], + ), + ), + ); expect(tester.renderObject(find.text('x')).localToGlobal(Offset.zero), const Offset(0.0, 200.0)); }); testWidgets('Viewport+SliverPadding changing padding', (WidgetTester tester) async { - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.left, - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(90.0, 1.0, 110.0, 2.0)), - const SliverToBoxAdapter(child: const SizedBox(width: 201.0, child: const Text('x'))), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.left, + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(90.0, 1.0, 110.0, 2.0)), + const SliverToBoxAdapter(child: const SizedBox(width: 201.0, child: const Text('x'))), + ], + ), + ), + ); expect(tester.renderObject(find.text('x')).localToGlobal(Offset.zero), const Offset(399.0, 0.0)); - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.left, - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(110.0, 1.0, 80.0, 2.0)), - const SliverToBoxAdapter(child: const SizedBox(width: 201.0, child: const Text('x'))), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.left, + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(110.0, 1.0, 80.0, 2.0)), + const SliverToBoxAdapter(child: const SizedBox(width: 201.0, child: const Text('x'))), + ], + ), + ), + ); expect(tester.renderObject(find.text('x')).localToGlobal(Offset.zero), const Offset(409.0, 0.0)); }); testWidgets('Viewport+SliverPadding changing direction', (WidgetTester tester) async { - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.up, - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.up, + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), + ], + ), + ), + ); expect(tester.renderObject(find.byType(SliverPadding)).afterPadding, 2.0); - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.down, - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.down, + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), + ], + ), + ), + ); expect(tester.renderObject(find.byType(SliverPadding)).afterPadding, 8.0); - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.right, - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.right, + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), + ], + ), + ), + ); expect(tester.renderObject(find.byType(SliverPadding)).afterPadding, 4.0); - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.left, - offset: new ViewportOffset.fixed(0.0), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.left, + offset: new ViewportOffset.fixed(0.0), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), + ], + ), + ), + ); expect(tester.renderObject(find.byType(SliverPadding)).afterPadding, 1.0); - await tester.pumpWidget(new Viewport( - axisDirection: AxisDirection.left, - offset: new ViewportOffset.fixed(99999.9), - slivers: [ - const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), - ], - )); + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + axisDirection: AxisDirection.left, + offset: new ViewportOffset.fixed(99999.9), + slivers: [ + const SliverPadding(padding: const EdgeInsets.fromLTRB(1.0, 2.0, 4.0, 8.0)), + ], + ), + ), + ); expect(tester.renderObject(find.byType(SliverPadding)).afterPadding, 1.0); }); } diff --git a/packages/flutter/test/widgets/slivers_protocol_test.dart b/packages/flutter/test/widgets/slivers_protocol_test.dart index 88a2c143375..aa8d6735241 100644 --- a/packages/flutter/test/widgets/slivers_protocol_test.dart +++ b/packages/flutter/test/widgets/slivers_protocol_test.dart @@ -20,14 +20,17 @@ void main() { testWidgets('Sliver protocol', (WidgetTester tester) async { GlobalKey key1, key2, key3, key4, key5; await tester.pumpWidget( - new CustomScrollView( - slivers: [ - new BigSliver(key: key1 = new GlobalKey()), - new OverlappingSliver(key: key2 = new GlobalKey()), - new OverlappingSliver(key: key3 = new GlobalKey()), - new BigSliver(key: key4 = new GlobalKey()), - new BigSliver(key: key5 = new GlobalKey()), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new CustomScrollView( + slivers: [ + new BigSliver(key: key1 = new GlobalKey()), + new OverlappingSliver(key: key2 = new GlobalKey()), + new OverlappingSliver(key: key3 = new GlobalKey()), + new BigSliver(key: key4 = new GlobalKey()), + new BigSliver(key: key5 = new GlobalKey()), + ], + ), ), ); final ScrollPosition position = tester.state(find.byType(Scrollable)).position; diff --git a/packages/flutter/test/widgets/slivers_test.dart b/packages/flutter/test/widgets/slivers_test.dart index b23ccb0655e..5bc1e8ad71f 100644 --- a/packages/flutter/test/widgets/slivers_test.dart +++ b/packages/flutter/test/widgets/slivers_test.dart @@ -7,17 +7,22 @@ import 'package:flutter/widgets.dart'; import 'package:flutter/rendering.dart'; Future test(WidgetTester tester, double offset, { double anchor: 0.0 }) { - return tester.pumpWidget(new Viewport( - anchor: anchor / 600.0, - offset: new ViewportOffset.fixed(offset), - slivers: [ - 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)), - const SliverToBoxAdapter(child: const SizedBox(height: 400.0)), - ], - )); + return tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Viewport( + anchor: anchor / 600.0, + offset: new ViewportOffset.fixed(offset), + slivers: [ + 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)), + const SliverToBoxAdapter(child: const SizedBox(height: 400.0)), + ], + ), + ), + ); } void verify(WidgetTester tester, List idealPositions, List idealVisibles) { diff --git a/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart b/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart index 858cc21fd20..0ae6ecc60c7 100644 --- a/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart +++ b/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart @@ -79,7 +79,12 @@ class FooScrollBehavior extends ScrollBehavior { void main() { 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(find.byType(Scrollable)).position.pixels, 0.0); await tester.tap(find.byType(GestureDetector).first); await tester.pumpAndSettle(); diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index 6170ec8bb68..e10deba75ff 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -50,26 +50,29 @@ void main() { String paragraphText(RenderParagraph paragraph) => paragraph.text.text; await tester.pumpWidget( - new WidgetInspector( - key: inspectorKey, - selectButtonBuilder: selectButtonBuilder, - child: new Material( - child: new ListView( - children: [ - new RaisedButton( - key: topButtonKey, - onPressed: () { - log.add('top'); - }, - child: const Text('TOP'), - ), - new RaisedButton( - onPressed: () { - log.add('bottom'); - }, - child: const Text('BOTTOM'), - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new WidgetInspector( + key: inspectorKey, + selectButtonBuilder: selectButtonBuilder, + child: new Material( + child: new ListView( + children: [ + new RaisedButton( + key: topButtonKey, + onPressed: () { + log.add('top'); + }, + child: const Text('TOP'), + ), + new RaisedButton( + onPressed: () { + log.add('bottom'); + }, + child: const Text('BOTTOM'), + ), + ], + ), ), ), ), @@ -118,16 +121,19 @@ void main() { dynamic getInspectorState() => inspectorKey.currentState; await tester.pumpWidget( - new WidgetInspector( - key: inspectorKey, - selectButtonBuilder: selectButtonBuilder, - child: new ListView( - children: [ - new Container( - key: childKey, - height: 5000.0, - ), - ], + new Directionality( + textDirection: TextDirection.ltr, + child: new WidgetInspector( + key: inspectorKey, + selectButtonBuilder: selectButtonBuilder, + child: new ListView( + children: [ + new Container( + key: childKey, + height: 5000.0, + ), + ], + ), ), ), );