Skip to content

Commit 9837eb6

Browse files
authored
Remove unnecessary null checks in flutter/rendering (#118923)
1 parent bae4c1d commit 9837eb6

37 files changed

+127
-757
lines changed

packages/flutter/lib/src/rendering/animated_size.dart

+1-11
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
8282
super.textDirection,
8383
super.child,
8484
Clip clipBehavior = Clip.hardEdge,
85-
}) : assert(vsync != null),
86-
assert(duration != null),
87-
assert(curve != null),
88-
assert(clipBehavior != null),
89-
_vsync = vsync,
85+
}) : _vsync = vsync,
9086
_clipBehavior = clipBehavior {
9187
_controller = AnimationController(
9288
vsync: vsync,
@@ -119,7 +115,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
119115
/// The duration of the animation.
120116
Duration get duration => _controller.duration!;
121117
set duration(Duration value) {
122-
assert(value != null);
123118
if (value == _controller.duration) {
124119
return;
125120
}
@@ -138,7 +133,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
138133
/// The curve of the animation.
139134
Curve get curve => _animation.curve;
140135
set curve(Curve value) {
141-
assert(value != null);
142136
if (value == _animation.curve) {
143137
return;
144138
}
@@ -151,7 +145,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
151145
Clip get clipBehavior => _clipBehavior;
152146
Clip _clipBehavior = Clip.hardEdge;
153147
set clipBehavior(Clip value) {
154-
assert(value != null);
155148
if (value != _clipBehavior) {
156149
_clipBehavior = value;
157150
markNeedsPaint();
@@ -169,7 +162,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
169162
TickerProvider get vsync => _vsync;
170163
TickerProvider _vsync;
171164
set vsync(TickerProvider value) {
172-
assert(value != null);
173165
if (value == _vsync) {
174166
return;
175167
}
@@ -218,7 +210,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
218210

219211
child!.layout(constraints, parentUsesSize: true);
220212

221-
assert(_state != null);
222213
switch (_state) {
223214
case RenderAnimatedSizeState.start:
224215
_layoutStart();
@@ -253,7 +244,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
253244
// size without modifying global state. See performLayout for comments
254245
// explaining the rational behind the implementation.
255246
final Size childSize = child!.getDryLayout(constraints);
256-
assert(_state != null);
257247
switch (_state) {
258248
case RenderAnimatedSizeState.start:
259249
return constraints.constrain(childSize);

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

-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
4343
..onSemanticsAction = _handleSemanticsAction;
4444
initRenderView();
4545
_handleSemanticsEnabledChanged();
46-
assert(renderView != null);
4746
addPersistentFrameCallback(_handlePersistentFrameCallback);
4847
initMouseTracker();
4948
if (kIsWeb) {
@@ -234,7 +233,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
234233
/// Sets the given [RenderView] object (which must not be null), and its tree, to
235234
/// be the new render tree to display. The previous tree, if any, is detached.
236235
set renderView(RenderView value) {
237-
assert(value != null);
238236
_pipelineOwner.rootNode = value;
239237
}
240238

@@ -244,7 +242,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
244242
@protected
245243
@visibleForTesting
246244
void handleMetricsChanged() {
247-
assert(renderView != null);
248245
renderView.configuration = createViewConfiguration();
249246
if (renderView.child != null) {
250247
scheduleForcedFrame();
@@ -512,7 +509,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
512509
// When editing the above, also update widgets/binding.dart's copy.
513510
@protected
514511
void drawFrame() {
515-
assert(renderView != null);
516512
pipelineOwner.flushLayout();
517513
pipelineOwner.flushCompositingBits();
518514
pipelineOwner.flushPaint();
@@ -544,9 +540,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
544540

545541
@override
546542
void hitTest(HitTestResult result, Offset position) {
547-
assert(renderView != null);
548-
assert(result != null);
549-
assert(position != null);
550543
renderView.hitTest(result, position: position);
551544
super.hitTest(result, position);
552545
}
@@ -620,7 +613,6 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
620613
/// This binding does not automatically schedule any frames. Callers are
621614
/// responsible for deciding when to first call [scheduleFrame].
622615
RenderingFlutterBinding({ RenderBox? root }) {
623-
assert(renderView != null);
624616
renderView.child = root;
625617
}
626618

packages/flutter/lib/src/rendering/box.dart

+2-46
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ class BoxConstraints extends Constraints {
9696
this.maxWidth = double.infinity,
9797
this.minHeight = 0.0,
9898
this.maxHeight = double.infinity,
99-
}) : assert(minWidth != null),
100-
assert(maxWidth != null),
101-
assert(minHeight != null),
102-
assert(maxHeight != null);
99+
});
103100

104101
/// Creates box constraints that is respected only by the given size.
105102
BoxConstraints.tight(Size size)
@@ -190,7 +187,6 @@ class BoxConstraints extends Constraints {
190187

191188
/// Returns new box constraints that are smaller by the given edge dimensions.
192189
BoxConstraints deflate(EdgeInsets edges) {
193-
assert(edges != null);
194190
assert(debugAssertIsValid());
195191
final double horizontal = edges.horizontal;
196192
final double vertical = edges.vertical;
@@ -472,7 +468,6 @@ class BoxConstraints extends Constraints {
472468
///
473469
/// {@macro dart.ui.shadow.lerp}
474470
static BoxConstraints? lerp(BoxConstraints? a, BoxConstraints? b, double t) {
475-
assert(t != null);
476471
if (a == null && b == null) {
477472
return null;
478473
}
@@ -762,8 +757,6 @@ class BoxHitTestResult extends HitTestResult {
762757
required Offset position,
763758
required BoxHitTest hitTest,
764759
}) {
765-
assert(position != null);
766-
assert(hitTest != null);
767760
if (transform != null) {
768761
transform = Matrix4.tryInvert(PointerEvent.removePerspectiveTransform(transform));
769762
if (transform == null) {
@@ -801,8 +794,6 @@ class BoxHitTestResult extends HitTestResult {
801794
required Offset position,
802795
required BoxHitTest hitTest,
803796
}) {
804-
assert(position != null);
805-
assert(hitTest != null);
806797
final Offset transformedPosition = offset == null ? position : position - offset;
807798
if (offset != null) {
808799
pushOffset(-offset);
@@ -838,9 +829,6 @@ class BoxHitTestResult extends HitTestResult {
838829
required Offset position,
839830
required BoxHitTest hitTest,
840831
}) {
841-
assert(position != null);
842-
assert(hitTest != null);
843-
assert(position != null);
844832
final Offset transformedPosition = transform == null ?
845833
position : MatrixUtils.transformPoint(transform, position);
846834
if (transform != null) {
@@ -887,7 +875,6 @@ class BoxHitTestResult extends HitTestResult {
887875
Matrix4? rawTransform,
888876
required BoxHitTestWithOutOfBandPosition hitTest,
889877
}) {
890-
assert(hitTest != null);
891878
assert(
892879
(paintOffset == null && paintTransform == null && rawTransform != null) ||
893880
(paintOffset == null && paintTransform != null && rawTransform == null) ||
@@ -915,8 +902,7 @@ class BoxHitTestEntry extends HitTestEntry<RenderBox> {
915902
/// Creates a box hit test entry.
916903
///
917904
/// The [localPosition] argument must not be null.
918-
BoxHitTestEntry(super.target, this.localPosition)
919-
: assert(localPosition != null);
905+
BoxHitTestEntry(super.target, this.localPosition);
920906

921907
/// The position of the hit test in the local coordinates of [target].
922908
final Offset localPosition;
@@ -1452,13 +1438,6 @@ abstract class RenderBox extends RenderObject {
14521438
@mustCallSuper
14531439
double getMinIntrinsicWidth(double height) {
14541440
assert(() {
1455-
if (height == null) {
1456-
throw FlutterError.fromParts(<DiagnosticsNode>[
1457-
ErrorSummary('The height argument to getMinIntrinsicWidth was null.'),
1458-
ErrorDescription('The argument to getMinIntrinsicWidth must not be negative or null.'),
1459-
ErrorHint('If you do not have a specific height in mind, then pass double.infinity instead.'),
1460-
]);
1461-
}
14621441
if (height < 0.0) {
14631442
throw FlutterError.fromParts(<DiagnosticsNode>[
14641443
ErrorSummary('The height argument to getMinIntrinsicWidth was negative.'),
@@ -1601,13 +1580,6 @@ abstract class RenderBox extends RenderObject {
16011580
@mustCallSuper
16021581
double getMaxIntrinsicWidth(double height) {
16031582
assert(() {
1604-
if (height == null) {
1605-
throw FlutterError.fromParts(<DiagnosticsNode>[
1606-
ErrorSummary('The height argument to getMaxIntrinsicWidth was null.'),
1607-
ErrorDescription('The argument to getMaxIntrinsicWidth must not be negative or null.'),
1608-
ErrorHint('If you do not have a specific height in mind, then pass double.infinity instead.'),
1609-
]);
1610-
}
16111583
if (height < 0.0) {
16121584
throw FlutterError.fromParts(<DiagnosticsNode>[
16131585
ErrorSummary('The height argument to getMaxIntrinsicWidth was negative.'),
@@ -1684,13 +1656,6 @@ abstract class RenderBox extends RenderObject {
16841656
@mustCallSuper
16851657
double getMinIntrinsicHeight(double width) {
16861658
assert(() {
1687-
if (width == null) {
1688-
throw FlutterError.fromParts(<DiagnosticsNode>[
1689-
ErrorSummary('The width argument to getMinIntrinsicHeight was null.'),
1690-
ErrorDescription('The argument to getMinIntrinsicHeight must not be negative or null.'),
1691-
ErrorHint('If you do not have a specific width in mind, then pass double.infinity instead.'),
1692-
]);
1693-
}
16941659
if (width < 0.0) {
16951660
throw FlutterError.fromParts(<DiagnosticsNode>[
16961661
ErrorSummary('The width argument to getMinIntrinsicHeight was negative.'),
@@ -1766,13 +1731,6 @@ abstract class RenderBox extends RenderObject {
17661731
@mustCallSuper
17671732
double getMaxIntrinsicHeight(double width) {
17681733
assert(() {
1769-
if (width == null) {
1770-
throw FlutterError.fromParts(<DiagnosticsNode>[
1771-
ErrorSummary('The width argument to getMaxIntrinsicHeight was null.'),
1772-
ErrorDescription('The argument to getMaxIntrinsicHeight must not be negative or null.'),
1773-
ErrorHint('If you do not have a specific width in mind, then pass double.infinity instead.'),
1774-
]);
1775-
}
17761734
if (width < 0.0) {
17771735
throw FlutterError.fromParts(<DiagnosticsNode>[
17781736
ErrorSummary('The width argument to getMaxIntrinsicHeight was negative.'),
@@ -2253,7 +2211,6 @@ abstract class RenderBox extends RenderObject {
22532211

22542212
@override
22552213
void debugAssertDoesMeetConstraints() {
2256-
assert(constraints != null);
22572214
assert(() {
22582215
if (!hasSize) {
22592216
final DiagnosticsNode contract;
@@ -2582,7 +2539,6 @@ abstract class RenderBox extends RenderObject {
25822539
/// child's [parentData] in the [BoxParentData.offset] field.
25832540
@override
25842541
void applyPaintTransform(RenderObject child, Matrix4 transform) {
2585-
assert(child != null);
25862542
assert(child.parent == this);
25872543
assert(() {
25882544
if (child.parentData is! BoxParentData) {

packages/flutter/lib/src/rendering/custom_layout.dart

+1-8
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ abstract class MultiChildLayoutDelegate {
187187
'There is no child with the id "$childId".',
188188
);
189189
}
190-
if (offset == null) {
191-
throw FlutterError(
192-
'The $this custom multichild layout delegate provided a null position for the child with id "$childId".',
193-
);
194-
}
195190
return true;
196191
}());
197192
final MultiChildLayoutParentData childParentData = child!.parentData! as MultiChildLayoutParentData;
@@ -311,8 +306,7 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
311306
RenderCustomMultiChildLayoutBox({
312307
List<RenderBox>? children,
313308
required MultiChildLayoutDelegate delegate,
314-
}) : assert(delegate != null),
315-
_delegate = delegate {
309+
}) : _delegate = delegate {
316310
addAll(children);
317311
}
318312

@@ -327,7 +321,6 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
327321
MultiChildLayoutDelegate get delegate => _delegate;
328322
MultiChildLayoutDelegate _delegate;
329323
set delegate(MultiChildLayoutDelegate newDelegate) {
330-
assert(newDelegate != null);
331324
if (_delegate == newDelegate) {
332325
return;
333326
}

packages/flutter/lib/src/rendering/custom_paint.dart

+2-5
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ class CustomPainterSemantics {
294294
required this.properties,
295295
this.transform,
296296
this.tags,
297-
}) : assert(rect != null),
298-
assert(properties != null);
297+
});
299298

300299
/// Identifies this object in a list of siblings.
301300
///
@@ -371,8 +370,7 @@ class RenderCustomPaint extends RenderProxyBox {
371370
this.isComplex = false,
372371
this.willChange = false,
373372
RenderBox? child,
374-
}) : assert(preferredSize != null),
375-
_painter = painter,
373+
}) : _painter = painter,
376374
_foregroundPainter = foregroundPainter,
377375
_preferredSize = preferredSize,
378376
super(child);
@@ -467,7 +465,6 @@ class RenderCustomPaint extends RenderProxyBox {
467465
Size get preferredSize => _preferredSize;
468466
Size _preferredSize;
469467
set preferredSize(Size value) {
470-
assert(value != null);
471468
if (preferredSize == value) {
472469
return;
473470
}

0 commit comments

Comments
 (0)