Skip to content

Commit 7272c80

Browse files
authored
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
1 parent 5d74b5c commit 7272c80

File tree

9 files changed

+43
-120
lines changed

9 files changed

+43
-120
lines changed

packages/flutter/lib/src/animation/animation.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ abstract class Animation<T> extends Listenable implements ValueListenable<T> {
269269
/// * "&#x23ED;": [AnimationStatus.completed] ([value] == 1.0)
270270
/// * "&#x23EE;": [AnimationStatus.dismissed] ([value] == 0.0)
271271
String toStringDetails() {
272-
assert(status != null);
273272
switch (status) {
274273
case AnimationStatus.forward:
275274
return '\u25B6'; // >

packages/flutter/lib/src/animation/animation_controller.dart

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ class AnimationController extends Animation<double>
242242
this.upperBound = 1.0,
243243
this.animationBehavior = AnimationBehavior.normal,
244244
required TickerProvider vsync,
245-
}) : assert(lowerBound != null),
246-
assert(upperBound != null),
247-
assert(upperBound >= lowerBound),
248-
assert(vsync != null),
245+
}) : assert(upperBound >= lowerBound),
249246
_direction = _AnimationDirection.forward {
250247
_ticker = vsync.createTicker(_tick);
251248
_internalSetValue(value ?? lowerBound);
@@ -275,9 +272,7 @@ class AnimationController extends Animation<double>
275272
this.debugLabel,
276273
required TickerProvider vsync,
277274
this.animationBehavior = AnimationBehavior.preserve,
278-
}) : assert(value != null),
279-
assert(vsync != null),
280-
lowerBound = double.negativeInfinity,
275+
}) : lowerBound = double.negativeInfinity,
281276
upperBound = double.infinity,
282277
_direction = _AnimationDirection.forward {
283278
_ticker = vsync.createTicker(_tick);
@@ -363,7 +358,6 @@ class AnimationController extends Animation<double>
363358
/// * [forward], [reverse], [animateTo], [animateWith], [fling], and [repeat],
364359
/// which start the animation controller.
365360
set value(double newValue) {
366-
assert(newValue != null);
367361
stop();
368362
_internalSetValue(newValue);
369363
notifyListeners();
@@ -657,7 +651,6 @@ class AnimationController extends Animation<double>
657651
}());
658652
assert(max >= min);
659653
assert(max <= upperBound && min >= lowerBound);
660-
assert(reverse != null);
661654
stop();
662655
return _startSimulation(_RepeatingSimulation(_value, min, max, reverse, period!, _directionSetter));
663656
}
@@ -744,7 +737,6 @@ class AnimationController extends Animation<double>
744737
}
745738

746739
TickerFuture _startSimulation(Simulation simulation) {
747-
assert(simulation != null);
748740
assert(!isAnimating);
749741
_simulation = simulation;
750742
_lastElapsedDuration = Duration.zero;
@@ -856,9 +848,7 @@ class AnimationController extends Animation<double>
856848

857849
class _InterpolationSimulation extends Simulation {
858850
_InterpolationSimulation(this._begin, this._end, Duration duration, this._curve, double scale)
859-
: assert(_begin != null),
860-
assert(_end != null),
861-
assert(duration != null && duration.inMicroseconds > 0),
851+
: assert(duration.inMicroseconds > 0),
862852
_durationInSeconds = (duration.inMicroseconds * scale) / Duration.microsecondsPerSecond;
863853

864854
final double _durationInSeconds;

packages/flutter/lib/src/animation/animations.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ class ReverseAnimation extends Animation<double>
271271
/// Creates a reverse animation.
272272
///
273273
/// The parent argument must not be null.
274-
ReverseAnimation(this.parent)
275-
: assert(parent != null);
274+
ReverseAnimation(this.parent);
276275

277276
/// The animation whose value and direction this animation is reversing.
278277
final Animation<double> parent;
@@ -310,7 +309,6 @@ class ReverseAnimation extends Animation<double>
310309
double get value => 1.0 - parent.value;
311310

312311
AnimationStatus _reverseStatus(AnimationStatus status) {
313-
assert(status != null);
314312
switch (status) {
315313
case AnimationStatus.forward: return AnimationStatus.reverse;
316314
case AnimationStatus.reverse: return AnimationStatus.forward;
@@ -384,8 +382,7 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
384382
required this.parent,
385383
required this.curve,
386384
this.reverseCurve,
387-
}) : assert(parent != null),
388-
assert(curve != null) {
385+
}) {
389386
_updateCurveDirection(parent.status);
390387
parent.addStatusListener(_updateCurveDirection);
391388
}
@@ -518,7 +515,7 @@ class TrainHoppingAnimation extends Animation<double>
518515
Animation<double> this._currentTrain,
519516
this._nextTrain, {
520517
this.onSwitchedTrain,
521-
}) : assert(_currentTrain != null) {
518+
}) {
522519
if (_nextTrain != null) {
523520
if (_currentTrain!.value == _nextTrain!.value) {
524521
_currentTrain = _nextTrain;
@@ -644,8 +641,7 @@ abstract class CompoundAnimation<T> extends Animation<T>
644641
CompoundAnimation({
645642
required this.first,
646643
required this.next,
647-
}) : assert(first != null),
648-
assert(next != null);
644+
});
649645

650646
/// The first sub-animation. Its status takes precedence if neither are
651647
/// animating.

packages/flutter/lib/src/animation/curves.dart

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ abstract class ParametricCurve<T> {
3535
/// implementation of [transform], which delegates the remaining logic to
3636
/// [transformInternal].
3737
T transform(double t) {
38-
assert(t != null);
3938
assert(t >= 0.0 && t <= 1.0, 'parametric value $t is outside of [0, 1] range.');
4039
return transformInternal(t);
4140
}
@@ -129,7 +128,7 @@ class SawTooth extends Curve {
129128
/// Creates a sawtooth curve.
130129
///
131130
/// The [count] argument must not be null.
132-
const SawTooth(this.count) : assert(count != null);
131+
const SawTooth(this.count);
133132

134133
/// The number of repetitions of the sawtooth pattern in the unit interval.
135134
final int count;
@@ -159,10 +158,7 @@ class Interval extends Curve {
159158
/// Creates an interval curve.
160159
///
161160
/// The arguments must not be null.
162-
const Interval(this.begin, this.end, { this.curve = Curves.linear })
163-
: assert(begin != null),
164-
assert(end != null),
165-
assert(curve != null);
161+
const Interval(this.begin, this.end, { this.curve = Curves.linear });
166162

167163
/// The largest value for which this interval is 0.0.
168164
///
@@ -207,7 +203,7 @@ class Threshold extends Curve {
207203
/// Creates a threshold curve.
208204
///
209205
/// The [threshold] argument must not be null.
210-
const Threshold(this.threshold) : assert(threshold != null);
206+
const Threshold(this.threshold);
211207

212208
/// The value before which the curve is 0.0 and after which the curve is 1.0.
213209
///
@@ -307,11 +303,7 @@ class Cubic extends Curve {
307303
/// cubic curves in [Curves].
308304
///
309305
/// The [a] (x1), [b] (y1), [c] (x2) and [d] (y2) arguments must not be null.
310-
const Cubic(this.a, this.b, this.c, this.d)
311-
: assert(a != null),
312-
assert(b != null),
313-
assert(c != null),
314-
assert(d != null);
306+
const Cubic(this.a, this.b, this.c, this.d);
315307

316308
/// The x coordinate of the first control point.
317309
///
@@ -518,9 +510,6 @@ abstract class Curve2D extends ParametricCurve<Offset> {
518510
// 4. Recursively sample the two parts.
519511
//
520512
// This algorithm concentrates samples in areas of high curvature.
521-
assert(tolerance != null);
522-
assert(start != null);
523-
assert(end != null);
524513
assert(end > start);
525514
// We want to pick a random seed that will keep the result stable if
526515
// evaluated again, so we use the first non-generated control point.
@@ -577,7 +566,6 @@ abstract class Curve2D extends ParametricCurve<Offset> {
577566
/// single-valued, it will return the parameter for only one of the values at
578567
/// the given `x` location.
579568
double findInverse(double x) {
580-
assert(x != null);
581569
double start = 0.0;
582570
double end = 1.0;
583571
late double mid;
@@ -612,7 +600,7 @@ class Curve2DSample {
612600
/// Creates an object that holds a sample; used with [Curve2D] subclasses.
613601
///
614602
/// All arguments must not be null.
615-
const Curve2DSample(this.t, this.value) : assert(t != null), assert(value != null);
603+
const Curve2DSample(this.t, this.value);
616604

617605
/// The parametric location of this sample point along the curve.
618606
final double t;
@@ -682,9 +670,7 @@ class CatmullRomSpline extends Curve2D {
682670
double tension = 0.0,
683671
Offset? startHandle,
684672
Offset? endHandle,
685-
}) : assert(controlPoints != null),
686-
assert(tension != null),
687-
assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
673+
}) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
688674
assert(tension >= 0.0, 'tension $tension must not be negative.'),
689675
assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'),
690676
_controlPoints = controlPoints,
@@ -702,9 +688,7 @@ class CatmullRomSpline extends Curve2D {
702688
double tension = 0.0,
703689
Offset? startHandle,
704690
Offset? endHandle,
705-
}) : assert(controlPoints != null),
706-
assert(tension != null),
707-
assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
691+
}) : assert(tension <= 1.0, 'tension $tension must not be greater than 1.0.'),
708692
assert(tension >= 0.0, 'tension $tension must not be negative.'),
709693
assert(controlPoints.length > 3, 'There must be at least four control points to create a CatmullRomSpline.'),
710694
_controlPoints = null,
@@ -860,8 +844,7 @@ class CatmullRomCurve extends Curve {
860844
///
861845
/// * This [paper on using Catmull-Rom splines](http://faculty.cs.tamu.edu/schaefer/research/cr_cad.pdf).
862846
CatmullRomCurve(this.controlPoints, {this.tension = 0.0})
863-
: assert(tension != null),
864-
assert(() {
847+
: assert(() {
865848
return validateControlPoints(
866849
controlPoints,
867850
tension: tension,
@@ -877,8 +860,7 @@ class CatmullRomCurve extends Curve {
877860
/// Same as [CatmullRomCurve.new], but it precomputes the internal curve data
878861
/// structures for a more predictable computation load.
879862
CatmullRomCurve.precompute(this.controlPoints, {this.tension = 0.0})
880-
: assert(tension != null),
881-
assert(() {
863+
: assert(() {
882864
return validateControlPoints(
883865
controlPoints,
884866
tension: tension,
@@ -963,7 +945,6 @@ class CatmullRomCurve extends Curve {
963945
double tension = 0.0,
964946
List<String>? reasons,
965947
}) {
966-
assert(tension != null);
967948
if (controlPoints == null) {
968949
assert(() {
969950
reasons?.add('Supplied control points cannot be null');
@@ -1143,7 +1124,7 @@ class FlippedCurve extends Curve {
11431124
/// Creates a flipped curve.
11441125
///
11451126
/// The [curve] argument must not be null.
1146-
const FlippedCurve(this.curve) : assert(curve != null);
1127+
const FlippedCurve(this.curve);
11471128

11481129
/// The curve that is being flipped.
11491130
final Curve curve;

packages/flutter/lib/src/animation/tween.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ class Tween<T extends Object?> extends Animatable<T> {
364364
class ReverseTween<T extends Object?> extends Tween<T> {
365365
/// Construct a [Tween] that evaluates its [parent] in reverse.
366366
ReverseTween(this.parent)
367-
: assert(parent != null),
368-
super(begin: parent.end, end: parent.begin);
367+
: super(begin: parent.end, end: parent.begin);
369368

370369
/// This tween's value is the same as the parent's value evaluated in reverse.
371370
///
@@ -544,8 +543,7 @@ class CurveTween extends Animatable<double> {
544543
/// Creates a curve tween.
545544
///
546545
/// The [curve] argument must not be null.
547-
CurveTween({ required this.curve })
548-
: assert(curve != null);
546+
CurveTween({ required this.curve });
549547

550548
/// The curve to use when transforming the value of the animation.
551549
Curve curve;

packages/flutter/lib/src/animation/tween_sequence.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class TweenSequence<T> extends Animatable<T> {
5151
/// best to reuse one, rather than rebuilding it on every frame, when that's
5252
/// possible.
5353
TweenSequence(List<TweenSequenceItem<T>> items)
54-
: assert(items != null),
55-
assert(items.isNotEmpty) {
54+
: assert(items.isNotEmpty) {
5655
_items.addAll(items);
5756

5857
double totalWeight = 0.0;
@@ -113,8 +112,7 @@ class FlippedTweenSequence extends TweenSequence<double> {
113112
/// There's a small cost associated with building a `TweenSequence` so it's
114113
/// best to reuse one, rather than rebuilding it on every frame, when that's
115114
/// possible.
116-
FlippedTweenSequence(super.items)
117-
: assert(items != null);
115+
FlippedTweenSequence(super.items);
118116

119117
@override
120118
double transform(double t) => 1 - super.transform(1 - t);
@@ -128,9 +126,7 @@ class TweenSequenceItem<T> {
128126
const TweenSequenceItem({
129127
required this.tween,
130128
required this.weight,
131-
}) : assert(tween != null),
132-
assert(weight != null),
133-
assert(weight > 0.0);
129+
}) : assert(weight > 0.0);
134130

135131
/// Defines the value of the [TweenSequence] for the interval within the
136132
/// animation's duration indicated by [weight] and this item's position

packages/flutter/lib/src/scheduler/binding.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ mixin SchedulerBinding on BindingBase {
385385
@protected
386386
@mustCallSuper
387387
void handleAppLifecycleStateChanged(AppLifecycleState state) {
388-
assert(state != null);
389388
_lifecycleState = state;
390389
switch (state) {
391390
case AppLifecycleState.resumed:
@@ -1026,7 +1025,6 @@ mixin SchedulerBinding on BindingBase {
10261025
/// presentation time, and can be used to ensure that animations running in
10271026
/// different processes are synchronized.
10281027
Duration get currentSystemFrameTimeStamp {
1029-
assert(_lastRawTimeStamp != null);
10301028
return _lastRawTimeStamp;
10311029
}
10321030

@@ -1279,7 +1277,6 @@ mixin SchedulerBinding on BindingBase {
12791277
// the error.
12801278
@pragma('vm:notify-debugger-on-exception')
12811279
void _invokeFrameCallback(FrameCallback callback, Duration timeStamp, [ StackTrace? callbackStack ]) {
1282-
assert(callback != null);
12831280
assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
12841281
assert(() {
12851282
_FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;

0 commit comments

Comments
 (0)