From 149f788c9edbaa5768a1cf060c2f36fcbc41a87c Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Wed, 9 Mar 2016 09:22:51 -0800 Subject: [PATCH] Use lowerBound() from package:collection/collection.dart --- .../lib/src/widgets/scrollable_grid.dart | 23 +++---------------- packages/flutter/pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/packages/flutter/lib/src/widgets/scrollable_grid.dart b/packages/flutter/lib/src/widgets/scrollable_grid.dart index 6cdd873220..1d0ebbb3cc 100644 --- a/packages/flutter/lib/src/widgets/scrollable_grid.dart +++ b/packages/flutter/lib/src/widgets/scrollable_grid.dart @@ -4,6 +4,7 @@ import 'dart:math' as math; +import 'package:collection/collection.dart' show lowerBound; import 'package:flutter/rendering.dart'; import 'framework.dart'; @@ -84,24 +85,6 @@ class GridViewport extends VirtualViewportFromIterable { _GridViewportElement createElement() => new _GridViewportElement(this); } -// TODO(abarth): This function should go somewhere more general. -// See https://github.com/dart-lang/collection/pull/16 -int _lowerBound(List sortedList, var value, { int begin: 0 }) { - int current = begin; - int count = sortedList.length - current; - while (count > 0) { - int step = count >> 1; - int test = current + step; - if (sortedList[test] < value) { - current = test + 1; - count -= step + 1; - } else { - count = step; - } - } - return current; -} - class _GridViewportElement extends VirtualViewportElement { _GridViewportElement(GridViewport widget) : super(widget); @@ -133,8 +116,8 @@ class _GridViewportElement extends VirtualViewportElement { double contentExtent = _specification.gridSize.height; double containerExtent = renderObject.size.height; - int materializedRowBase = math.max(0, _lowerBound(_specification.rowOffsets, widget.startOffset) - 1); - int materializedRowLimit = math.min(_specification.rowCount, _lowerBound(_specification.rowOffsets, widget.startOffset + containerExtent)); + int materializedRowBase = math.max(0, lowerBound(_specification.rowOffsets, widget.startOffset) - 1); + int materializedRowLimit = math.min(_specification.rowCount, lowerBound(_specification.rowOffsets, widget.startOffset + containerExtent)); _materializedChildBase = (materializedRowBase * _specification.columnCount).clamp(0, renderObject.virtualChildCount); _materializedChildCount = (materializedRowLimit * _specification.columnCount).clamp(0, renderObject.virtualChildCount) - _materializedChildBase; diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index b566737ee4..f75dc72161 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -5,7 +5,7 @@ description: A framework for writing Flutter applications homepage: http://flutter.io dependencies: - collection: '>=1.1.3 <2.0.0' + collection: '>=1.4.0 <2.0.0' intl: '>=0.12.4+2 <0.13.0' vector_math: '>=1.4.5 <2.0.0' quiver: '>=0.21.4 <0.22.0'