Commit 2b3099c8 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Always select a diagonal for ArcTween even if begin and end rects are equal (#5151)

Fixes https://github.com/flutter/flutter/issues/5086
parent f59d04bf
......@@ -243,3 +243,21 @@ class _LazyListIterator<E> implements Iterator<E> {
return true;
}
}
// COLLECTION UTILITIES
typedef dynamic KeyFunc<T>(T input);
/// Select the element for which the key function returns the maximum value.
dynamic/*=T*/ maxBy/*<T>*/(Iterable<dynamic/*=T*/> input, KeyFunc/*<T>*/ keyFunc) {
dynamic/*=T*/ maxValue;
dynamic maxKey;
for (dynamic/*=T*/ value in input) {
dynamic key = keyFunc(value);
if (maxKey == null || key > maxKey) {
maxValue = value;
maxKey = key;
}
}
return maxValue;
}
......@@ -5,6 +5,7 @@
import 'dart:math' as math;
import 'dart:ui' show hashValues, lerpDouble;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
......@@ -165,14 +166,7 @@ class MaterialRectArcTween extends RectTween {
@required Rect end
}) : super(begin: begin, end: end) {
final Offset centersVector = end.center - begin.center;
double maxSupport = 0.0;
for (_Diagonal diagonal in _allDiagonals) {
final double support = _diagonalSupport(centersVector, diagonal);
if (support > maxSupport) {
_diagonal = diagonal;
maxSupport = support;
}
}
_diagonal = maxBy(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d));
_beginArc = new MaterialPointArcTween(
begin: _cornerFor(begin, _diagonal.beginId),
end: _cornerFor(end, _diagonal.beginId)
......
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