[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Remove unnecessary null checks in flutter/rendering (#118923)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer committed Jan 21, 2023
1 parent bae4c1d commit 9837eb6
Show file tree
Hide file tree
Showing 37 changed files with 127 additions and 757 deletions.
12 changes: 1 addition & 11 deletions packages/flutter/lib/src/rendering/animated_size.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
super.textDirection,
super.child,
Clip clipBehavior = Clip.hardEdge,
}) : assert(vsync != null),
assert(duration != null),
assert(curve != null),
assert(clipBehavior != null),
_vsync = vsync,
}) : _vsync = vsync,
_clipBehavior = clipBehavior {
_controller = AnimationController(
vsync: vsync,
Expand Down Expand Up @@ -119,7 +115,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
/// The duration of the animation.
Duration get duration => _controller.duration!;
set duration(Duration value) {
assert(value != null);
if (value == _controller.duration) {
return;
}
Expand All @@ -138,7 +133,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
/// The curve of the animation.
Curve get curve => _animation.curve;
set curve(Curve value) {
assert(value != null);
if (value == _animation.curve) {
return;
}
Expand All @@ -151,7 +145,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
Clip get clipBehavior => _clipBehavior;
Clip _clipBehavior = Clip.hardEdge;
set clipBehavior(Clip value) {
assert(value != null);
if (value != _clipBehavior) {
_clipBehavior = value;
markNeedsPaint();
Expand All @@ -169,7 +162,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
TickerProvider get vsync => _vsync;
TickerProvider _vsync;
set vsync(TickerProvider value) {
assert(value != null);
if (value == _vsync) {
return;
}
Expand Down Expand Up @@ -218,7 +210,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {

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

assert(_state != null);
switch (_state) {
case RenderAnimatedSizeState.start:
_layoutStart();
Expand Down Expand Up @@ -253,7 +244,6 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
// size without modifying global state. See performLayout for comments
// explaining the rational behind the implementation.
final Size childSize = child!.getDryLayout(constraints);
assert(_state != null);
switch (_state) {
case RenderAnimatedSizeState.start:
return constraints.constrain(childSize);
Expand Down
8 changes: 0 additions & 8 deletions packages/flutter/lib/src/rendering/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
..onSemanticsAction = _handleSemanticsAction;
initRenderView();
_handleSemanticsEnabledChanged();
assert(renderView != null);
addPersistentFrameCallback(_handlePersistentFrameCallback);
initMouseTracker();
if (kIsWeb) {
Expand Down Expand Up @@ -234,7 +233,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// Sets the given [RenderView] object (which must not be null), and its tree, to
/// be the new render tree to display. The previous tree, if any, is detached.
set renderView(RenderView value) {
assert(value != null);
_pipelineOwner.rootNode = value;
}

Expand All @@ -244,7 +242,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
@protected
@visibleForTesting
void handleMetricsChanged() {
assert(renderView != null);
renderView.configuration = createViewConfiguration();
if (renderView.child != null) {
scheduleForcedFrame();
Expand Down Expand Up @@ -512,7 +509,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
// When editing the above, also update widgets/binding.dart's copy.
@protected
void drawFrame() {
assert(renderView != null);
pipelineOwner.flushLayout();
pipelineOwner.flushCompositingBits();
pipelineOwner.flushPaint();
Expand Down Expand Up @@ -544,9 +540,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture

@override
void hitTest(HitTestResult result, Offset position) {
assert(renderView != null);
assert(result != null);
assert(position != null);
renderView.hitTest(result, position: position);
super.hitTest(result, position);
}
Expand Down Expand Up @@ -620,7 +613,6 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
/// This binding does not automatically schedule any frames. Callers are
/// responsible for deciding when to first call [scheduleFrame].
RenderingFlutterBinding({ RenderBox? root }) {
assert(renderView != null);
renderView.child = root;
}

Expand Down
48 changes: 2 additions & 46 deletions packages/flutter/lib/src/rendering/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ class BoxConstraints extends Constraints {
this.maxWidth = double.infinity,
this.minHeight = 0.0,
this.maxHeight = double.infinity,
}) : assert(minWidth != null),
assert(maxWidth != null),
assert(minHeight != null),
assert(maxHeight != null);
});

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

/// Returns new box constraints that are smaller by the given edge dimensions.
BoxConstraints deflate(EdgeInsets edges) {
assert(edges != null);
assert(debugAssertIsValid());
final double horizontal = edges.horizontal;
final double vertical = edges.vertical;
Expand Down Expand Up @@ -472,7 +468,6 @@ class BoxConstraints extends Constraints {
///
/// {@macro dart.ui.shadow.lerp}
static BoxConstraints? lerp(BoxConstraints? a, BoxConstraints? b, double t) {
assert(t != null);
if (a == null && b == null) {
return null;
}
Expand Down Expand Up @@ -762,8 +757,6 @@ class BoxHitTestResult extends HitTestResult {
required Offset position,
required BoxHitTest hitTest,
}) {
assert(position != null);
assert(hitTest != null);
if (transform != null) {
transform = Matrix4.tryInvert(PointerEvent.removePerspectiveTransform(transform));
if (transform == null) {
Expand Down Expand Up @@ -801,8 +794,6 @@ class BoxHitTestResult extends HitTestResult {
required Offset position,
required BoxHitTest hitTest,
}) {
assert(position != null);
assert(hitTest != null);
final Offset transformedPosition = offset == null ? position : position - offset;
if (offset != null) {
pushOffset(-offset);
Expand Down Expand Up @@ -838,9 +829,6 @@ class BoxHitTestResult extends HitTestResult {
required Offset position,
required BoxHitTest hitTest,
}) {
assert(position != null);
assert(hitTest != null);
assert(position != null);
final Offset transformedPosition = transform == null ?
position : MatrixUtils.transformPoint(transform, position);
if (transform != null) {
Expand Down Expand Up @@ -887,7 +875,6 @@ class BoxHitTestResult extends HitTestResult {
Matrix4? rawTransform,
required BoxHitTestWithOutOfBandPosition hitTest,
}) {
assert(hitTest != null);
assert(
(paintOffset == null && paintTransform == null && rawTransform != null) ||
(paintOffset == null && paintTransform != null && rawTransform == null) ||
Expand Down Expand Up @@ -915,8 +902,7 @@ class BoxHitTestEntry extends HitTestEntry<RenderBox> {
/// Creates a box hit test entry.
///
/// The [localPosition] argument must not be null.
BoxHitTestEntry(super.target, this.localPosition)
: assert(localPosition != null);
BoxHitTestEntry(super.target, this.localPosition);

/// The position of the hit test in the local coordinates of [target].
final Offset localPosition;
Expand Down Expand Up @@ -1452,13 +1438,6 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper
double getMinIntrinsicWidth(double height) {
assert(() {
if (height == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The height argument to getMinIntrinsicWidth was null.'),
ErrorDescription('The argument to getMinIntrinsicWidth must not be negative or null.'),
ErrorHint('If you do not have a specific height in mind, then pass double.infinity instead.'),
]);
}
if (height < 0.0) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The height argument to getMinIntrinsicWidth was negative.'),
Expand Down Expand Up @@ -1601,13 +1580,6 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper
double getMaxIntrinsicWidth(double height) {
assert(() {
if (height == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The height argument to getMaxIntrinsicWidth was null.'),
ErrorDescription('The argument to getMaxIntrinsicWidth must not be negative or null.'),
ErrorHint('If you do not have a specific height in mind, then pass double.infinity instead.'),
]);
}
if (height < 0.0) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The height argument to getMaxIntrinsicWidth was negative.'),
Expand Down Expand Up @@ -1684,13 +1656,6 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper
double getMinIntrinsicHeight(double width) {
assert(() {
if (width == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The width argument to getMinIntrinsicHeight was null.'),
ErrorDescription('The argument to getMinIntrinsicHeight must not be negative or null.'),
ErrorHint('If you do not have a specific width in mind, then pass double.infinity instead.'),
]);
}
if (width < 0.0) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The width argument to getMinIntrinsicHeight was negative.'),
Expand Down Expand Up @@ -1766,13 +1731,6 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper
double getMaxIntrinsicHeight(double width) {
assert(() {
if (width == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The width argument to getMaxIntrinsicHeight was null.'),
ErrorDescription('The argument to getMaxIntrinsicHeight must not be negative or null.'),
ErrorHint('If you do not have a specific width in mind, then pass double.infinity instead.'),
]);
}
if (width < 0.0) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The width argument to getMaxIntrinsicHeight was negative.'),
Expand Down Expand Up @@ -2253,7 +2211,6 @@ abstract class RenderBox extends RenderObject {

@override
void debugAssertDoesMeetConstraints() {
assert(constraints != null);
assert(() {
if (!hasSize) {
final DiagnosticsNode contract;
Expand Down Expand Up @@ -2582,7 +2539,6 @@ abstract class RenderBox extends RenderObject {
/// child's [parentData] in the [BoxParentData.offset] field.
@override
void applyPaintTransform(RenderObject child, Matrix4 transform) {
assert(child != null);
assert(child.parent == this);
assert(() {
if (child.parentData is! BoxParentData) {
Expand Down
9 changes: 1 addition & 8 deletions packages/flutter/lib/src/rendering/custom_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ abstract class MultiChildLayoutDelegate {
'There is no child with the id "$childId".',
);
}
if (offset == null) {
throw FlutterError(
'The $this custom multichild layout delegate provided a null position for the child with id "$childId".',
);
}
return true;
}());
final MultiChildLayoutParentData childParentData = child!.parentData! as MultiChildLayoutParentData;
Expand Down Expand Up @@ -311,8 +306,7 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
RenderCustomMultiChildLayoutBox({
List<RenderBox>? children,
required MultiChildLayoutDelegate delegate,
}) : assert(delegate != null),
_delegate = delegate {
}) : _delegate = delegate {
addAll(children);
}

Expand All @@ -327,7 +321,6 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
MultiChildLayoutDelegate get delegate => _delegate;
MultiChildLayoutDelegate _delegate;
set delegate(MultiChildLayoutDelegate newDelegate) {
assert(newDelegate != null);
if (_delegate == newDelegate) {
return;
}
Expand Down
7 changes: 2 additions & 5 deletions packages/flutter/lib/src/rendering/custom_paint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ class CustomPainterSemantics {
required this.properties,
this.transform,
this.tags,
}) : assert(rect != null),
assert(properties != null);
});

/// Identifies this object in a list of siblings.
///
Expand Down Expand Up @@ -371,8 +370,7 @@ class RenderCustomPaint extends RenderProxyBox {
this.isComplex = false,
this.willChange = false,
RenderBox? child,
}) : assert(preferredSize != null),
_painter = painter,
}) : _painter = painter,
_foregroundPainter = foregroundPainter,
_preferredSize = preferredSize,
super(child);
Expand Down Expand Up @@ -467,7 +465,6 @@ class RenderCustomPaint extends RenderProxyBox {
Size get preferredSize => _preferredSize;
Size _preferredSize;
set preferredSize(Size value) {
assert(value != null);
if (preferredSize == value) {
return;
}
Expand Down
Loading

0 comments on commit 9837eb6

Please sign in to comment.