Unverified Commit e8c94210 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

migrate part of painting to nullsafety (#62951)

parent 2c1b95b9
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:io';
......@@ -33,7 +32,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
final double scale;
@override
final Map<String, String> headers;
final Map<String, String>? headers;
@override
Future<NetworkImage> obtainKey(image_provider.ImageConfiguration configuration) {
......@@ -71,7 +70,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
HttpClient client = _sharedHttpClient;
assert(() {
if (debugNetworkImageHttpClientProvider != null)
client = debugNetworkImageHttpClientProvider();
client = debugNetworkImageHttpClientProvider!();
return true;
}());
return client;
......@@ -102,7 +101,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
final Uint8List bytes = await consolidateHttpClientResponseBytes(
response,
onBytesReceived: (int cumulative, int total) {
onBytesReceived: (int cumulative, int? total) {
chunkEvents.add(ImageChunkEvent(
cumulativeBytesLoaded: cumulative,
expectedTotalBytes: total,
......@@ -118,7 +117,7 @@ class NetworkImage extends image_provider.ImageProvider<image_provider.NetworkIm
// have had a chance to track the key in the cache at all.
// Schedule a microtask to give the cache a chance to add the key.
scheduleMicrotask(() {
PaintingBinding.instance.imageCache.evict(key);
PaintingBinding.instance!.imageCache!.evict(key);
});
rethrow;
} finally {
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:ui' as ui;
......@@ -33,7 +32,7 @@ class NetworkImage
final double scale;
@override
final Map<String, String> headers;
final Map<String, String>? headers;
@override
Future<NetworkImage> obtainKey(
......@@ -58,9 +57,9 @@ class NetworkImage
informationCollector: _imageStreamInformationCollector(key));
}
InformationCollector _imageStreamInformationCollector(
InformationCollector? _imageStreamInformationCollector(
image_provider.NetworkImage key) {
InformationCollector collector;
InformationCollector? collector;
assert(() {
collector = () {
return <DiagnosticsNode>[
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
......@@ -57,24 +56,24 @@ class BeveledRectangleBorder extends OutlinedBorder {
}
@override
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
assert(t != null);
if (a is BeveledRectangleBorder) {
return BeveledRectangleBorder(
side: BorderSide.lerp(a.side, side, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!,
);
}
return super.lerpFrom(a, t);
}
@override
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
assert(t != null);
if (b is BeveledRectangleBorder) {
return BeveledRectangleBorder(
side: BorderSide.lerp(side, b.side, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!,
);
}
return super.lerpTo(b, t);
......@@ -83,7 +82,7 @@ class BeveledRectangleBorder extends OutlinedBorder {
/// Returns a copy of this RoundedRectangleBorder with the given fields
/// replaced with the new values.
@override
BeveledRectangleBorder copyWith({ BorderSide side, BorderRadius borderRadius }) {
BeveledRectangleBorder copyWith({ BorderSide? side, BorderRadius? borderRadius }) {
return BeveledRectangleBorder(
side: side ?? this.side,
borderRadius: borderRadius ?? this.borderRadius,
......@@ -120,17 +119,17 @@ class BeveledRectangleBorder extends OutlinedBorder {
}
@override
Path getInnerPath(Rect rect, { TextDirection textDirection }) {
Path getInnerPath(Rect rect, { TextDirection? textDirection }) {
return _getPath(borderRadius.resolve(textDirection).toRRect(rect).deflate(side.width));
}
@override
Path getOuterPath(Rect rect, { TextDirection textDirection }) {
Path getOuterPath(Rect rect, { TextDirection? textDirection }) {
return _getPath(borderRadius.resolve(textDirection).toRRect(rect));
}
@override
void paint(Canvas canvas, Rect rect, { TextDirection textDirection }) {
void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) {
if (rect.isEmpty)
return;
switch (side.style) {
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
......@@ -130,7 +129,7 @@ abstract class BorderRadiusGeometry {
/// into a concrete [BorderRadius] using [resolve].
///
/// {@macro dart.ui.shadow.lerp}
static BorderRadiusGeometry lerp(BorderRadiusGeometry a, BorderRadiusGeometry b, double t) {
static BorderRadiusGeometry? lerp(BorderRadiusGeometry? a, BorderRadiusGeometry? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
......@@ -148,11 +147,11 @@ abstract class BorderRadiusGeometry {
/// * [BorderRadius], for which this is a no-op (returns itself).
/// * [BorderRadiusDirectional], which flips the horizontal direction
/// based on the `direction` argument.
BorderRadius resolve(TextDirection direction);
BorderRadius resolve(TextDirection? direction);
@override
String toString() {
String visual, logical;
String? visual, logical;
if (_topLeft == _topRight &&
_topRight == _bottomLeft &&
_bottomLeft == _bottomRight) {
......@@ -474,24 +473,24 @@ class BorderRadius extends BorderRadiusGeometry {
/// If either is null, this function interpolates from [BorderRadius.zero].
///
/// {@macro dart.ui.shadow.lerp}
static BorderRadius lerp(BorderRadius a, BorderRadius b, double t) {
static BorderRadius? lerp(BorderRadius? a, BorderRadius? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b * t;
return b! * t;
if (b == null)
return a * (1.0 - t);
return BorderRadius.only(
topLeft: Radius.lerp(a.topLeft, b.topLeft, t),
topRight: Radius.lerp(a.topRight, b.topRight, t),
bottomLeft: Radius.lerp(a.bottomLeft, b.bottomLeft, t),
bottomRight: Radius.lerp(a.bottomRight, b.bottomRight, t),
topLeft: Radius.lerp(a.topLeft, b.topLeft, t)!,
topRight: Radius.lerp(a.topRight, b.topRight, t)!,
bottomLeft: Radius.lerp(a.bottomLeft, b.bottomLeft, t)!,
bottomRight: Radius.lerp(a.bottomRight, b.bottomRight, t)!,
);
}
@override
BorderRadius resolve(TextDirection direction) => this;
BorderRadius resolve(TextDirection? direction) => this;
}
/// An immutable set of radii for each corner of a rectangle, but with the
......@@ -691,26 +690,26 @@ class BorderRadiusDirectional extends BorderRadiusGeometry {
/// If either is null, this function interpolates from [BorderRadiusDirectional.zero].
///
/// {@macro dart.ui.shadow.lerp}
static BorderRadiusDirectional lerp(BorderRadiusDirectional a, BorderRadiusDirectional b, double t) {
static BorderRadiusDirectional? lerp(BorderRadiusDirectional? a, BorderRadiusDirectional? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b * t;
return b! * t;
if (b == null)
return a * (1.0 - t);
return BorderRadiusDirectional.only(
topStart: Radius.lerp(a.topStart, b.topStart, t),
topEnd: Radius.lerp(a.topEnd, b.topEnd, t),
bottomStart: Radius.lerp(a.bottomStart, b.bottomStart, t),
bottomEnd: Radius.lerp(a.bottomEnd, b.bottomEnd, t),
topStart: Radius.lerp(a.topStart, b.topStart, t)!,
topEnd: Radius.lerp(a.topEnd, b.topEnd, t)!,
bottomStart: Radius.lerp(a.bottomStart, b.bottomStart, t)!,
bottomEnd: Radius.lerp(a.bottomEnd, b.bottomEnd, t)!,
);
}
@override
BorderRadius resolve(TextDirection direction) {
BorderRadius resolve(TextDirection? direction) {
assert(direction != null);
switch (direction) {
switch (direction!) {
case TextDirection.rtl:
return BorderRadius.only(
topLeft: topEnd,
......@@ -726,7 +725,6 @@ class BorderRadiusDirectional extends BorderRadiusGeometry {
bottomRight: bottomEnd,
);
}
return null;
}
}
......@@ -838,9 +836,9 @@ class _MixedBorderRadius extends BorderRadiusGeometry {
}
@override
BorderRadius resolve(TextDirection direction) {
BorderRadius resolve(TextDirection? direction) {
assert(direction != null);
switch (direction) {
switch (direction!) {
case TextDirection.rtl:
return BorderRadius.only(
topLeft: _topLeft + _topEnd,
......@@ -856,6 +854,5 @@ class _MixedBorderRadius extends BorderRadiusGeometry {
bottomRight: _bottomRight + _bottomEnd,
);
}
return null;
}
}
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
import 'dart:ui' as ui show lerpDouble;
......@@ -130,9 +129,9 @@ class BorderSide {
/// Creates a copy of this border but with the given fields replaced with the new values.
BorderSide copyWith({
Color color,
double width,
BorderStyle style,
Color? color,
double? width,
BorderStyle? style,
}) {
assert(width == null || width >= 0.0);
return BorderSide(
......@@ -186,7 +185,6 @@ class BorderSide {
..strokeWidth = 0.0
..style = PaintingStyle.stroke;
}
return null;
}
/// Whether the two given [BorderSide]s can be merged using [new
......@@ -219,12 +217,12 @@ class BorderSide {
return a;
if (t == 1.0)
return b;
final double width = ui.lerpDouble(a.width, b.width, t);
final double width = ui.lerpDouble(a.width, b.width, t)!;
if (width < 0.0)
return BorderSide.none;
if (a.style == b.style) {
return BorderSide(
color: Color.lerp(a.color, b.color, t),
color: Color.lerp(a.color, b.color, t)!,
width: width,
style: a.style, // == b.style
);
......@@ -247,7 +245,7 @@ class BorderSide {
break;
}
return BorderSide(
color: Color.lerp(colorA, colorB, t),
color: Color.lerp(colorA, colorB, t)!,
width: width,
style: BorderStyle.solid,
);
......@@ -319,7 +317,7 @@ abstract class ShapeBorder {
/// The `reversed` argument is true if this object was the right operand of
/// the `+` operator, and false if it was the left operand.
@protected
ShapeBorder add(ShapeBorder other, { bool reversed = false }) => null;
ShapeBorder? add(ShapeBorder other, { bool reversed = false }) => null;
/// Creates a new border consisting of the two borders on either side of the
/// operator.
......@@ -382,7 +380,7 @@ abstract class ShapeBorder {
///
/// Instead of calling this directly, use [ShapeBorder.lerp].
@protected
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
if (a == null)
return scale(t);
return null;
......@@ -414,7 +412,7 @@ abstract class ShapeBorder {
///
/// Instead of calling this directly, use [ShapeBorder.lerp].
@protected
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
if (b == null)
return scale(1.0 - t);
return null;
......@@ -428,9 +426,9 @@ abstract class ShapeBorder {
/// and `b` after `t=0.5`.
///
/// {@macro dart.ui.shadow.lerp}
static ShapeBorder lerp(ShapeBorder a, ShapeBorder b, double t) {
static ShapeBorder? lerp(ShapeBorder? a, ShapeBorder? b, double t) {
assert(t != null);
ShapeBorder result;
ShapeBorder? result;
if (b != null)
result = b.lerpFrom(a, t);
if (result == null && a != null)
......@@ -457,7 +455,7 @@ abstract class ShapeBorder {
///
/// * [getInnerPath], which creates the path for the inner edge.
/// * [Path.contains], which can tell if an [Offset] is within a [Path].
Path getOuterPath(Rect rect, { TextDirection textDirection });
Path getOuterPath(Rect rect, { TextDirection? textDirection });
/// Create a [Path] that describes the inner edge of the border.
///
......@@ -478,7 +476,7 @@ abstract class ShapeBorder {
///
/// * [getOuterPath], which creates the path for the outer edge.
/// * [Path.contains], which can tell if an [Offset] is within a [Path].
Path getInnerPath(Rect rect, { TextDirection textDirection });
Path getInnerPath(Rect rect, { TextDirection? textDirection });
/// Paints the border within the given [Rect] on the given [Canvas].
///
......@@ -486,7 +484,7 @@ abstract class ShapeBorder {
/// has a text direction dependency (for example if it is expressed in terms
/// of "start" and "end" instead of "left" and "right"). It may be null if
/// the border will not need the text direction to paint itself.
void paint(Canvas canvas, Rect rect, { TextDirection textDirection });
void paint(Canvas canvas, Rect rect, { TextDirection? textDirection });
@override
String toString() {
......@@ -548,7 +546,7 @@ class _CompoundBorder extends ShapeBorder {
// border, and "merged" is the result of attempting to merge it with the
// new border. If it's null, it couldn't be merged.
final ShapeBorder ours = reversed ? borders.last : borders.first;
final ShapeBorder merged = ours.add(other, reversed: reversed)
final ShapeBorder? merged = ours.add(other, reversed: reversed)
?? other.add(ours, reversed: !reversed);
if (merged != null) {
final List<ShapeBorder> result = <ShapeBorder>[...borders];
......@@ -574,27 +572,27 @@ class _CompoundBorder extends ShapeBorder {
}
@override
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
return _CompoundBorder.lerp(a, this, t);
}
@override
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
return _CompoundBorder.lerp(this, b, t);
}
static _CompoundBorder lerp(ShapeBorder a, ShapeBorder b, double t) {
static _CompoundBorder lerp(ShapeBorder? a, ShapeBorder? b, double t) {
assert(t != null);
assert(a is _CompoundBorder || b is _CompoundBorder); // Not really necessary, but all call sites currently intend this.
final List<ShapeBorder> aList = a is _CompoundBorder ? a.borders : <ShapeBorder>[a];
final List<ShapeBorder> bList = b is _CompoundBorder ? b.borders : <ShapeBorder>[b];
final List<ShapeBorder?> aList = a is _CompoundBorder ? a.borders : <ShapeBorder?>[a];
final List<ShapeBorder?> bList = b is _CompoundBorder ? b.borders : <ShapeBorder?>[b];
final List<ShapeBorder> results = <ShapeBorder>[];
final int length = math.max(aList.length, bList.length);
for (int index = 0; index < length; index += 1) {
final ShapeBorder localA = index < aList.length ? aList[index] : null;
final ShapeBorder localB = index < bList.length ? bList[index] : null;
final ShapeBorder? localA = index < aList.length ? aList[index] : null;
final ShapeBorder? localB = index < bList.length ? bList[index] : null;
if (localA != null && localB != null) {
final ShapeBorder localResult = localA.lerpTo(localB, t) ?? localB.lerpFrom(localA, t);
final ShapeBorder? localResult = localA.lerpTo(localB, t) ?? localB.lerpFrom(localA, t);
if (localResult != null) {
results.add(localResult);
continue;
......@@ -613,19 +611,19 @@ class _CompoundBorder extends ShapeBorder {
}
@override
Path getInnerPath(Rect rect, { TextDirection textDirection }) {
Path getInnerPath(Rect rect, { TextDirection? textDirection }) {
for (int index = 0; index < borders.length - 1; index += 1)
rect = borders[index].dimensions.resolve(textDirection).deflateRect(rect);
return borders.last.getInnerPath(rect, textDirection: textDirection);
}
@override
Path getOuterPath(Rect rect, { TextDirection textDirection }) {
Path getOuterPath(Rect rect, { TextDirection? textDirection }) {
return borders.first.getOuterPath(rect, textDirection: textDirection);
}
@override
void paint(Canvas canvas, Rect rect, { TextDirection textDirection }) {
void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) {
for (final ShapeBorder border in borders) {
border.paint(canvas, rect, textDirection: textDirection);
rect = border.dimensions.resolve(textDirection).deflateRect(rect);
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
......@@ -85,7 +84,7 @@ abstract class BoxBorder extends ShapeBorder {
// We override this to tighten the return value, so that callers can assume
// that we'll return a [BoxBorder].
@override
BoxBorder add(ShapeBorder other, { bool reversed = false }) => null;
BoxBorder? add(ShapeBorder other, { bool reversed = false }) => null;
/// Linearly interpolate between two borders.
///
......@@ -104,12 +103,12 @@ abstract class BoxBorder extends ShapeBorder {
/// instead [add] the two sets of sides and interpolate them simultaneously.
///
/// {@macro dart.ui.shadow.lerp}
static BoxBorder lerp(BoxBorder a, BoxBorder b, double t) {
static BoxBorder? lerp(BoxBorder? a, BoxBorder? b, double t) {
assert(t != null);
if ((a is Border || a == null) && (b is Border || b == null))
return Border.lerp(a as Border, b as Border, t);
if ((a is BorderDirectional || a == null) && (b is BorderDirectional || b == null))
return BorderDirectional.lerp(a as BorderDirectional, b as BorderDirectional, t);
if ((a is Border?) && (b is Border?))
return Border.lerp(a, b, t);
if ((a is BorderDirectional?) && (b is BorderDirectional?))
return BorderDirectional.lerp(a, b, t);
if (b is Border && a is BorderDirectional) {
final BoxBorder c = b;
b = a;
......@@ -167,14 +166,14 @@ abstract class BoxBorder extends ShapeBorder {
}
@override
Path getInnerPath(Rect rect, { @required TextDirection textDirection }) {
Path getInnerPath(Rect rect, { TextDirection? textDirection }) {
assert(textDirection != null, 'The textDirection argument to $runtimeType.getInnerPath must not be null.');
return Path()
..addRect(dimensions.resolve(textDirection).deflateRect(rect));
}
@override
Path getOuterPath(Rect rect, { @required TextDirection textDirection }) {
Path getOuterPath(Rect rect, { TextDirection? textDirection }) {
assert(textDirection != null, 'The textDirection argument to $runtimeType.getOuterPath must not be null.');
return Path()
..addRect(rect);
......@@ -203,9 +202,9 @@ abstract class BoxBorder extends ShapeBorder {
void paint(
Canvas canvas,
Rect rect, {
TextDirection textDirection,
TextDirection? textDirection,
BoxShape shape = BoxShape.rectangle,
BorderRadius borderRadius,
BorderRadius? borderRadius,
});
static void _paintUniformBorderWithRadius(Canvas canvas, Rect rect, BorderSide side, BorderRadius borderRadius) {
......@@ -414,7 +413,7 @@ class Border extends BoxBorder {
}
@override
Border add(ShapeBorder other, { bool reversed = false }) {
Border? add(ShapeBorder other, { bool reversed = false }) {
if (other is Border &&
BorderSide.canMerge(top, other.top) &&
BorderSide.canMerge(right, other.right) &&
......@@ -436,14 +435,14 @@ class Border extends BoxBorder {
}
@override
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
if (a is Border)
return Border.lerp(a, this, t);
return super.lerpFrom(a, t);
}
@override
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
if (b is Border)
return Border.lerp(this, b, t);
return super.lerpTo(b, t);
......@@ -455,12 +454,12 @@ class Border extends BoxBorder {
/// borders.
///
/// {@macro dart.ui.shadow.lerp}
static Border lerp(Border a, Border b, double t) {
static Border? lerp(Border? a, Border? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b.scale(t);
return b!.scale(t);
if (b == null)
return a.scale(1.0 - t);
return Border(
......@@ -494,9 +493,9 @@ class Border extends BoxBorder {
void paint(
Canvas canvas,
Rect rect, {
TextDirection textDirection,
TextDirection? textDirection,
BoxShape shape = BoxShape.rectangle,
BorderRadius borderRadius,
BorderRadius? borderRadius,
}) {
if (isUniform) {
switch (top.style) {
......@@ -694,7 +693,7 @@ class BorderDirectional extends BoxBorder {
}
@override
BoxBorder add(ShapeBorder other, { bool reversed = false }) {
BoxBorder? add(ShapeBorder other, { bool reversed = false }) {
if (other is BorderDirectional) {
final BorderDirectional typedOther = other;
if (BorderSide.canMerge(top, typedOther.top) &&
......@@ -747,14 +746,14 @@ class BorderDirectional extends BoxBorder {
}
@override
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
if (a is BorderDirectional)
return BorderDirectional.lerp(a, this, t);
return super.lerpFrom(a, t);
}
@override
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
if (b is BorderDirectional)
return BorderDirectional.lerp(this, b, t);
return super.lerpTo(b, t);
......@@ -766,12 +765,12 @@ class BorderDirectional extends BoxBorder {
/// borders.
///
/// {@macro dart.ui.shadow.lerp}
static BorderDirectional lerp(BorderDirectional a, BorderDirectional b, double t) {
static BorderDirectional? lerp(BorderDirectional? a, BorderDirectional? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b.scale(t);
return b!.scale(t);
if (b == null)
return a.scale(1.0 - t);
return BorderDirectional(
......@@ -808,9 +807,9 @@ class BorderDirectional extends BoxBorder {
void paint(
Canvas canvas,
Rect rect, {
TextDirection textDirection,
TextDirection? textDirection,
BoxShape shape = BoxShape.rectangle,
BorderRadius borderRadius,
BorderRadius? borderRadius,
}) {
if (isUniform) {
switch (top.style) {
......@@ -839,7 +838,7 @@ class BorderDirectional extends BoxBorder {
BorderSide left, right;
assert(textDirection != null, 'Non-uniform BorderDirectional objects require a TextDirection when painting.');
switch (textDirection) {
switch (textDirection!) {
case TextDirection.rtl:
left = end;
right = start;
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
import 'dart:ui' as ui show Shadow, lerpDouble;
......@@ -79,19 +78,19 @@ class BoxShadow extends ui.Shadow {
/// offset and a zero blurRadius.
///
/// {@macro dart.ui.shadow.lerp}
static BoxShadow lerp(BoxShadow a, BoxShadow b, double t) {
static BoxShadow? lerp(BoxShadow? a, BoxShadow? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b.scale(t);
return b!.scale(t);
if (b == null)
return a.scale(1.0 - t);
return BoxShadow(
color: Color.lerp(a.color, b.color, t),
offset: Offset.lerp(a.offset, b.offset, t),
blurRadius: ui.lerpDouble(a.blurRadius, b.blurRadius, t),
spreadRadius: ui.lerpDouble(a.spreadRadius, b.spreadRadius, t),
color: Color.lerp(a.color, b.color, t)!,
offset: Offset.lerp(a.offset, b.offset, t)!,
blurRadius: ui.lerpDouble(a.blurRadius, b.blurRadius, t)!,
spreadRadius: ui.lerpDouble(a.spreadRadius, b.spreadRadius, t)!,
);
}
......@@ -100,7 +99,7 @@ class BoxShadow extends ui.Shadow {
/// If the lists differ in length, excess items are lerped with null.
///
/// {@macro dart.ui.shadow.lerp}
static List<BoxShadow> lerpList(List<BoxShadow> a, List<BoxShadow> b, double t) {
static List<BoxShadow>? lerpList(List<BoxShadow>? a, List<BoxShadow>? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
......@@ -108,7 +107,7 @@ class BoxShadow extends ui.Shadow {
b ??= <BoxShadow>[];
final int commonLength = math.min(a.length, b.length);
return <BoxShadow>[
for (int i = 0; i < commonLength; i += 1) BoxShadow.lerp(a[i], b[i], t),
for (int i = 0; i < commonLength; i += 1) BoxShadow.lerp(a[i], b[i], t)!,
for (int i = commonLength; i < a.length; i += 1) a[i].scale(1.0 - t),
for (int i = commonLength; i < b.length; i += 1) b[i].scale(t),
];
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui show lerpDouble, WindowPadding;
......@@ -73,7 +72,6 @@ abstract class EdgeInsetsGeometry {
case Axis.vertical:
return vertical;
}
return null;
}
/// The size that this [EdgeInsets] would occupy with an empty interior.
......@@ -218,12 +216,12 @@ abstract class EdgeInsetsGeometry {
/// into a concrete [EdgeInsets] using [resolve].
///
/// {@macro dart.ui.shadow.lerp}
static EdgeInsetsGeometry lerp(EdgeInsetsGeometry a, EdgeInsetsGeometry b, double t) {
static EdgeInsetsGeometry? lerp(EdgeInsetsGeometry? a, EdgeInsetsGeometry? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b * t;
return b! * t;
if (b == null)
return a * (1.0 - t);
if (a is EdgeInsets && b is EdgeInsets)
......@@ -231,12 +229,12 @@ abstract class EdgeInsetsGeometry {
if (a is EdgeInsetsDirectional && b is EdgeInsetsDirectional)
return EdgeInsetsDirectional.lerp(a, b, t);
return _MixedEdgeInsets.fromLRSETB(
ui.lerpDouble(a._left, b._left, t),
ui.lerpDouble(a._right, b._right, t),
ui.lerpDouble(a._start, b._start, t),
ui.lerpDouble(a._end, b._end, t),
ui.lerpDouble(a._top, b._top, t),
ui.lerpDouble(a._bottom, b._bottom, t),
ui.lerpDouble(a._left, b._left, t)!,
ui.lerpDouble(a._right, b._right, t)!,
ui.lerpDouble(a._start, b._start, t)!,
ui.lerpDouble(a._end, b._end, t)!,
ui.lerpDouble(a._top, b._top, t)!,
ui.lerpDouble(a._bottom, b._bottom, t)!,
);
}
......@@ -249,7 +247,7 @@ abstract class EdgeInsetsGeometry {
/// * [EdgeInsets], for which this is a no-op (returns itself).
/// * [EdgeInsetsDirectional], which flips the horizontal direction
/// based on the `direction` argument.
EdgeInsets resolve(TextDirection direction);
EdgeInsets resolve(TextDirection? direction);
@override
String toString() {
......@@ -597,32 +595,32 @@ class EdgeInsets extends EdgeInsetsGeometry {
/// If either is null, this function interpolates from [EdgeInsets.zero].
///
/// {@macro dart.ui.shadow.lerp}
static EdgeInsets lerp(EdgeInsets a, EdgeInsets b, double t) {
static EdgeInsets? lerp(EdgeInsets? a, EdgeInsets? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b * t;
return b! * t;
if (b == null)
return a * (1.0 - t);
return EdgeInsets.fromLTRB(
ui.lerpDouble(a.left, b.left, t),
ui.lerpDouble(a.top, b.top, t),
ui.lerpDouble(a.right, b.right, t),
ui.lerpDouble(a.bottom, b.bottom, t),
ui.lerpDouble(a.left, b.left, t)!,
ui.lerpDouble(a.top, b.top, t)!,
ui.lerpDouble(a.right, b.right, t)!,
ui.lerpDouble(a.bottom, b.bottom, t)!,
);
}
@override
EdgeInsets resolve(TextDirection direction) => this;
EdgeInsets resolve(TextDirection? direction) => this;
/// Creates a copy of this EdgeInsets but with the given fields replaced
/// with the new values.
EdgeInsets copyWith({
double left,
double top,
double right,
double bottom,
double? left,
double? top,
double? right,
double? bottom,
}) {
return EdgeInsets.only(
left: left ?? this.left,
......@@ -822,32 +820,31 @@ class EdgeInsetsDirectional extends EdgeInsetsGeometry {
/// [EdgeInsetsGeometry.lerp] static method.
///
/// {@macro dart.ui.shadow.lerp}
static EdgeInsetsDirectional lerp(EdgeInsetsDirectional a, EdgeInsetsDirectional b, double t) {
static EdgeInsetsDirectional? lerp(EdgeInsetsDirectional? a, EdgeInsetsDirectional? b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
if (a == null)
return b * t;
return b! * t;
if (b == null)
return a * (1.0 - t);
return EdgeInsetsDirectional.fromSTEB(
ui.lerpDouble(a.start, b.start, t),
ui.lerpDouble(a.top, b.top, t),
ui.lerpDouble(a.end, b.end, t),
ui.lerpDouble(a.bottom, b.bottom, t),
ui.lerpDouble(a.start, b.start, t)!,
ui.lerpDouble(a.top, b.top, t)!,
ui.lerpDouble(a.end, b.end, t)!,
ui.lerpDouble(a.bottom, b.bottom, t)!,
);
}
@override
EdgeInsets resolve(TextDirection direction) {
EdgeInsets resolve(TextDirection? direction) {
assert(direction != null);
switch (direction) {
switch (direction!) {
case TextDirection.rtl:
return EdgeInsets.fromLTRB(end, top, start, bottom);
case TextDirection.ltr:
return EdgeInsets.fromLTRB(start, top, end, bottom);
}
return null;
}
}
......@@ -943,14 +940,13 @@ class _MixedEdgeInsets extends EdgeInsetsGeometry {
}
@override
EdgeInsets resolve(TextDirection direction) {
EdgeInsets resolve(TextDirection? direction) {
assert(direction != null);
switch (direction) {
switch (direction!) {
case TextDirection.rtl:
return EdgeInsets.fromLTRB(_end + _left, _top, _start + _right, _bottom);
case TextDirection.ltr:
return EdgeInsets.fromLTRB(_start + _left, _top, _end + _right, _bottom);
}
return null;
}
}
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