Commit 149f788c authored by Hans Muller's avatar Hans Muller

Use lowerBound() from package:collection/collection.dart

parent df94a0ea
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:collection/collection.dart' show lowerBound;
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'framework.dart'; import 'framework.dart';
...@@ -84,24 +85,6 @@ class GridViewport extends VirtualViewportFromIterable { ...@@ -84,24 +85,6 @@ class GridViewport extends VirtualViewportFromIterable {
_GridViewportElement createElement() => new _GridViewportElement(this); _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<GridViewport> { class _GridViewportElement extends VirtualViewportElement<GridViewport> {
_GridViewportElement(GridViewport widget) : super(widget); _GridViewportElement(GridViewport widget) : super(widget);
...@@ -133,8 +116,8 @@ class _GridViewportElement extends VirtualViewportElement<GridViewport> { ...@@ -133,8 +116,8 @@ class _GridViewportElement extends VirtualViewportElement<GridViewport> {
double contentExtent = _specification.gridSize.height; double contentExtent = _specification.gridSize.height;
double containerExtent = renderObject.size.height; double containerExtent = renderObject.size.height;
int materializedRowBase = math.max(0, _lowerBound(_specification.rowOffsets, widget.startOffset) - 1); int materializedRowBase = math.max(0, lowerBound(_specification.rowOffsets, widget.startOffset) - 1);
int materializedRowLimit = math.min(_specification.rowCount, _lowerBound(_specification.rowOffsets, widget.startOffset + containerExtent)); int materializedRowLimit = math.min(_specification.rowCount, lowerBound(_specification.rowOffsets, widget.startOffset + containerExtent));
_materializedChildBase = (materializedRowBase * _specification.columnCount).clamp(0, renderObject.virtualChildCount); _materializedChildBase = (materializedRowBase * _specification.columnCount).clamp(0, renderObject.virtualChildCount);
_materializedChildCount = (materializedRowLimit * _specification.columnCount).clamp(0, renderObject.virtualChildCount) - _materializedChildBase; _materializedChildCount = (materializedRowLimit * _specification.columnCount).clamp(0, renderObject.virtualChildCount) - _materializedChildBase;
......
...@@ -5,7 +5,7 @@ description: A framework for writing Flutter applications ...@@ -5,7 +5,7 @@ description: A framework for writing Flutter applications
homepage: http://flutter.io homepage: http://flutter.io
dependencies: dependencies:
collection: '>=1.1.3 <2.0.0' collection: '>=1.4.0 <2.0.0'
intl: '>=0.12.4+2 <0.13.0' intl: '>=0.12.4+2 <0.13.0'
vector_math: '>=1.4.5 <2.0.0' vector_math: '>=1.4.5 <2.0.0'
quiver: '>=0.21.4 <0.22.0' quiver: '>=0.21.4 <0.22.0'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment