Unverified Commit 7272c809 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Remove unnecessary null checks in `flutter/{animation,semantics,scheduler}` (#118922)

* Remove unnecessary null checks in flutter/animation

* Remove unnecessary null checks in flutter/semantics

* Remove unnecessary null checks in flutter/scheduler
parent 5d74b5cb
......@@ -269,7 +269,6 @@ abstract class Animation<T> extends Listenable implements ValueListenable<T> {
/// * "&#x23ED;": [AnimationStatus.completed] ([value] == 1.0)
/// * "&#x23EE;": [AnimationStatus.dismissed] ([value] == 0.0)
String toStringDetails() {
assert(status != null);
switch (status) {
case AnimationStatus.forward:
return '\u25B6'; // >
......
......@@ -242,10 +242,7 @@ class AnimationController extends Animation<double>
this.upperBound = 1.0,
this.animationBehavior = AnimationBehavior.normal,
required TickerProvider vsync,
}) : assert(lowerBound != null),
assert(upperBound != null),
assert(upperBound >= lowerBound),
assert(vsync != null),
}) : assert(upperBound >= lowerBound),
_direction = _AnimationDirection.forward {
_ticker = vsync.createTicker(_tick);
_internalSetValue(value ?? lowerBound);
......@@ -275,9 +272,7 @@ class AnimationController extends Animation<double>
this.debugLabel,
required TickerProvider vsync,
this.animationBehavior = AnimationBehavior.preserve,
}) : assert(value != null),
assert(vsync != null),
lowerBound = double.negativeInfinity,
}) : lowerBound = double.negativeInfinity,
upperBound = double.infinity,
_direction = _AnimationDirection.forward {
_ticker = vsync.createTicker(_tick);
......@@ -363,7 +358,6 @@ class AnimationController extends Animation<double>
/// * [forward], [reverse], [animateTo], [animateWith], [fling], and [repeat],
/// which start the animation controller.
set value(double newValue) {
assert(newValue != null);
stop();
_internalSetValue(newValue);
notifyListeners();
......@@ -657,7 +651,6 @@ class AnimationController extends Animation<double>
}());
assert(max >= min);
assert(max <= upperBound && min >= lowerBound);
assert(reverse != null);
stop();
return _startSimulation(_RepeatingSimulation(_value, min, max, reverse, period!, _directionSetter));
}
......@@ -744,7 +737,6 @@ class AnimationController extends Animation<double>
}
TickerFuture _startSimulation(Simulation simulation) {
assert(simulation != null);
assert(!isAnimating);
_simulation = simulation;
_lastElapsedDuration = Duration.zero;
......@@ -856,9 +848,7 @@ class AnimationController extends Animation<double>
class _InterpolationSimulation extends Simulation {
_InterpolationSimulation(this._begin, this._end, Duration duration, this._curve, double scale)
: assert(_begin != null),
assert(_end != null),
assert(duration != null && duration.inMicroseconds > 0),
: assert(duration.inMicroseconds > 0),
_durationInSeconds = (duration.inMicroseconds * scale) / Duration.microsecondsPerSecond;
final double _durationInSeconds;
......
......@@ -271,8 +271,7 @@ class ReverseAnimation extends Animation<double>
/// Creates a reverse animation.
///
/// The parent argument must not be null.
ReverseAnimation(this.parent)
: assert(parent != null);
ReverseAnimation(this.parent);
/// The animation whose value and direction this animation is reversing.
final Animation<double> parent;
......@@ -310,7 +309,6 @@ class ReverseAnimation extends Animation<double>
double get value => 1.0 - parent.value;
AnimationStatus _reverseStatus(AnimationStatus status) {
assert(status != null);
switch (status) {
case AnimationStatus.forward: return AnimationStatus.reverse;
case AnimationStatus.reverse: return AnimationStatus.forward;
......@@ -384,8 +382,7 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
required this.parent,
required this.curve,
this.reverseCurve,
}) : assert(parent != null),
assert(curve != null) {
}) {
_updateCurveDirection(parent.status);
parent.addStatusListener(_updateCurveDirection);
}
......@@ -518,7 +515,7 @@ class TrainHoppingAnimation extends Animation<double>
Animation<double> this._currentTrain,
this._nextTrain, {
this.onSwitchedTrain,
}) : assert(_currentTrain != null) {
}) {
if (_nextTrain != null) {
if (_currentTrain!.value == _nextTrain!.value) {
_currentTrain = _nextTrain;
......@@ -644,8 +641,7 @@ abstract class CompoundAnimation<T> extends Animation<T>
CompoundAnimation({
required this.first,
required this.next,
}) : assert(first != null),
assert(next != null);
});
/// The first sub-animation. Its status takes precedence if neither are
/// animating.
......
......@@ -35,7 +35,6 @@ abstract class ParametricCurve<T> {
/// implementation of [transform], which delegates the remaining logic to
/// [transformInternal].
T transform(double t) {
assert(t != null);
assert(t >= 0.0 && t <= 1.0, 'parametric value $t is outside of [0, 1] range.');
return transformInternal(t);
}
......@@ -129,7 +128,7 @@ class SawTooth extends Curve {
/// Creates a sawtooth curve.
///
/// The [count] argument must not be null.
const SawTooth(this.count) : assert(count != null);
const SawTooth(this.count);
/// The number of repetitions of the sawtooth pattern in the unit interval.
final int count;
......@@ -159,10 +158,7 @@ class Interval extends Curve {
/// Creates an interval curve.
///
/// The arguments must not be null.
const Interval(this.begin, this.end, { this.curve = Curves.linear })
: assert(begin != null),
assert(end != null),
assert(curve != null);
const Interval(this.begin, this.end, { this.curve = Curves.linear });
/// The largest value for which this interval is 0.0.
///
......@@ -207,7 +203,7 @@ class Threshold extends Curve {
/// Creates a threshold curve.
///
/// The [threshold] argument must not be null.
const Threshold(this.threshold) : assert(threshold != null);
const Threshold(this.threshold);
/// The value before which the curve is 0.0 and after which the curve is 1.0.
///
......@@ -307,11 +303,7 @@ class Cubic extends Curve {
/// cubic curves in [Curves].
///
/// The [a] (x1), [b] (y1), [c] (x2) and [d] (y2) arguments must not be null.
const Cubic(this.a, this.b, this.c, this.d)
: assert(a != null),
assert(b != null),
assert(c != null),
assert(d != null);
const Cubic(this.a, this.b, this.c, this.d);
/// The x coordinate of the first control point.
///
......@@ -518,9 +510,6 @@ abstract class Curve2D extends ParametricCurve<Offset> {
// 4. Recursively sample the two parts.
//
// This algorithm concentrates samples in areas of high curvature.
assert(tolerance != null);
assert(start != null);
assert(end != null);
assert(end > start);
// We want to pick a random seed that will keep the result stable if
// evaluated again, so we use the first non-generated control point.
......@@ -577,7 +566,6 @@ abstract class Curve2D extends ParametricCurve<Offset> {
/// single-valued, it will return the parameter for only one of the values at
/// the given `x` location.
double findInverse(double x) {
assert(x != null);
double start = 0.0;
double end = 1.0;
late double mid;
......@@ -612,7 +600,7 @@ class Curve2DSample {
/// Creates an object that holds a sample; used with [Curve2D] subclasses.
///
/// All arguments must not be null.
const Curve2DSample(this.t, this.value) : assert(t != null), assert(value != null);
const Curve2DSample(this.t, this.value);
/// The parametric location of this sample point along the curve.
final double t;
......@@ -682,9 +670,7 @@ class CatmullRomSpline extends Curve2D {
double tension = 0.0,
Offset? startHandle,
Offset? endHandle,
}) : assert(controlPoints != null),
assert(tension != null),
assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
}) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
assert(tension >= 0.0, 'tension $tension must not be negative.'),
assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'),
_controlPoints = controlPoints,
......@@ -702,9 +688,7 @@ class CatmullRomSpline extends Curve2D {
double tension = 0.0,
Offset? startHandle,
Offset? endHandle,
}) : assert(controlPoints != null),
assert(tension != null),
assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
}) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
assert(tension >= 0.0, 'tension $tension must not be negative.'),
assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'),
_controlPoints = null,
......@@ -860,8 +844,7 @@ class CatmullRomCurve extends Curve {
///
/// * This [paper on using Catmull-Rom splines](http://faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf).
CatmullRomCurve(this.controlPoints, {this.tension = 0.0})
: assert(tension != null),
assert(() {
: assert(() {
return validateControlPoints(
controlPoints,
tension: tension,
......@@ -877,8 +860,7 @@ class CatmullRomCurve extends Curve {
/// Same as [CatmullRomCurve.new], but it precomputes the internal curve data
/// structures for a more predictable computation load.
CatmullRomCurve.precompute(this.controlPoints, {this.tension = 0.0})
: assert(tension != null),
assert(() {
: assert(() {
return validateControlPoints(
controlPoints,
tension: tension,
......@@ -963,7 +945,6 @@ class CatmullRomCurve extends Curve {
double tension = 0.0,
List<String>? reasons,
}) {
assert(tension != null);
if (controlPoints == null) {
assert(() {
reasons?.add('Supplied control points cannot be null');
......@@ -1143,7 +1124,7 @@ class FlippedCurve extends Curve {
/// Creates a flipped curve.
///
/// The [curve] argument must not be null.
const FlippedCurve(this.curve) : assert(curve != null);
const FlippedCurve(this.curve);
/// The curve that is being flipped.
final Curve curve;
......
......@@ -364,8 +364,7 @@ class Tween<T extends Object?> extends Animatable<T> {
class ReverseTween<T extends Object?> extends Tween<T> {
/// Construct a [Tween] that evaluates its [parent] in reverse.
ReverseTween(this.parent)
: assert(parent != null),
super(begin: parent.end, end: parent.begin);
: super(begin: parent.end, end: parent.begin);
/// This tween's value is the same as the parent's value evaluated in reverse.
///
......@@ -544,8 +543,7 @@ class CurveTween extends Animatable<double> {
/// Creates a curve tween.
///
/// The [curve] argument must not be null.
CurveTween({ required this.curve })
: assert(curve != null);
CurveTween({ required this.curve });
/// The curve to use when transforming the value of the animation.
Curve curve;
......
......@@ -51,8 +51,7 @@ class TweenSequence<T> extends Animatable<T> {
/// best to reuse one, rather than rebuilding it on every frame, when that's
/// possible.
TweenSequence(List<TweenSequenceItem<T>> items)
: assert(items != null),
assert(items.isNotEmpty) {
: assert(items.isNotEmpty) {
_items.addAll(items);
double totalWeight = 0.0;
......@@ -113,8 +112,7 @@ class FlippedTweenSequence extends TweenSequence<double> {
/// There's a small cost associated with building a `TweenSequence` so it's
/// best to reuse one, rather than rebuilding it on every frame, when that's
/// possible.
FlippedTweenSequence(super.items)
: assert(items != null);
FlippedTweenSequence(super.items);
@override
double transform(double t) => 1 - super.transform(1 - t);
......@@ -128,9 +126,7 @@ class TweenSequenceItem<T> {
const TweenSequenceItem({
required this.tween,
required this.weight,
}) : assert(tween != null),
assert(weight != null),
assert(weight > 0.0);
}) : assert(weight > 0.0);
/// Defines the value of the [TweenSequence] for the interval within the
/// animation's duration indicated by [weight] and this item's position
......
......@@ -385,7 +385,6 @@ mixin SchedulerBinding on BindingBase {
@protected
@mustCallSuper
void handleAppLifecycleStateChanged(AppLifecycleState state) {
assert(state != null);
_lifecycleState = state;
switch (state) {
case AppLifecycleState.resumed:
......@@ -1026,7 +1025,6 @@ mixin SchedulerBinding on BindingBase {
/// presentation time, and can be used to ensure that animations running in
/// different processes are synchronized.
Duration get currentSystemFrameTimeStamp {
assert(_lastRawTimeStamp != null);
return _lastRawTimeStamp;
}
......@@ -1279,7 +1277,6 @@ mixin SchedulerBinding on BindingBase {
// the error.
@pragma('vm:notify-debugger-on-exception')
void _invokeFrameCallback(FrameCallback callback, Duration timeStamp, [ StackTrace? callbackStack ]) {
assert(callback != null);
assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
assert(() {
_FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;
......
......@@ -87,9 +87,7 @@ class AnnounceSemanticsEvent extends SemanticsEvent {
/// Constructs an event that triggers an announcement by the platform.
const AnnounceSemanticsEvent(this.message, this.textDirection, {this.assertiveness = Assertiveness.polite})
: assert(message != null),
assert(textDirection != null),
super('announce');
: super('announce');
/// The message to announce.
///
......
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