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