diff --git a/packages/flutter/lib/src/painting/edge_insets.dart b/packages/flutter/lib/src/painting/edge_insets.dart index 5ebbc56a9a..aede3926e7 100644 --- a/packages/flutter/lib/src/painting/edge_insets.dart +++ b/packages/flutter/lib/src/painting/edge_insets.dart @@ -6,6 +6,15 @@ import 'dart:ui' as ui show lerpDouble, WindowPadding; import 'basic_types.dart'; +/// The two cardinal directions in two dimensions. +enum Axis { + /// Left and right + horizontal, + + /// Up and down + vertical, +} + /// An immutable set of offsets in each of the four cardinal directions. /// /// Typically used for an offset from each of the four sides of a box. For @@ -56,6 +65,18 @@ class EdgeInsets { /// The total offset in the horizontal direction. double get vertical => top + bottom; + /// The total offset in the given direction. + double along(Axis axis) { + assert(axis != null); + switch (axis) { + case Axis.horizontal: + return horizontal; + case Axis.vertical: + return vertical; + } + return null; + } + /// The size that this EdgeInsets would occupy with an empty interior. Size get collapsedSize => new Size(horizontal, vertical); diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index c39edfccfb..cb7759a60e 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -19,15 +19,6 @@ class _DebugSize extends Size { final bool _canBeUsedByParent; } -/// The two cardinal directions in two dimensions. -enum Axis { - /// Left and right - horizontal, - - /// Up and down - vertical, -} - /// Immutable layout constraints for box layout. /// /// A size respects a BoxConstraints if, and only if, all of the following @@ -130,10 +121,10 @@ class BoxConstraints extends Constraints { BoxConstraints deflate(EdgeInsets edges) { assert(edges != null); assert(debugAssertIsValid()); - double horizontal = edges.left + edges.right; - double vertical = edges.top + edges.bottom; - double deflatedMinWidth = math.max(0.0, minWidth - horizontal); - double deflatedMinHeight = math.max(0.0, minHeight - vertical); + final double horizontal = edges.horizontal; + final double vertical = edges.vertical; + final double deflatedMinWidth = math.max(0.0, minWidth - horizontal); + final double deflatedMinHeight = math.max(0.0, minHeight - vertical); return new BoxConstraints( minWidth: deflatedMinWidth, maxWidth: math.max(deflatedMinWidth, maxWidth - horizontal), @@ -1144,7 +1135,7 @@ abstract class RenderBox extends RenderObject { /// The caller is responsible for transforming [position] into the local /// coordinate space of the callee. The callee is responsible for checking /// whether the given position is within its bounds. - bool hitTest(HitTestResult result, { Point position }) { + bool hitTest(HitTestResult result, { @required Point position }) { assert(() { if (needsLayout) { throw new FlutterError( diff --git a/packages/flutter/lib/src/rendering/list.dart b/packages/flutter/lib/src/rendering/list.dart index 0eb2c2f633..d695780ab8 100644 --- a/packages/flutter/lib/src/rendering/list.dart +++ b/packages/flutter/lib/src/rendering/list.dart @@ -75,17 +75,6 @@ class RenderList extends RenderVirtualViewport { child.parentData = new ListParentData(); } - double get _scrollAxisPadding { - switch (mainAxis) { - case Axis.vertical: - return padding.vertical; - case Axis.horizontal: - return padding.horizontal; - } - assert(mainAxis != null); - return null; - } - double get _preferredExtent { if (itemExtent == null) return double.INFINITY; @@ -94,7 +83,7 @@ class RenderList extends RenderVirtualViewport { return double.INFINITY; double extent = itemExtent * count; if (padding != null) - extent += _scrollAxisPadding; + extent += padding.along(mainAxis); return extent; } diff --git a/packages/flutter/lib/src/rendering/viewport.dart b/packages/flutter/lib/src/rendering/viewport.dart index b6a70d01fa..e7238727f5 100644 --- a/packages/flutter/lib/src/rendering/viewport.dart +++ b/packages/flutter/lib/src/rendering/viewport.dart @@ -274,7 +274,7 @@ class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin< @override void performLayout() { - ViewportDimensions oldDimensions = dimensions; + final ViewportDimensions oldDimensions = dimensions; if (child != null) { child.layout(_getInnerConstraints(constraints), parentUsesSize: true); size = constraints.constrain(child.size); diff --git a/packages/flutter/lib/src/widgets/lazy_block.dart b/packages/flutter/lib/src/widgets/lazy_block.dart index c560880d85..1b2298f683 100644 --- a/packages/flutter/lib/src/widgets/lazy_block.dart +++ b/packages/flutter/lib/src/widgets/lazy_block.dart @@ -315,18 +315,7 @@ class LazyBlockViewport extends RenderObjectWidget { /// See [LazyBlockDelegate] for details. final LazyBlockDelegate delegate; - double get _mainAxisPadding { - if (padding == null) - return 0.0; - switch (mainAxis) { - case Axis.horizontal: - return padding.horizontal; - case Axis.vertical: - return padding.vertical; - } - assert(mainAxis != null); - return null; - } + double get _mainAxisPadding => padding == null ? 0.0 : padding.along(mainAxis); @override _LazyBlockElement createElement() => new _LazyBlockElement(this);