Unverified Commit e71eb183 authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Use `curly_braces_in_flow_control_structures` for `rendering` (#104611)

* Use `curly_braces_in_flow_control_structures` for `rendering`

* fix comments

* fix dangling
parent b0aa5025
......@@ -94,8 +94,9 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
duration: duration,
reverseDuration: reverseDuration,
)..addListener(() {
if (_controller.value != _lastValue)
if (_controller.value != _lastValue) {
markNeedsLayout();
}
});
_animation = CurvedAnimation(
parent: _controller,
......@@ -120,16 +121,18 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
Duration get duration => _controller.duration!;
set duration(Duration value) {
assert(value != null);
if (value == _controller.duration)
if (value == _controller.duration) {
return;
}
_controller.duration = value;
}
/// The duration of the animation when running in reverse.
Duration? get reverseDuration => _controller.reverseDuration;
set reverseDuration(Duration? value) {
if (value == _controller.reverseDuration)
if (value == _controller.reverseDuration) {
return;
}
_controller.reverseDuration = value;
}
......@@ -137,8 +140,9 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
Curve get curve => _animation.curve;
set curve(Curve value) {
assert(value != null);
if (value == _animation.curve)
if (value == _animation.curve) {
return;
}
_animation.curve = value;
}
......@@ -167,8 +171,9 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
TickerProvider _vsync;
set vsync(TickerProvider value) {
assert(value != null);
if (value == _vsync)
if (value == _vsync) {
return;
}
_vsync = value;
_controller.resync(vsync);
}
......@@ -234,9 +239,10 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
alignChild();
if (size.width < _sizeTween.end!.width ||
size.height < _sizeTween.end!.height)
size.height < _sizeTween.end!.height) {
_hasVisualOverflow = true;
}
}
@override
Size computeDryLayout(BoxConstraints constraints) {
......@@ -318,8 +324,10 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
} else {
// Child size stabilized.
_state = RenderAnimatedSizeState.stable;
if (!_controller.isAnimating)
_controller.forward(); // resume the animation after being detached
if (!_controller.isAnimating) {
// Resume the animation after being detached.
_controller.forward();
}
}
}
......
......@@ -77,8 +77,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
name: 'debugPaint',
getter: () async => debugPaintSizeEnabled,
setter: (bool value) {
if (debugPaintSizeEnabled == value)
if (debugPaintSizeEnabled == value) {
return Future<void>.value();
}
debugPaintSizeEnabled = value;
return _forceRepaint();
},
......@@ -87,8 +88,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
name: 'debugPaintBaselinesEnabled',
getter: () async => debugPaintBaselinesEnabled,
setter: (bool value) {
if (debugPaintBaselinesEnabled == value)
if (debugPaintBaselinesEnabled == value) {
return Future<void>.value();
}
debugPaintBaselinesEnabled = value;
return _forceRepaint();
},
......@@ -99,8 +101,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
setter: (bool value) {
final bool repaint = debugRepaintRainbowEnabled && !value;
debugRepaintRainbowEnabled = value;
if (repaint)
if (repaint) {
return _forceRepaint();
}
return Future<void>.value();
},
);
......@@ -117,8 +120,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
name: 'debugDisableClipLayers',
getter: () async => debugDisableClipLayers,
setter: (bool value) {
if (debugDisableClipLayers == value)
if (debugDisableClipLayers == value) {
return Future<void>.value();
}
debugDisableClipLayers = value;
return _forceRepaint();
},
......@@ -127,8 +131,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
name: 'debugDisablePhysicalShapeLayers',
getter: () async => debugDisablePhysicalShapeLayers,
setter: (bool value) {
if (debugDisablePhysicalShapeLayers == value)
if (debugDisablePhysicalShapeLayers == value) {
return Future<void>.value();
}
debugDisablePhysicalShapeLayers = value;
return _forceRepaint();
},
......@@ -137,8 +142,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
name: 'debugDisableOpacityLayers',
getter: () async => debugDisableOpacityLayers,
setter: (bool value) {
if (debugDisableOpacityLayers == value)
if (debugDisableOpacityLayers == value) {
return Future<void>.value();
}
debugDisableOpacityLayers = value;
return _forceRepaint();
},
......@@ -181,16 +187,18 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
name: 'profileRenderObjectPaints',
getter: () async => debugProfilePaintsEnabled,
setter: (bool value) async {
if (debugProfilePaintsEnabled != value)
if (debugProfilePaintsEnabled != value) {
debugProfilePaintsEnabled = value;
}
},
);
registerBoolServiceExtension(
name: 'profileRenderObjectLayouts',
getter: () async => debugProfileLayoutsEnabled,
setter: (bool value) async {
if (debugProfileLayoutsEnabled != value)
if (debugProfileLayoutsEnabled != value) {
debugProfileLayoutsEnabled = value;
}
},
);
}
......@@ -431,9 +439,10 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
// Always schedule a warm up frame even if the deferral count is not down to
// zero yet since the removal of a deferral may uncover new deferrals that
// are lower in the widget tree.
if (!_firstFrameSent)
if (!_firstFrameSent) {
scheduleWarmUpFrame();
}
}
/// Call this to pretend that no frames have been sent to the engine yet.
///
......@@ -610,8 +619,9 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
/// if you are using it directly. If you are using the widgets framework,
/// see [WidgetsFlutterBinding.ensureInitialized].
static RendererBinding ensureInitialized() {
if (RendererBinding._instance == null)
if (RendererBinding._instance == null) {
RenderingFlutterBinding();
}
return RendererBinding.instance;
}
}
This diff is collapsed.
......@@ -318,20 +318,23 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
@override
void setupParentData(RenderBox child) {
if (child.parentData is! MultiChildLayoutParentData)
if (child.parentData is! MultiChildLayoutParentData) {
child.parentData = MultiChildLayoutParentData();
}
}
/// The delegate that controls the layout of the children.
MultiChildLayoutDelegate get delegate => _delegate;
MultiChildLayoutDelegate _delegate;
set delegate(MultiChildLayoutDelegate newDelegate) {
assert(newDelegate != null);
if (_delegate == newDelegate)
if (_delegate == newDelegate) {
return;
}
final MultiChildLayoutDelegate oldDelegate = _delegate;
if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate))
if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate)) {
markNeedsLayout();
}
_delegate = newDelegate;
if (attached) {
oldDelegate._relayout?.removeListener(markNeedsLayout);
......@@ -363,32 +366,36 @@ class RenderCustomMultiChildLayoutBox extends RenderBox
@override
double computeMinIntrinsicWidth(double height) {
final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width;
if (width.isFinite)
if (width.isFinite) {
return width;
}
return 0.0;
}
@override
double computeMaxIntrinsicWidth(double height) {
final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width;
if (width.isFinite)
if (width.isFinite) {
return width;
}
return 0.0;
}
@override
double computeMinIntrinsicHeight(double width) {
final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height;
if (height.isFinite)
if (height.isFinite) {
return height;
}
return 0.0;
}
@override
double computeMaxIntrinsicHeight(double width) {
final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height;
if (height.isFinite)
if (height.isFinite) {
return height;
}
return 0.0;
}
......
......@@ -397,8 +397,9 @@ class RenderCustomPaint extends RenderProxyBox {
///
/// If the new value is null, then there is no background custom painter.
set painter(CustomPainter? value) {
if (_painter == value)
if (_painter == value) {
return;
}
final CustomPainter? oldPainter = _painter;
_painter = value;
_didUpdatePainter(_painter, oldPainter);
......@@ -422,8 +423,9 @@ class RenderCustomPaint extends RenderProxyBox {
///
/// If the new value is null, then there is no foreground custom painter.
set foregroundPainter(CustomPainter? value) {
if (_foregroundPainter == value)
if (_foregroundPainter == value) {
return;
}
final CustomPainter? oldPainter = _foregroundPainter;
_foregroundPainter = value;
_didUpdatePainter(_foregroundPainter, oldPainter);
......@@ -447,8 +449,9 @@ class RenderCustomPaint extends RenderProxyBox {
// Check if we need to rebuild semantics.
if (newPainter == null) {
assert(oldPainter != null); // We should be called only for changes.
if (attached)
if (attached) {
markNeedsSemanticsUpdate();
}
} else if (oldPainter == null ||
newPainter.runtimeType != oldPainter.runtimeType ||
newPainter.shouldRebuildSemantics(oldPainter)) {
......@@ -467,8 +470,9 @@ class RenderCustomPaint extends RenderProxyBox {
Size _preferredSize;
set preferredSize(Size value) {
assert(value != null);
if (preferredSize == value)
if (preferredSize == value) {
return;
}
_preferredSize = value;
markNeedsLayout();
}
......@@ -488,29 +492,33 @@ class RenderCustomPaint extends RenderProxyBox {
@override
double computeMinIntrinsicWidth(double height) {
if (child == null)
if (child == null) {
return preferredSize.width.isFinite ? preferredSize.width : 0;
}
return super.computeMinIntrinsicWidth(height);
}
@override
double computeMaxIntrinsicWidth(double height) {
if (child == null)
if (child == null) {
return preferredSize.width.isFinite ? preferredSize.width : 0;
}
return super.computeMaxIntrinsicWidth(height);
}
@override
double computeMinIntrinsicHeight(double width) {
if (child == null)
if (child == null) {
return preferredSize.height.isFinite ? preferredSize.height : 0;
}
return super.computeMinIntrinsicHeight(width);
}
@override
double computeMaxIntrinsicHeight(double width) {
if (child == null)
if (child == null) {
return preferredSize.height.isFinite ? preferredSize.height : 0;
}
return super.computeMaxIntrinsicHeight(width);
}
......@@ -530,8 +538,9 @@ class RenderCustomPaint extends RenderProxyBox {
@override
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
if (_foregroundPainter != null && (_foregroundPainter!.hitTest(position) ?? false))
if (_foregroundPainter != null && (_foregroundPainter!.hitTest(position) ?? false)) {
return true;
}
return super.hitTestChildren(result, position: position);
}
......@@ -558,8 +567,9 @@ class RenderCustomPaint extends RenderProxyBox {
debugPreviousCanvasSaveCount = canvas.getSaveCount();
return true;
}());
if (offset != Offset.zero)
if (offset != Offset.zero) {
canvas.translate(offset.dx, offset.dy);
}
painter.paint(canvas, size);
assert(() {
// This isn't perfect. For example, we can't catch the case of
......@@ -613,11 +623,13 @@ class RenderCustomPaint extends RenderProxyBox {
}
void _setRasterCacheHints(PaintingContext context) {
if (isComplex)
if (isComplex) {
context.setIsComplexHint();
if (willChange)
}
if (willChange) {
context.setWillChangeHint();
}
}
/// Builds semantics for the picture drawn by [painter].
SemanticsBuilderCallback? _backgroundSemanticsBuilder;
......@@ -745,8 +757,9 @@ class RenderCustomPaint extends RenderProxyBox {
while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) {
final SemanticsNode oldChild = oldSemantics[oldChildrenTop];
final CustomPainterSemantics newSemantics = newChildSemantics[newChildrenTop];
if (!_canUpdateSemanticsChild(oldChild, newSemantics))
if (!_canUpdateSemanticsChild(oldChild, newSemantics)) {
break;
}
final SemanticsNode newChild = _updateSemanticsChild(oldChild, newSemantics);
newChildren[newChildrenTop] = newChild;
newChildrenTop += 1;
......@@ -757,8 +770,9 @@ class RenderCustomPaint extends RenderProxyBox {
while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) {
final SemanticsNode oldChild = oldSemantics[oldChildrenBottom];
final CustomPainterSemantics newChild = newChildSemantics[newChildrenBottom];
if (!_canUpdateSemanticsChild(oldChild, newChild))
if (!_canUpdateSemanticsChild(oldChild, newChild)) {
break;
}
oldChildrenBottom -= 1;
newChildrenBottom -= 1;
}
......@@ -770,8 +784,9 @@ class RenderCustomPaint extends RenderProxyBox {
oldKeyedChildren = <Key, SemanticsNode>{};
while (oldChildrenTop <= oldChildrenBottom) {
final SemanticsNode oldChild = oldSemantics[oldChildrenTop];
if (oldChild.key != null)
if (oldChild.key != null) {
oldKeyedChildren[oldChild.key!] = oldChild;
}
oldChildrenTop += 1;
}
}
......
......@@ -504,9 +504,10 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
@override
void setupParentData(RenderBox child) {
if (child.parentData is! FlexParentData)
if (child.parentData is! FlexParentData) {
child.parentData = FlexParentData();
}
}
bool get _canComputeIntrinsics => crossAxisAlignment != CrossAxisAlignment.baseline;
......@@ -589,8 +590,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
child = firstChild;
while (child != null) {
final int flex = _getFlex(child);
if (flex > 0)
if (flex > 0) {
maxCrossSize = math.max(maxCrossSize, childSize(child, spacePerFlex * flex));
}
final FlexParentData childParentData = child.parentData! as FlexParentData;
child = childParentData.nextSibling;
}
......@@ -637,8 +639,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
if (_direction == Axis.horizontal)
if (_direction == Axis.horizontal) {
return defaultComputeDistanceToHighestActualBaseline(baseline);
}
return defaultComputeDistanceToFirstActualBaseline(baseline);
}
......@@ -730,16 +733,20 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
RenderBox? node = this;
switch (_direction) {
case Axis.horizontal:
while (!node!.constraints.hasBoundedWidth && node.parent is RenderBox)
while (!node!.constraints.hasBoundedWidth && node.parent is RenderBox) {
node = node.parent! as RenderBox;
if (!node.constraints.hasBoundedWidth)
}
if (!node.constraints.hasBoundedWidth) {
node = null;
}
break;
case Axis.vertical:
while (!node!.constraints.hasBoundedHeight && node.parent is RenderBox)
while (!node!.constraints.hasBoundedHeight && node.parent is RenderBox) {
node = node.parent! as RenderBox;
if (!node.constraints.hasBoundedHeight)
}
if (!node.constraints.hasBoundedHeight) {
node = null;
}
break;
}
if (node != null) {
......@@ -943,8 +950,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
double maxSizeBelowBaseline = 0;
while (child != null) {
assert(() {
if (textBaseline == null)
if (textBaseline == null) {
throw FlutterError('To use FlexAlignItems.baseline, you must also specify which baseline to use using the "baseline" argument.');
}
return true;
}());
final double? distance = child.getDistanceToBaseline(textBaseline!, onlyReal: true);
......@@ -1039,17 +1047,19 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
if (_direction == Axis.horizontal) {
assert(textBaseline != null);
final double? distance = child.getDistanceToBaseline(textBaseline!, onlyReal: true);
if (distance != null)
if (distance != null) {
childCrossPosition = maxBaselineDistance - distance;
else
} else {
childCrossPosition = 0.0;
}
} else {
childCrossPosition = 0.0;
}
break;
}
if (flipMainAxis)
if (flipMainAxis) {
childMainPosition -= _getMainSize(child.size);
}
switch (_direction) {
case Axis.horizontal:
childParentData.offset = Offset(childMainPosition, childCrossPosition);
......@@ -1080,8 +1090,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}
// There's no point in drawing the children if we're empty.
if (size.isEmpty)
if (size.isEmpty) {
return;
}
_clipRectLayer.layer = context.pushClipRect(
needsCompositing,
......@@ -1160,9 +1171,10 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
String toStringShort() {
String header = super.toStringShort();
if (!kReleaseMode) {
if (_hasOverflow)
if (_hasOverflow) {
header += ' OVERFLOWING';
}
}
return header;
}
......
......@@ -193,11 +193,12 @@ class RenderFlow extends RenderBox
@override
void setupParentData(RenderBox child) {
final ParentData? childParentData = child.parentData;
if (childParentData is FlowParentData)
if (childParentData is FlowParentData) {
childParentData._transform = null;
else
} else {
child.parentData = FlowParentData();
}
}
/// The delegate that controls the transformation matrices of the children.
FlowDelegate get delegate => _delegate;
......@@ -209,15 +210,17 @@ class RenderFlow extends RenderBox
/// layout or painting.
set delegate(FlowDelegate newDelegate) {
assert(newDelegate != null);
if (_delegate == newDelegate)
if (_delegate == newDelegate) {
return;
}
final FlowDelegate oldDelegate = _delegate;
_delegate = newDelegate;
if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate))
if (newDelegate.runtimeType != oldDelegate.runtimeType || newDelegate.shouldRelayout(oldDelegate)) {
markNeedsLayout();
else if (newDelegate.shouldRepaint(oldDelegate))
} else if (newDelegate.shouldRepaint(oldDelegate)) {
markNeedsPaint();
}
if (attached) {
oldDelegate._repaint?.removeListener(markNeedsPaint);
......@@ -266,32 +269,36 @@ class RenderFlow extends RenderBox
@override
double computeMinIntrinsicWidth(double height) {
final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width;
if (width.isFinite)
if (width.isFinite) {
return width;
}
return 0.0;
}
@override
double computeMaxIntrinsicWidth(double height) {
final double width = _getSize(BoxConstraints.tightForFinite(height: height)).width;
if (width.isFinite)
if (width.isFinite) {
return width;
}
return 0.0;
}
@override
double computeMinIntrinsicHeight(double width) {
final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height;
if (height.isFinite)
if (height.isFinite) {
return height;
}
return 0.0;
}
@override
double computeMaxIntrinsicHeight(double width) {
final double height = _getSize(BoxConstraints.tightForFinite(width: width)).height;
if (height.isFinite)
if (height.isFinite) {
return height;
}
return 0.0;
}
......@@ -330,8 +337,9 @@ class RenderFlow extends RenderBox
@override
Size? getChildSize(int i) {
if (i < 0 || i >= _randomAccessChildren.length)
if (i < 0 || i >= _randomAccessChildren.length) {
return null;
}
return _randomAccessChildren[i].size;
}
......@@ -355,8 +363,9 @@ class RenderFlow extends RenderBox
// We return after assigning _transform so that the transparent child can
// still be hit tested at the correct location.
if (opacity == 0.0)
if (opacity == 0.0) {
return;
}
void painter(PaintingContext context, Offset offset) {
context.paintChild(child, offset);
......@@ -411,13 +420,15 @@ class RenderFlow extends RenderBox
final List<RenderBox> children = getChildrenAsList();
for (int i = _lastPaintOrder.length - 1; i >= 0; --i) {
final int childIndex = _lastPaintOrder[i];
if (childIndex >= children.length)
if (childIndex >= children.length) {
continue;
}
final RenderBox child = children[childIndex];
final FlowParentData childParentData = child.parentData! as FlowParentData;
final Matrix4? transform = childParentData._transform;
if (transform == null)
if (transform == null) {
continue;
}
final bool absorbed = result.addWithPaintTransform(
transform: transform,
position: position,
......@@ -425,17 +436,19 @@ class RenderFlow extends RenderBox
return child.hitTest(result, position: position);
},
);
if (absorbed)
if (absorbed) {
return true;
}
}
return false;
}
@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
final FlowParentData childParentData = child.parentData! as FlowParentData;
if (childParentData._transform != null)
if (childParentData._transform != null) {
transform.multiply(childParentData._transform!);
}
super.applyPaintTransform(child, transform);
}
}
......@@ -73,8 +73,9 @@ class RenderImage extends RenderBox {
bool? _flipHorizontally;
void _resolve() {
if (_resolvedAlignment != null)
if (_resolvedAlignment != null) {
return;
}
_resolvedAlignment = alignment.resolve(textDirection);
_flipHorizontally = matchTextDirection && textDirection == TextDirection.rtl;
}
......@@ -101,9 +102,10 @@ class RenderImage extends RenderBox {
_image?.dispose();
_image = value;
markNeedsPaint();
if (_width == null || _height == null)
if (_width == null || _height == null) {
markNeedsLayout();
}
}
/// A string used to identify the source of the image.
String? debugImageLabel;
......@@ -115,8 +117,9 @@ class RenderImage extends RenderBox {
double? get width => _width;
double? _width;
set width(double? value) {
if (value == _width)
if (value == _width) {
return;
}
_width = value;
markNeedsLayout();
}
......@@ -128,8 +131,9 @@ class RenderImage extends RenderBox {
double? get height => _height;
double? _height;
set height(double? value) {
if (value == _height)
if (value == _height) {
return;
}
_height = value;
markNeedsLayout();
}
......@@ -141,8 +145,9 @@ class RenderImage extends RenderBox {
double _scale;
set scale(double value) {
assert(value != null);
if (value == _scale)
if (value == _scale) {
return;
}
_scale = value;
markNeedsLayout();
}
......@@ -150,18 +155,20 @@ class RenderImage extends RenderBox {
ColorFilter? _colorFilter;
void _updateColorFilter() {
if (_color == null)
if (_color == null) {
_colorFilter = null;
else
} else {
_colorFilter = ColorFilter.mode(_color!, _colorBlendMode ?? BlendMode.srcIn);
}
}
/// If non-null, this color is blended with each image pixel using [colorBlendMode].
Color? get color => _color;
Color? _color;
set color(Color? value) {
if (value == _color)
if (value == _color) {
return;
}
_color = value;
_updateColorFilter();
markNeedsPaint();
......@@ -172,15 +179,18 @@ class RenderImage extends RenderBox {
Animation<double>? get opacity => _opacity;
Animation<double>? _opacity;
set opacity(Animation<double>? value) {
if (value == _opacity)
if (value == _opacity) {
return;
}
if (attached)
if (attached) {
_opacity?.removeListener(markNeedsPaint);
}
_opacity = value;
if (attached)
if (attached) {
value?.addListener(markNeedsPaint);
}
}
/// Used to set the filterQuality of the image.
///
......@@ -191,8 +201,9 @@ class RenderImage extends RenderBox {
FilterQuality _filterQuality;
set filterQuality(FilterQuality value) {
assert(value != null);
if (value == _filterQuality)
if (value == _filterQuality) {
return;
}
_filterQuality = value;
markNeedsPaint();
}
......@@ -209,8 +220,9 @@ class RenderImage extends RenderBox {
BlendMode? get colorBlendMode => _colorBlendMode;
BlendMode? _colorBlendMode;
set colorBlendMode(BlendMode? value) {
if (value == _colorBlendMode)
if (value == _colorBlendMode) {
return;
}
_colorBlendMode = value;
_updateColorFilter();
markNeedsPaint();
......@@ -223,8 +235,9 @@ class RenderImage extends RenderBox {
BoxFit? get fit => _fit;
BoxFit? _fit;
set fit(BoxFit? value) {
if (value == _fit)
if (value == _fit) {
return;
}
_fit = value;
markNeedsPaint();
}
......@@ -237,8 +250,9 @@ class RenderImage extends RenderBox {
AlignmentGeometry _alignment;
set alignment(AlignmentGeometry value) {
assert(value != null);
if (value == _alignment)
if (value == _alignment) {
return;
}
_alignment = value;
_markNeedResolution();
}
......@@ -248,8 +262,9 @@ class RenderImage extends RenderBox {
ImageRepeat _repeat;
set repeat(ImageRepeat value) {
assert(value != null);
if (value == _repeat)
if (value == _repeat) {
return;
}
_repeat = value;
markNeedsPaint();
}
......@@ -264,8 +279,9 @@ class RenderImage extends RenderBox {
Rect? get centerSlice => _centerSlice;
Rect? _centerSlice;
set centerSlice(Rect? value) {
if (value == _centerSlice)
if (value == _centerSlice) {
return;
}
_centerSlice = value;
markNeedsPaint();
}
......@@ -278,8 +294,9 @@ class RenderImage extends RenderBox {
bool get invertColors => _invertColors;
bool _invertColors;
set invertColors(bool value) {
if (value == _invertColors)
if (value == _invertColors) {
return;
}
_invertColors = value;
markNeedsPaint();
}
......@@ -302,8 +319,9 @@ class RenderImage extends RenderBox {
bool _matchTextDirection;
set matchTextDirection(bool value) {
assert(value != null);
if (value == _matchTextDirection)
if (value == _matchTextDirection) {
return;
}
_matchTextDirection = value;
_markNeedResolution();
}
......@@ -316,8 +334,9 @@ class RenderImage extends RenderBox {
TextDirection? get textDirection => _textDirection;
TextDirection? _textDirection;
set textDirection(TextDirection? value) {
if (_textDirection == value)
if (_textDirection == value) {
return;
}
_textDirection = value;
_markNeedResolution();
}
......@@ -351,8 +370,9 @@ class RenderImage extends RenderBox {
height: _height,
).enforce(constraints);
if (_image == null)
if (_image == null) {
return constraints.smallest;
}
return constraints.constrainSizeAndAttemptToPreserveAspectRatio(Size(
_image!.width.toDouble() / _scale,
......@@ -363,8 +383,9 @@ class RenderImage extends RenderBox {
@override
double computeMinIntrinsicWidth(double height) {
assert(height >= 0.0);
if (_width == null && _height == null)
if (_width == null && _height == null) {
return 0.0;
}
return _sizeForConstraints(BoxConstraints.tightForFinite(height: height)).width;
}
......@@ -377,8 +398,9 @@ class RenderImage extends RenderBox {
@override
double computeMinIntrinsicHeight(double width) {
assert(width >= 0.0);
if (_width == null && _height == null)
if (_width == null && _height == null) {
return 0.0;
}
return _sizeForConstraints(BoxConstraints.tightForFinite(width: width)).height;
}
......@@ -415,8 +437,9 @@ class RenderImage extends RenderBox {
@override
void paint(PaintingContext context, Offset offset) {
if (_image == null)
if (_image == null) {
return;
}
_resolve();
assert(_resolvedAlignment != null);
assert(_flipHorizontally != null);
......
......@@ -39,9 +39,10 @@ class RenderListBody extends RenderBox
@override
void setupParentData(RenderBox child) {
if (child.parentData is! ListBodyParentData)
if (child.parentData is! ListBodyParentData) {
child.parentData = ListBodyParentData();
}
}
/// The direction in which the children are laid out.
///
......@@ -51,8 +52,9 @@ class RenderListBody extends RenderBox
AxisDirection _axisDirection;
set axisDirection(AxisDirection value) {
assert(value != null);
if (_axisDirection == value)
if (_axisDirection == value) {
return;
}
_axisDirection = value;
markNeedsLayout();
}
......@@ -92,12 +94,14 @@ class RenderListBody extends RenderBox
assert(() {
switch (mainAxis) {
case Axis.horizontal:
if (!constraints.hasBoundedWidth)
if (!constraints.hasBoundedWidth) {
return true;
}
break;
case Axis.vertical:
if (!constraints.hasBoundedHeight)
if (!constraints.hasBoundedHeight) {
return true;
}
break;
}
throw FlutterError.fromParts(<DiagnosticsNode>[
......@@ -116,12 +120,14 @@ class RenderListBody extends RenderBox
assert(() {
switch (mainAxis) {
case Axis.horizontal:
if (constraints.hasBoundedHeight)
if (constraints.hasBoundedHeight) {
return true;
}
break;
case Axis.vertical:
if (constraints.hasBoundedWidth)
if (constraints.hasBoundedWidth) {
return true;
}
break;
}
// TODO(ianh): Detect if we're actually nested blocks and say something
......
......@@ -226,13 +226,16 @@ class RenderListWheelViewport
ViewportOffset _offset;
set offset(ViewportOffset value) {
assert(value != null);
if (value == _offset)
if (value == _offset) {
return;
if (attached)
}
if (attached) {
_offset.removeListener(_hasScrolled);
}
_offset = value;
if (attached)
if (attached) {
_offset.addListener(_hasScrolled);
}
markNeedsLayout();
}
......@@ -272,8 +275,9 @@ class RenderListWheelViewport
value > 0,
diameterRatioZeroMessage,
);
if (value == _diameterRatio)
if (value == _diameterRatio) {
return;
}
_diameterRatio = value;
markNeedsPaint();
markNeedsSemanticsUpdate();
......@@ -302,8 +306,9 @@ class RenderListWheelViewport
value <= 0.01,
perspectiveTooHighMessage,
);
if (value == _perspective)
if (value == _perspective) {
return;
}
_perspective = value;
markNeedsPaint();
markNeedsSemanticsUpdate();
......@@ -338,8 +343,9 @@ class RenderListWheelViewport
double _offAxisFraction = 0.0;
set offAxisFraction(double value) {
assert(value != null);
if (value == _offAxisFraction)
if (value == _offAxisFraction) {
return;
}
_offAxisFraction = value;
markNeedsPaint();
}
......@@ -351,8 +357,9 @@ class RenderListWheelViewport
bool _useMagnifier = false;
set useMagnifier(bool value) {
assert(value != null);
if (value == _useMagnifier)
if (value == _useMagnifier) {
return;
}
_useMagnifier = value;
markNeedsPaint();
}
......@@ -371,8 +378,9 @@ class RenderListWheelViewport
set magnification(double value) {
assert(value != null);
assert(value > 0);
if (value == _magnification)
if (value == _magnification) {
return;
}
_magnification = value;
markNeedsPaint();
}
......@@ -390,8 +398,9 @@ class RenderListWheelViewport
set overAndUnderCenterOpacity(double value) {
assert(value != null);
assert(value >= 0 && value <= 1);
if (value == _overAndUnderCenterOpacity)
if (value == _overAndUnderCenterOpacity) {
return;
}
_overAndUnderCenterOpacity = value;
markNeedsPaint();
}
......@@ -407,8 +416,9 @@ class RenderListWheelViewport
set itemExtent(double value) {
assert(value != null);
assert(value > 0);
if (value == _itemExtent)
if (value == _itemExtent) {
return;
}
_itemExtent = value;
markNeedsLayout();
}
......@@ -439,8 +449,9 @@ class RenderListWheelViewport
set squeeze(double value) {
assert(value != null);
assert(value > 0);
if (value == _squeeze)
if (value == _squeeze) {
return;
}
_squeeze = value;
markNeedsLayout();
markNeedsSemanticsUpdate();
......@@ -464,8 +475,9 @@ class RenderListWheelViewport
!renderChildrenOutsideViewport || clipBehavior == Clip.none,
clipBehaviorAndRenderChildrenOutsideViewportConflict,
);
if (value == _renderChildrenOutsideViewport)
if (value == _renderChildrenOutsideViewport) {
return;
}
_renderChildrenOutsideViewport = value;
markNeedsLayout();
markNeedsSemanticsUpdate();
......@@ -492,9 +504,10 @@ class RenderListWheelViewport
@override
void setupParentData(RenderObject child) {
if (child.parentData is! ListWheelParentData)
if (child.parentData is! ListWheelParentData) {
child.parentData = ListWheelParentData();
}
}
@override
void attach(PipelineOwner owner) {
......@@ -521,8 +534,9 @@ class RenderListWheelViewport
/// the first item in the center.
double get _minEstimatedScrollExtent {
assert(hasSize);
if (childManager.childCount == null)
if (childManager.childCount == null) {
return double.negativeInfinity;
}
return 0.0;
}
......@@ -530,8 +544,9 @@ class RenderListWheelViewport
/// the last item in the center.
double get _maxEstimatedScrollExtent {
assert(hasSize);
if (childManager.childCount == null)
if (childManager.childCount == null) {
return double.infinity;
}
return math.max(0.0, (childManager.childCount! - 1) * _itemExtent);
}
......@@ -563,8 +578,9 @@ class RenderListWheelViewport
/// When the center of children passes this angle, they are no longer painted
/// if [renderChildrenOutsideViewport] is false.
double get _maxVisibleRadian {
if (_diameterRatio < 1.0)
if (_diameterRatio < 1.0) {
return math.pi / 2.0;
}
return math.asin(1.0 / _diameterRatio);
}
......@@ -594,15 +610,17 @@ class RenderListWheelViewport
@override
double computeMinIntrinsicHeight(double width) {
if (childManager.childCount == null)
if (childManager.childCount == null) {
return 0.0;
}
return childManager.childCount! * _itemExtent;
}
@override
double computeMaxIntrinsicHeight(double width) {
if (childManager.childCount == null)
if (childManager.childCount == null) {
return 0.0;
}
return childManager.childCount! * _itemExtent;
}
......@@ -674,8 +692,9 @@ class RenderListWheelViewport
// If renderChildrenOutsideViewport is true, we spawn extra children by
// doubling the visibility range, those that are in the backside of the
// cylinder won't be painted anyway.
if (renderChildrenOutsideViewport)
if (renderChildrenOutsideViewport) {
visibleHeight *= 2;
}
final double firstVisibleOffset =
offset.pixels + _itemExtent / 2 - visibleHeight / 2;
......@@ -687,20 +706,24 @@ class RenderListWheelViewport
int targetLastIndex = scrollOffsetToIndex(lastVisibleOffset);
// Because we exclude lastVisibleOffset, if there's a new child starting at
// that offset, it is removed.
if (targetLastIndex * _itemExtent == lastVisibleOffset)
if (targetLastIndex * _itemExtent == lastVisibleOffset) {
targetLastIndex--;
}
// Validates the target index range.
while (!childManager.childExistsAt(targetFirstIndex) && targetFirstIndex <= targetLastIndex)
while (!childManager.childExistsAt(targetFirstIndex) && targetFirstIndex <= targetLastIndex) {
targetFirstIndex++;
while (!childManager.childExistsAt(targetLastIndex) && targetFirstIndex <= targetLastIndex)
}
while (!childManager.childExistsAt(targetLastIndex) && targetFirstIndex <= targetLastIndex) {
targetLastIndex--;
}
// If it turns out there's no children to layout, we remove old children and
// return.
if (targetFirstIndex > targetLastIndex) {
while (firstChild != null)
while (firstChild != null) {
_destroyChild(firstChild!);
}
return;
}
......@@ -715,9 +738,10 @@ class RenderListWheelViewport
// Case when there is no intersection.
if (childCount > 0 &&
(indexOf(firstChild!) > targetLastIndex || indexOf(lastChild!) < targetFirstIndex)) {
while (firstChild != null)
while (firstChild != null) {
_destroyChild(firstChild!);
}
}
final BoxConstraints childConstraints = constraints.copyWith(
minHeight: _itemExtent,
......@@ -842,8 +866,9 @@ class RenderListWheelViewport
// renderChildrenOutsideViewport is true. Otherwise, only children within
// suitable angles (via _first/lastVisibleLayoutOffset) reach the paint
// phase.
if (angle > math.pi / 2.0 || angle < -math.pi / 2.0)
if (angle > math.pi / 2.0 || angle < -math.pi / 2.0) {
return;
}
final Matrix4 transform = MatrixUtils.createCylindricalProjectionTransform(
radius: size.height * _diameterRatio / 2.0,
......@@ -1038,8 +1063,9 @@ class RenderListWheelViewport
// `child` will be the last RenderObject before the viewport when walking up from `target`.
RenderObject child = target;
while (child.parent != this)
while (child.parent != this) {
child = child.parent! as RenderObject;
}
final ListWheelParentData parentData = child.parentData! as ListWheelParentData;
final double targetOffset = parentData.offset.dy; // the so-called "centerPosition"
......
......@@ -193,9 +193,10 @@ class MouseTracker extends ChangeNotifier {
void _monitorMouseConnection(VoidCallback task) {
final bool mouseWasConnected = mouseIsConnected;
task();
if (mouseWasConnected != mouseIsConnected)
if (mouseWasConnected != mouseIsConnected) {
notifyListeners();
}
}
bool _debugDuringDeviceUpdate = false;
// Used to wrap any procedure that might call `_handleDeviceUpdate`.
......@@ -217,8 +218,9 @@ class MouseTracker extends ChangeNotifier {
// Whether an observed event might update a device.
static bool _shouldMarkStateDirty(_MouseState? state, PointerEvent event) {
if (state == null)
if (state == null) {
return true;
}
assert(event != null);
final PointerEvent lastEvent = state.latestEvent;
assert(event.device == lastEvent.device);
......@@ -227,8 +229,9 @@ class MouseTracker extends ChangeNotifier {
assert((event is PointerAddedEvent) == (lastEvent is PointerRemovedEvent));
// Ignore events that are unrelated to mouse tracking.
if (event is PointerSignalEvent)
if (event is PointerSignalEvent) {
return false;
}
return lastEvent is PointerAddedEvent
|| event is PointerRemovedEvent
|| lastEvent.position != event.position;
......@@ -256,8 +259,9 @@ class MouseTracker extends ChangeNotifier {
assert(hitTest != null);
final Offset globalPosition = state.latestEvent.position;
final int device = state.device;
if (!_mouseStates.containsKey(device))
if (!_mouseStates.containsKey(device)) {
return LinkedHashMap<MouseTrackerAnnotation, Matrix4>();
}
return _hitTestResultToAnnotations(hitTest(globalPosition));
}
......@@ -303,15 +307,18 @@ class MouseTracker extends ChangeNotifier {
/// position of the event. It should not simply return cached hit test
/// result, because the cache does not change throughout a tap sequence.
void updateWithEvent(PointerEvent event, ValueGetter<HitTestResult> getResult) {
if (event.kind != PointerDeviceKind.mouse)
if (event.kind != PointerDeviceKind.mouse) {
return;
if (event is PointerSignalEvent)
}
if (event is PointerSignalEvent) {
return;
}
final HitTestResult result = event is PointerRemovedEvent ? HitTestResult() : getResult();
final int device = event.device;
final _MouseState? existingState = _mouseStates[device];
if (!_shouldMarkStateDirty(existingState, event))
if (!_shouldMarkStateDirty(existingState, event)) {
return;
}
_monitorMouseConnection(() {
_deviceUpdatePhase(() {
......@@ -319,14 +326,16 @@ class MouseTracker extends ChangeNotifier {
// so that [mouseIsConnected], which is decided by `_mouseStates`, is
// correct during the callbacks.
if (existingState == null) {
if (event is PointerRemovedEvent)
if (event is PointerRemovedEvent) {
return;
}
_mouseStates[device] = _MouseState(initialEvent: event);
} else {
assert(event is! PointerAddedEvent);
if (event is PointerRemovedEvent)
if (event is PointerRemovedEvent) {
_mouseStates.remove(event.device);
}
}
final _MouseState targetState = _mouseStates[device] ?? existingState!;
final PointerEvent lastEvent = targetState.replaceLatestEvent(event);
......@@ -400,8 +409,9 @@ class MouseTracker extends ChangeNotifier {
final PointerExitEvent baseExitEvent = PointerExitEvent.fromMouseEvent(latestEvent);
lastAnnotations.forEach((MouseTrackerAnnotation annotation, Matrix4 transform) {
if (!nextAnnotations.containsKey(annotation))
if (annotation.validForMouseTracker && annotation.onExit != null)
if (annotation.validForMouseTracker && annotation.onExit != null) {
annotation.onExit!(baseExitEvent.transformed(lastAnnotations[annotation]));
}
});
// Send enter events to annotations that are not in last but in next, in
......@@ -411,8 +421,9 @@ class MouseTracker extends ChangeNotifier {
).toList();
final PointerEnterEvent baseEnterEvent = PointerEnterEvent.fromMouseEvent(latestEvent);
for (final MouseTrackerAnnotation annotation in enteringAnnotations.reversed) {
if (annotation.validForMouseTracker && annotation.onEnter != null)
if (annotation.validForMouseTracker && annotation.onEnter != null) {
annotation.onEnter!(baseEnterEvent.transformed(nextAnnotations[annotation]));
}
}
}
}
......@@ -119,9 +119,10 @@ class RenderParagraph extends RenderBox
@override
void setupParentData(RenderBox child) {
if (child.parentData is! TextParentData)
if (child.parentData is! TextParentData) {
child.parentData = TextParentData();
}
}
static final String _placeholderCharacter = String.fromCharCode(PlaceholderSpan.placeholderCodeUnit);
final TextPainter _textPainter;
......@@ -164,8 +165,9 @@ class RenderParagraph extends RenderBox
/// are any.
@visibleForTesting
List<TextSelection> get selections {
if (_lastSelectableFragments == null)
if (_lastSelectableFragments == null) {
return const <TextSelection>[];
}
final List<TextSelection> results = <TextSelection>[];
for (final _SelectableFragment fragment in _lastSelectableFragments!) {
if (fragment._textSelectionStart != null &&
......@@ -191,8 +193,9 @@ class RenderParagraph extends RenderBox
SelectionRegistrar? get registrar => _registrar;
SelectionRegistrar? _registrar;
set registrar(SelectionRegistrar? value) {
if (value == _registrar)
if (value == _registrar) {
return;
}
_removeSelectionRegistrarSubscription();
_disposeSelectableFragments();
_registrar = value;
......@@ -221,8 +224,9 @@ class RenderParagraph extends RenderBox
while (start < plainText.length) {
int end = plainText.indexOf(_placeholderCharacter, start);
if (start != end) {
if (end == -1)
if (end == -1) {
end = plainText.length;
}
result.add(_SelectableFragment(paragraph: this, range: TextRange(start: start, end: end)));
start = end;
}
......@@ -232,8 +236,9 @@ class RenderParagraph extends RenderBox
}
void _disposeSelectableFragments() {
if (_lastSelectableFragments == null)
if (_lastSelectableFragments == null) {
return;
}
for (final _SelectableFragment fragment in _lastSelectableFragments!) {
fragment.dispose();
}
......@@ -270,8 +275,9 @@ class RenderParagraph extends RenderBox
TextAlign get textAlign => _textPainter.textAlign;
set textAlign(TextAlign value) {
assert(value != null);
if (_textPainter.textAlign == value)
if (_textPainter.textAlign == value) {
return;
}
_textPainter.textAlign = value;
markNeedsPaint();
}
......@@ -292,8 +298,9 @@ class RenderParagraph extends RenderBox
TextDirection get textDirection => _textPainter.textDirection!;
set textDirection(TextDirection value) {
assert(value != null);
if (_textPainter.textDirection == value)
if (_textPainter.textDirection == value) {
return;
}
_textPainter.textDirection = value;
markNeedsLayout();
}
......@@ -309,8 +316,9 @@ class RenderParagraph extends RenderBox
bool _softWrap;
set softWrap(bool value) {
assert(value != null);
if (_softWrap == value)
if (_softWrap == value) {
return;
}
_softWrap = value;
markNeedsLayout();
}
......@@ -320,8 +328,9 @@ class RenderParagraph extends RenderBox
TextOverflow _overflow;
set overflow(TextOverflow value) {
assert(value != null);
if (_overflow == value)
if (_overflow == value) {
return;
}
_overflow = value;
_textPainter.ellipsis = value == TextOverflow.ellipsis ? _kEllipsis : null;
markNeedsLayout();
......@@ -334,8 +343,9 @@ class RenderParagraph extends RenderBox
double get textScaleFactor => _textPainter.textScaleFactor;
set textScaleFactor(double value) {
assert(value != null);
if (_textPainter.textScaleFactor == value)
if (_textPainter.textScaleFactor == value) {
return;
}
_textPainter.textScaleFactor = value;
_overflowShader = null;
markNeedsLayout();
......@@ -349,8 +359,9 @@ class RenderParagraph extends RenderBox
/// zero.
set maxLines(int? value) {
assert(value == null || value > 0);
if (_textPainter.maxLines == value)
if (_textPainter.maxLines == value) {
return;
}
_textPainter.maxLines = value;
_overflowShader = null;
markNeedsLayout();
......@@ -366,8 +377,9 @@ class RenderParagraph extends RenderBox
Locale? get locale => _textPainter.locale;
/// The value may be null.
set locale(Locale? value) {
if (_textPainter.locale == value)
if (_textPainter.locale == value) {
return;
}
_textPainter.locale = value;
_overflowShader = null;
markNeedsLayout();
......@@ -377,8 +389,9 @@ class RenderParagraph extends RenderBox
StrutStyle? get strutStyle => _textPainter.strutStyle;
/// The value may be null.
set strutStyle(StrutStyle? value) {
if (_textPainter.strutStyle == value)
if (_textPainter.strutStyle == value) {
return;
}
_textPainter.strutStyle = value;
_overflowShader = null;
markNeedsLayout();
......@@ -388,8 +401,9 @@ class RenderParagraph extends RenderBox
TextWidthBasis get textWidthBasis => _textPainter.textWidthBasis;
set textWidthBasis(TextWidthBasis value) {
assert(value != null);
if (_textPainter.textWidthBasis == value)
if (_textPainter.textWidthBasis == value) {
return;
}
_textPainter.textWidthBasis = value;
_overflowShader = null;
markNeedsLayout();
......@@ -398,8 +412,9 @@ class RenderParagraph extends RenderBox
/// {@macro dart.ui.textHeightBehavior}
ui.TextHeightBehavior? get textHeightBehavior => _textPainter.textHeightBehavior;
set textHeightBehavior(ui.TextHeightBehavior? value) {
if (_textPainter.textHeightBehavior == value)
if (_textPainter.textHeightBehavior == value) {
return;
}
_textPainter.textHeightBehavior = value;
_overflowShader = null;
markNeedsLayout();
......@@ -409,8 +424,9 @@ class RenderParagraph extends RenderBox
Color? get selectionColor => _selectionColor;
Color? _selectionColor;
set selectionColor(Color? value) {
if (_selectionColor == value)
if (_selectionColor == value) {
return;
}
_selectionColor = value;
if (_lastSelectableFragments?.any((_SelectableFragment fragment) => fragment.value.hasSelection) ?? false) {
markNeedsPaint();
......@@ -1247,8 +1263,9 @@ class _SelectableFragment with Selectable, ChangeNotifier {
late SelectionGeometry _selectionGeometry;
void _updateSelectionGeometry() {
final SelectionGeometry newValue = _getSelectionGeometry();
if (_selectionGeometry == newValue)
if (_selectionGeometry == newValue) {
return;
}
_selectionGeometry = newValue;
notifyListeners();
}
......@@ -1377,11 +1394,12 @@ class _SelectableFragment with Selectable, ChangeNotifier {
}
void _setSelectionPosition(TextPosition? position, {required bool isEnd}) {
if (isEnd)
if (isEnd) {
_textSelectionEnd = position;
else
} else {
_textSelectionStart = position;
}
}
SelectionResult _handleClearSelection() {
_textSelectionStart = null;
......@@ -1423,8 +1441,9 @@ class _SelectableFragment with Selectable, ChangeNotifier {
///
/// The parameter `start` must be smaller than `end`.
bool _positionIsWithinCurrentSelection(TextPosition position) {
if (_textSelectionStart == null || _textSelectionEnd == null)
if (_textSelectionStart == null || _textSelectionEnd == null) {
return false;
}
// Normalize current selection.
late TextPosition currentStart;
late TextPosition currentEnd;
......@@ -1509,8 +1528,9 @@ class _SelectableFragment with Selectable, ChangeNotifier {
}
void paint(PaintingContext context, Offset offset) {
if (_textSelectionStart == null || _textSelectionEnd == null)
if (_textSelectionStart == null || _textSelectionEnd == null) {
return;
}
if (paragraph.selectionColor != null) {
final TextSelection selection = TextSelection(
baseOffset: _textSelectionStart!.offset,
......
......@@ -82,8 +82,9 @@ class RenderPerformanceOverlay extends RenderBox {
int _optionsMask;
set optionsMask(int value) {
assert(value != null);
if (value == _optionsMask)
if (value == _optionsMask) {
return;
}
_optionsMask = value;
markNeedsPaint();
}
......@@ -95,8 +96,9 @@ class RenderPerformanceOverlay extends RenderBox {
int _rasterizerThreshold;
set rasterizerThreshold(int value) {
assert(value != null);
if (value == _rasterizerThreshold)
if (value == _rasterizerThreshold) {
return;
}
_rasterizerThreshold = value;
markNeedsPaint();
}
......@@ -106,8 +108,9 @@ class RenderPerformanceOverlay extends RenderBox {
bool _checkerboardRasterCacheImages;
set checkerboardRasterCacheImages(bool value) {
assert(value != null);
if (value == _checkerboardRasterCacheImages)
if (value == _checkerboardRasterCacheImages) {
return;
}
_checkerboardRasterCacheImages = value;
markNeedsPaint();
}
......@@ -117,8 +120,9 @@ class RenderPerformanceOverlay extends RenderBox {
bool _checkerboardOffscreenLayers;
set checkerboardOffscreenLayers(bool value) {
assert(value != null);
if (value == _checkerboardOffscreenLayers)
if (value == _checkerboardOffscreenLayers) {
return;
}
_checkerboardOffscreenLayers = value;
markNeedsPaint();
}
......@@ -143,11 +147,13 @@ class RenderPerformanceOverlay extends RenderBox {
const double kDefaultGraphHeight = 80.0;
double result = 0.0;
if ((optionsMask | (1 << PerformanceOverlayOption.displayRasterizerStatistics.index) > 0) ||
(optionsMask | (1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index) > 0))
(optionsMask | (1 << PerformanceOverlayOption.visualizeRasterizerStatistics.index) > 0)) {
result += kDefaultGraphHeight;
}
if ((optionsMask | (1 << PerformanceOverlayOption.displayEngineStatistics.index) > 0) ||
(optionsMask | (1 << PerformanceOverlayOption.visualizeEngineStatistics.index) > 0))
(optionsMask | (1 << PerformanceOverlayOption.visualizeEngineStatistics.index) > 0)) {
result += kDefaultGraphHeight;
}
return result;
}
......
......@@ -111,8 +111,9 @@ class RenderAndroidView extends PlatformViewRenderBox {
set controller(AndroidViewController controller) {
assert(_viewController != null);
assert(controller != null);
if (_viewController == controller)
if (_viewController == controller) {
return;
}
_viewController.removeOnPlatformViewCreatedListener(_onPlatformViewCreated);
super.controller = controller;
_viewController = controller;
......@@ -166,8 +167,9 @@ class RenderAndroidView extends PlatformViewRenderBox {
// Android virtual displays cannot have a zero size.
// Trying to size it to 0 crashes the app, which was happening when starting the app
// with a locked screen (see: https://github.com/flutter/flutter/issues/20456).
if (_state == _PlatformViewState.resizing || size.isEmpty)
if (_state == _PlatformViewState.resizing || size.isEmpty) {
return;
}
_state = _PlatformViewState.resizing;
markNeedsPaint();
......@@ -200,8 +202,9 @@ class RenderAndroidView extends PlatformViewRenderBox {
void _setOffset() {
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (!_isDisposed) {
if (attached)
if (attached) {
await _viewController.setOffset(localToGlobal(Offset.zero));
}
// Schedule a new post frame callback.
_setOffset();
}
......@@ -210,8 +213,9 @@ class RenderAndroidView extends PlatformViewRenderBox {
@override
void paint(PaintingContext context, Offset offset) {
if (_viewController.textureId == null || _currentTextureSize == null)
if (_viewController.textureId == null || _currentTextureSize == null) {
return;
}
// As resizing the Android view happens asynchronously we don't know exactly when is a
// texture frame with the new size is ready for consumption.
......@@ -248,8 +252,9 @@ class RenderAndroidView extends PlatformViewRenderBox {
}
void _paintTexture(PaintingContext context, Offset offset) {
if (_currentTextureSize == null)
if (_currentTextureSize == null) {
return;
}
context.addLayer(TextureLayer(
rect: offset & _currentTextureSize!,
......@@ -372,8 +377,9 @@ class RenderUiKitView extends RenderBox {
@override
bool hitTest(BoxHitTestResult result, { Offset? position }) {
if (hitTestBehavior == PlatformViewHitTestBehavior.transparent || !size.contains(position!))
if (hitTestBehavior == PlatformViewHitTestBehavior.transparent || !size.contains(position!)) {
return false;
}
result.add(BoxHitTestEntry(this, position));
return hitTestBehavior == PlatformViewHitTestBehavior.opaque;
}
......@@ -716,10 +722,11 @@ mixin _PlatformViewGestureMixin on RenderBox implements MouseTrackerAnnotation {
set hitTestBehavior(PlatformViewHitTestBehavior value) {
if (value != _hitTestBehavior) {
_hitTestBehavior = value;
if (owner != null)
if (owner != null) {
markNeedsPaint();
}
}
}
PlatformViewHitTestBehavior? _hitTestBehavior;
_HandlePointerEvent? _handlePointerEvent;
......
......@@ -42,9 +42,10 @@ abstract class RenderProxySliver extends RenderSliver with RenderObjectWithChild
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SliverPhysicalParentData)
if (child.parentData is! SliverPhysicalParentData) {
child.parentData = SliverPhysicalParentData();
}
}
@override
void performLayout() {
......@@ -55,9 +56,10 @@ abstract class RenderProxySliver extends RenderSliver with RenderObjectWithChild
@override
void paint(PaintingContext context, Offset offset) {
if (child != null)
if (child != null) {
context.paintChild(child!, offset);
}
}
@override
bool hitTestChildren(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) {
......@@ -131,18 +133,21 @@ class RenderSliverOpacity extends RenderProxySliver {
set opacity(double value) {
assert(value != null);
assert(value >= 0.0 && value <= 1.0);
if (_opacity == value)
if (_opacity == value) {
return;
}
final bool didNeedCompositing = alwaysNeedsCompositing;
final bool wasVisible = _alpha != 0;
_opacity = value;
_alpha = ui.Color.getAlphaFromOpacity(_opacity);
if (didNeedCompositing != alwaysNeedsCompositing)
if (didNeedCompositing != alwaysNeedsCompositing) {
markNeedsCompositingBitsUpdate();
}
markNeedsPaint();
if (wasVisible != (_alpha != 0) && !alwaysIncludeSemantics)
if (wasVisible != (_alpha != 0) && !alwaysIncludeSemantics) {
markNeedsSemanticsUpdate();
}
}
/// Whether child semantics are included regardless of the opacity.
///
......@@ -152,8 +157,9 @@ class RenderSliverOpacity extends RenderProxySliver {
bool get alwaysIncludeSemantics => _alwaysIncludeSemantics;
bool _alwaysIncludeSemantics;
set alwaysIncludeSemantics(bool value) {
if (value == _alwaysIncludeSemantics)
if (value == _alwaysIncludeSemantics) {
return;
}
_alwaysIncludeSemantics = value;
markNeedsSemanticsUpdate();
}
......@@ -182,9 +188,10 @@ class RenderSliverOpacity extends RenderProxySliver {
@override
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
if (child != null && (_alpha != 0 || alwaysIncludeSemantics))
if (child != null && (_alpha != 0 || alwaysIncludeSemantics)) {
visitor(child!);
}
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
......@@ -227,12 +234,14 @@ class RenderSliverIgnorePointer extends RenderProxySliver {
bool _ignoring;
set ignoring(bool value) {
assert(value != null);
if (value == _ignoring)
if (value == _ignoring) {
return;
}
_ignoring = value;
if (_ignoringSemantics == null || !_ignoringSemantics!)
if (_ignoringSemantics == null || !_ignoringSemantics!) {
markNeedsSemanticsUpdate();
}
}
/// Whether the semantics of this render object is ignored when compiling the
/// semantics tree.
......@@ -243,13 +252,15 @@ class RenderSliverIgnorePointer extends RenderProxySliver {
bool? get ignoringSemantics => _ignoringSemantics;
bool? _ignoringSemantics;
set ignoringSemantics(bool? value) {
if (value == _ignoringSemantics)
if (value == _ignoringSemantics) {
return;
}
final bool oldEffectiveValue = _effectiveIgnoringSemantics;
_ignoringSemantics = value;
if (oldEffectiveValue != _effectiveIgnoringSemantics)
if (oldEffectiveValue != _effectiveIgnoringSemantics) {
markNeedsSemanticsUpdate();
}
}
bool get _effectiveIgnoringSemantics => ignoringSemantics ?? ignoring;
......@@ -265,9 +276,10 @@ class RenderSliverIgnorePointer extends RenderProxySliver {
@override
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
if (child != null && !_effectiveIgnoringSemantics)
if (child != null && !_effectiveIgnoringSemantics) {
visitor(child!);
}
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
......@@ -302,8 +314,9 @@ class RenderSliverOffstage extends RenderProxySliver {
set offstage(bool value) {
assert(value != null);
if (value == _offstage)
if (value == _offstage) {
return;
}
_offstage = value;
markNeedsLayoutForSizedByParentChange();
}
......@@ -312,11 +325,12 @@ class RenderSliverOffstage extends RenderProxySliver {
void performLayout() {
assert(child != null);
child!.layout(constraints, parentUsesSize: true);
if (!offstage)
if (!offstage) {
geometry = child!.geometry;
else
} else {
geometry = SliverGeometry.zero;
}
}
@override
bool hitTest(SliverHitTestResult result, {required double mainAxisPosition, required double crossAxisPosition}) {
......@@ -341,15 +355,17 @@ class RenderSliverOffstage extends RenderProxySliver {
@override
void paint(PaintingContext context, Offset offset) {
if (offstage)
if (offstage) {
return;
}
context.paintChild(child!, offset);
}
@override
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
if (offstage)
if (offstage) {
return;
}
super.visitChildrenForSemantics(visitor);
}
......@@ -361,8 +377,9 @@ class RenderSliverOffstage extends RenderProxySliver {
@override
List<DiagnosticsNode> debugDescribeChildren() {
if (child == null)
if (child == null) {
return <DiagnosticsNode>[];
}
return <DiagnosticsNode>[
child!.toDiagnosticsNode(
name: 'child',
......
......@@ -34,8 +34,9 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
int _quarterTurns;
set quarterTurns(int value) {
assert(value != null);
if (_quarterTurns == value)
if (_quarterTurns == value) {
return;
}
_quarterTurns = value;
markNeedsLayout();
}
......@@ -44,29 +45,33 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
@override
double computeMinIntrinsicWidth(double height) {
if (child == null)
if (child == null) {
return 0.0;
}
return _isVertical ? child!.getMinIntrinsicHeight(height) : child!.getMinIntrinsicWidth(height);
}
@override
double computeMaxIntrinsicWidth(double height) {
if (child == null)
if (child == null) {
return 0.0;
}
return _isVertical ? child!.getMaxIntrinsicHeight(height) : child!.getMaxIntrinsicWidth(height);
}
@override
double computeMinIntrinsicHeight(double width) {
if (child == null)
if (child == null) {
return 0.0;
}
return _isVertical ? child!.getMinIntrinsicWidth(width) : child!.getMinIntrinsicHeight(width);
}
@override
double computeMaxIntrinsicHeight(double width) {
if (child == null)
if (child == null) {
return 0.0;
}
return _isVertical ? child!.getMaxIntrinsicWidth(width) : child!.getMaxIntrinsicHeight(width);
}
......@@ -99,8 +104,9 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
@override
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
assert(_paintTransform != null || debugNeedsLayout || child == null);
if (child == null || _paintTransform == null)
if (child == null || _paintTransform == null) {
return false;
}
return result.addWithPaintTransform(
transform: _paintTransform,
position: position,
......@@ -139,8 +145,9 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
if (_paintTransform != null)
if (_paintTransform != null) {
transform.multiply(_paintTransform!);
}
super.applyPaintTransform(child, transform);
}
}
......@@ -161,8 +161,9 @@ mixin SelectionRegistrant on Selectable {
SelectionRegistrar? get registrar => _registrar;
SelectionRegistrar? _registrar;
set registrar(SelectionRegistrar? value) {
if (value == _registrar)
if (value == _registrar) {
return;
}
if (value == null) {
// When registrar goes from non-null to null;
removeListener(_updateSelectionRegistrarSubscription);
......@@ -219,10 +220,12 @@ class SelectionUtils {
if (targetRect.contains(point)) {
return SelectionResult.end;
}
if (point.dy < targetRect.top)
if (point.dy < targetRect.top) {
return SelectionResult.previous;
if (point.dy > targetRect.bottom)
}
if (point.dy > targetRect.bottom) {
return SelectionResult.next;
}
return point.dx >= targetRect.right
? SelectionResult.next
: SelectionResult.previous;
......@@ -505,10 +508,12 @@ class SelectionGeometry {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
if (other.runtimeType != runtimeType)
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is SelectionGeometry
&& other.startSelectionPoint == startSelectionPoint
&& other.endSelectionPoint == endSelectionPoint
......@@ -555,10 +560,12 @@ class SelectionPoint {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
if (other.runtimeType != runtimeType)
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is SelectionPoint
&& other.localPosition == localPosition
&& other.lineHeight == lineHeight
......
......@@ -411,8 +411,9 @@ class SliverConstraints extends Constraints {
bool hasErrors = false;
final StringBuffer errorMessage = StringBuffer('\n');
void verify(bool check, String message) {
if (check)
if (check) {
return;
}
hasErrors = true;
errorMessage.writeln(' $message');
}
......@@ -461,10 +462,12 @@ class SliverConstraints extends Constraints {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
if (other is! SliverConstraints)
}
if (other is! SliverConstraints) {
return false;
}
assert(other.debugAssertIsValid());
return other.axisDirection == axisDirection
&& other.growthDirection == growthDirection
......@@ -704,8 +707,9 @@ class SliverGeometry with Diagnosticable {
}) {
assert(() {
void verify(bool check, String summary, {List<DiagnosticsNode>? details}) {
if (check)
if (check) {
return;
}
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('${objectRuntimeType(this, 'SliverGeometry')} is not valid: $summary'),
...?details,
......@@ -1140,8 +1144,9 @@ abstract class RenderSliver extends RenderObject {
assert(sizedByParent || !debugDoingThisResize);
assert(() {
if ((sizedByParent && debugDoingThisResize) ||
(!sizedByParent && debugDoingThisLayout))
(!sizedByParent && debugDoingThisLayout)) {
return true;
}
assert(!debugDoingThisResize);
DiagnosticsNode? contract, violation, hint;
if (debugDoingThisLayout) {
......@@ -1149,13 +1154,15 @@ abstract class RenderSliver extends RenderObject {
violation = ErrorDescription('It appears that the geometry setter was called from performLayout().');
} else {
violation = ErrorDescription('The geometry setter was called from outside layout (neither performResize() nor performLayout() were being run for this object).');
if (owner != null && owner!.debugDoingLayout)
if (owner != null && owner!.debugDoingLayout) {
hint = ErrorDescription('Only the object itself can set its geometry. It is a contract violation for other objects to set it.');
}
if (sizedByParent)
}
if (sizedByParent) {
contract = ErrorDescription('Because this RenderSliver has sizedByParent set to true, it must set its geometry in performResize().');
else
} else {
contract = ErrorDescription('Because this RenderSliver has sizedByParent set to false, it must set its geometry in performLayout().');
}
final List<DiagnosticsNode> information = <DiagnosticsNode>[
ErrorSummary('RenderSliver geometry setter called incorrectly.'),
......@@ -1476,8 +1483,9 @@ abstract class RenderSliver extends RenderObject {
void _debugDrawArrow(Canvas canvas, Paint paint, Offset p0, Offset p1, GrowthDirection direction) {
assert(() {
if (p0 == p1)
if (p0 == p1) {
return true;
}
assert(p0.dx == p1.dx || p0.dy == p1.dy); // must be axis-aligned
final double d = (p1 - p0).distance * 0.2;
final Offset temp;
......@@ -1680,13 +1688,15 @@ mixin RenderSliverHelpers implements RenderSliver {
assert(constraints.axis != null);
switch (constraints.axis) {
case Axis.horizontal:
if (!rightWayUp)
if (!rightWayUp) {
delta = geometry!.paintExtent - child.size.width - delta;
}
transform.translate(delta, crossAxisDelta);
break;
case Axis.vertical:
if (!rightWayUp)
if (!rightWayUp) {
delta = geometry!.paintExtent - child.size.height - delta;
}
transform.translate(crossAxisDelta, delta);
break;
}
......@@ -1716,9 +1726,10 @@ abstract class RenderSliverSingleBoxAdapter extends RenderSliver with RenderObje
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SliverPhysicalParentData)
if (child.parentData is! SliverPhysicalParentData) {
child.parentData = SliverPhysicalParentData();
}
}
/// Sets the [SliverPhysicalParentData.paintOffset] for the given child
/// according to the [SliverConstraints.axisDirection] and
......@@ -1748,8 +1759,9 @@ abstract class RenderSliverSingleBoxAdapter extends RenderSliver with RenderObje
@override
bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) {
assert(geometry!.hitTestExtent > 0.0);
if (child != null)
if (child != null) {
return hitTestBoxChild(BoxHitTestResult.wrap(result), child!, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition);
}
return false;
}
......
......@@ -48,8 +48,9 @@ class RenderSliverFillViewport extends RenderSliverFixedExtentBoxAdaptor {
double _viewportFraction;
set viewportFraction(double value) {
assert(value != null);
if (_viewportFraction == value)
if (_viewportFraction == value) {
return;
}
_viewportFraction = value;
markNeedsLayout();
}
......@@ -86,11 +87,12 @@ class RenderSliverFillRemainingWithScrollable extends RenderSliverSingleBoxAdapt
final SliverConstraints constraints = this.constraints;
final double extent = constraints.remainingPaintExtent - math.min(constraints.overlap, 0.0);
if (child != null)
if (child != null) {
child!.layout(constraints.asBoxConstraints(
minExtent: extent,
maxExtent: extent,
));
}
final double paintedChildSize = calculatePaintOffset(constraints, from: 0.0, to: extent);
assert(paintedChildSize.isFinite);
......@@ -101,9 +103,10 @@ class RenderSliverFillRemainingWithScrollable extends RenderSliverSingleBoxAdapt
maxPaintExtent: paintedChildSize,
hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0,
);
if (child != null)
if (child != null) {
setChildParentData(child!, constraints, geometry!);
}
}
}
/// A sliver that contains a single box child that is non-scrollable and fills
......@@ -174,9 +177,10 @@ class RenderSliverFillRemaining extends RenderSliverSingleBoxAdapter {
maxPaintExtent: paintedChildSize,
hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0,
);
if (child != null)
if (child != null) {
setChildParentData(child!, constraints, geometry!);
}
}
}
/// A sliver that contains a single box child that is non-scrollable and fills
......@@ -251,7 +255,8 @@ class RenderSliverFillRemainingAndOverscroll extends RenderSliverSingleBoxAdapte
maxPaintExtent: maxExtent,
hasVisualOverflow: extent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0,
);
if (child != null)
if (child != null) {
setChildParentData(child!, constraints, geometry!);
}
}
}
......@@ -310,8 +310,9 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda
// We may have started the layout while scrolled to the end, which would not
// expose a new child.
if (estimatedMaxScrollOffset == trailingScrollOffset)
if (estimatedMaxScrollOffset == trailingScrollOffset) {
childManager.setDidUnderflow(true);
}
childManager.didFinishLayout();
}
}
......@@ -351,8 +352,9 @@ class RenderSliverFixedExtentList extends RenderSliverFixedExtentBoxAdaptor {
double _itemExtent;
set itemExtent(double value) {
assert(value != null);
if (_itemExtent == value)
if (_itemExtent == value) {
return;
}
_itemExtent = value;
markNeedsLayout();
}
......
......@@ -207,8 +207,9 @@ class SliverGridRegularTileLayout extends SliverGridLayout {
}
double _getOffsetFromStartInCrossAxis(double crossAxisStart) {
if (reverseCrossAxis)
if (reverseCrossAxis) {
return crossAxisCount * crossAxisStride - crossAxisStart - childCrossAxisExtent - (crossAxisStride - childCrossAxisExtent);
}
return crossAxisStart;
}
......@@ -526,20 +527,23 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SliverGridParentData)
if (child.parentData is! SliverGridParentData) {
child.parentData = SliverGridParentData();
}
}
/// The delegate that controls the size and position of the children.
SliverGridDelegate get gridDelegate => _gridDelegate;
SliverGridDelegate _gridDelegate;
set gridDelegate(SliverGridDelegate value) {
assert(value != null);
if (_gridDelegate == value)
if (_gridDelegate == value) {
return;
}
if (value.runtimeType != _gridDelegate.runtimeType ||
value.shouldRelayout(_gridDelegate))
value.shouldRelayout(_gridDelegate)) {
markNeedsLayout();
}
_gridDelegate = value;
}
......@@ -677,8 +681,9 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
// We may have started the layout while scrolled to the end, which
// would not expose a new child.
if (estimatedTotalExtent == trailingScrollOffset)
if (estimatedTotalExtent == trailingScrollOffset) {
childManager.setDidUnderflow(true);
}
childManager.didFinishLayout();
}
}
......@@ -227,11 +227,13 @@ class RenderSliverList extends RenderSliverMultiBoxAdaptor {
bool advance() { // returns true if we advanced, false if we have no more children
// This function is used in two different places below, to avoid code duplication.
assert(child != null);
if (child == trailingChildWithLayout)
if (child == trailingChildWithLayout) {
inLayoutRange = false;
}
child = childAfter(child!);
if (child == null)
if (child == null) {
inLayoutRange = false;
}
index += 1;
if (!inLayoutRange) {
if (child == null || indexOf(child!) != index) {
......@@ -334,8 +336,9 @@ class RenderSliverList extends RenderSliverMultiBoxAdaptor {
// We may have started the layout while scrolled to the end, which would not
// expose a new child.
if (estimatedMaxScrollOffset == endScrollOffset)
if (estimatedMaxScrollOffset == endScrollOffset) {
childManager.setDidUnderflow(true);
}
childManager.didFinishLayout();
}
}
......@@ -198,9 +198,10 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SliverMultiBoxAdaptorParentData)
if (child.parentData is! SliverMultiBoxAdaptorParentData) {
child.parentData = SliverMultiBoxAdaptorParentData();
}
}
/// The delegate that manages the children of this object.
///
......@@ -240,9 +241,10 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
void adoptChild(RenderObject child) {
super.adoptChild(child);
final SliverMultiBoxAdaptorParentData childParentData = child.parentData! as SliverMultiBoxAdaptorParentData;
if (!childParentData._keptAlive)
if (!childParentData._keptAlive) {
childManager.didAdoptChild(child as RenderBox);
}
}
bool _debugAssertChildListLocked() => childManager.debugAssertChildListLocked();
......@@ -304,8 +306,9 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
// be moved to other index. In other cases, the existing child should have been
// removed by updateChild. Thus, it is ok to overwrite it.
assert(() {
if (_keepAliveBucket.containsKey(childParentData.index))
if (_keepAliveBucket.containsKey(childParentData.index)) {
_debugDanglingKeepAlives.add(_keepAliveBucket[childParentData.index]!);
}
return true;
}());
_keepAliveBucket[childParentData.index!] = child;
......@@ -371,16 +374,18 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
@override
void attach(PipelineOwner owner) {
super.attach(owner);
for (final RenderBox child in _keepAliveBucket.values)
for (final RenderBox child in _keepAliveBucket.values) {
child.attach(owner);
}
}
@override
void detach() {
super.detach();
for (final RenderBox child in _keepAliveBucket.values)
for (final RenderBox child in _keepAliveBucket.values) {
child.detach();
}
}
@override
void redepthChildren() {
......@@ -556,8 +561,9 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
RenderBox? child = lastChild;
final BoxHitTestResult boxResult = BoxHitTestResult.wrap(result);
while (child != null) {
if (hitTestBoxChild(boxResult, child, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition))
if (hitTestBoxChild(boxResult, child, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition)) {
return true;
}
child = childBefore(child);
}
return false;
......@@ -601,8 +607,9 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
@override
void paint(PaintingContext context, Offset offset) {
if (firstChild == null)
if (firstChild == null) {
return;
}
// offset is to the top-left corner, regardless of our axis direction.
// originOffset gives us the delta from the real origin to the origin in the axis direction.
final Offset mainAxisUnit, crossAxisUnit, originOffset;
......@@ -643,13 +650,15 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
originOffset.dx + mainAxisUnit.dx * mainAxisDelta + crossAxisUnit.dx * crossAxisDelta,
originOffset.dy + mainAxisUnit.dy * mainAxisDelta + crossAxisUnit.dy * crossAxisDelta,
);
if (addExtent)
if (addExtent) {
childOffset += mainAxisUnit * paintExtentOf(child);
}
// If the child's visible interval (mainAxisDelta, mainAxisDelta + paintExtentOf(child))
// does not intersect the paint extent interval (0, constraints.remainingPaintExtent), it's hidden.
if (mainAxisDelta < constraints.remainingPaintExtent && mainAxisDelta + paintExtentOf(child) > 0)
if (mainAxisDelta < constraints.remainingPaintExtent && mainAxisDelta + paintExtentOf(child) > 0) {
context.paintChild(child, childOffset);
}
child = childAfter(child);
}
......@@ -688,8 +697,9 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
while (true) {
final SliverMultiBoxAdaptorParentData childParentData = child!.parentData! as SliverMultiBoxAdaptorParentData;
children.add(child.toDiagnosticsNode(name: 'child with index ${childParentData.index}'));
if (child == lastChild)
if (child == lastChild) {
break;
}
child = childParentData.nextSibling;
}
}
......
......@@ -105,9 +105,10 @@ abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObj
@override
void setupParentData(RenderObject child) {
if (child.parentData is! SliverPhysicalParentData)
if (child.parentData is! SliverPhysicalParentData) {
child.parentData = SliverPhysicalParentData();
}
}
@override
void performLayout() {
......@@ -326,8 +327,9 @@ class RenderSliverPadding extends RenderSliverEdgeInsetsPadding {
EdgeInsets? _resolvedPadding;
void _resolve() {
if (resolvedPadding != null)
if (resolvedPadding != null) {
return;
}
_resolvedPadding = padding.resolve(textDirection);
assert(resolvedPadding!.isNonNegative);
}
......@@ -346,8 +348,9 @@ class RenderSliverPadding extends RenderSliverEdgeInsetsPadding {
set padding(EdgeInsetsGeometry value) {
assert(value != null);
assert(padding.isNonNegative);
if (_padding == value)
if (_padding == value) {
return;
}
_padding = value;
_markNeedsResolution();
}
......@@ -359,8 +362,9 @@ class RenderSliverPadding extends RenderSliverEdgeInsetsPadding {
TextDirection? get textDirection => _textDirection;
TextDirection? _textDirection;
set textDirection(TextDirection? value) {
if (_textDirection == value)
if (_textDirection == value) {
return;
}
_textDirection = value;
_markNeedsResolution();
}
......
......@@ -149,8 +149,9 @@ abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObje
/// The dimension of the child in the main axis.
@protected
double get childExtent {
if (child == null)
if (child == null) {
return 0.0;
}
assert(child!.hasSize);
assert(constraints.axis != null);
switch (constraints.axis) {
......@@ -230,8 +231,9 @@ abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObje
}
assert(minExtent != null);
assert(() {
if (minExtent <= maxExtent)
if (minExtent <= maxExtent) {
return true;
}
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The maxExtent for this $runtimeType is less than its minExtent.'),
DoubleProperty('The specified maxExtent was', maxExtent),
......@@ -285,8 +287,9 @@ abstract class RenderSliverPersistentHeader extends RenderSliver with RenderObje
@override
bool hitTestChildren(SliverHitTestResult result, { required double mainAxisPosition, required double crossAxisPosition }) {
assert(geometry!.hitTestExtent > 0.0);
if (child != null)
if (child != null) {
return hitTestBoxChild(BoxHitTestResult.wrap(result), child!, mainAxisPosition: mainAxisPosition, crossAxisPosition: crossAxisPosition);
}
return false;
}
......@@ -549,8 +552,9 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
TickerProvider? get vsync => _vsync;
TickerProvider? _vsync;
set vsync(TickerProvider? value) {
if (value == _vsync)
if (value == _vsync) {
return;
}
_vsync = value;
if (value == null) {
_controller?.dispose();
......@@ -615,8 +619,9 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
final AnimationController effectiveController =
_controller ??= AnimationController(vsync: vsync!, duration: duration)
..addListener(() {
if (_effectiveScrollOffset == _animation.value)
if (_effectiveScrollOffset == _animation.value) {
return;
}
_effectiveScrollOffset = _animation.value;
markNeedsLayout();
});
......@@ -638,12 +643,15 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
/// If the header isn't already fully exposed, then scroll it into view.
void maybeStartSnapAnimation(ScrollDirection direction) {
final FloatingHeaderSnapConfiguration? snap = snapConfiguration;
if (snap == null)
if (snap == null) {
return;
if (direction == ScrollDirection.forward && _effectiveScrollOffset! <= 0.0)
}
if (direction == ScrollDirection.forward && _effectiveScrollOffset! <= 0.0) {
return;
if (direction == ScrollDirection.reverse && _effectiveScrollOffset! >= maxExtent)
}
if (direction == ScrollDirection.reverse && _effectiveScrollOffset! >= maxExtent) {
return;
}
_updateAnimation(
snap.duration,
......@@ -671,11 +679,15 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
final bool allowFloatingExpansion = constraints.userScrollDirection == ScrollDirection.forward
|| (_lastStartedScrollDirection != null && _lastStartedScrollDirection == ScrollDirection.forward);
if (allowFloatingExpansion) {
if (_effectiveScrollOffset! > maxExtent) // We're scrolled off-screen, but should reveal, so
_effectiveScrollOffset = maxExtent; // pretend we're just at the limit.
if (_effectiveScrollOffset! > maxExtent) {
// We're scrolled off-screen, but should reveal, so pretend we're just at the limit.
_effectiveScrollOffset = maxExtent;
}
} else {
if (delta > 0.0) // If we are trying to expand when allowFloatingExpansion is false,
delta = 0.0; // disallow the expansion. (But allow shrinking, i.e. delta < 0.0 is fine.)
if (delta > 0.0) {
// Disallow the expansion. (But allow shrinking, i.e. delta < 0.0 is fine.)
delta = 0.0;
}
}
_effectiveScrollOffset = clampDouble(_effectiveScrollOffset! - delta, 0.0, constraints.scrollOffset);
} else {
......@@ -700,8 +712,9 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste
Curve curve = Curves.ease,
}) {
final PersistentHeaderShowOnScreenConfiguration? showOnScreen = showOnScreenConfiguration;
if (showOnScreen == null)
if (showOnScreen == null) {
return super.showOnScreen(descendant: descendant, rect: rect, duration: duration, curve: curve);
}
assert(child != null || descendant == null);
// We prefer the child's coordinate space (instead of the sliver's) because
......
......@@ -136,10 +136,12 @@ class RelativeRect {
/// {@macro dart.ui.shadow.lerp}
static RelativeRect? lerp(RelativeRect? a, RelativeRect? b, double t) {
assert(t != null);
if (a == null && b == null)
if (a == null && b == null) {
return null;
if (a == null)
}
if (a == null) {
return RelativeRect.fromLTRB(b!.left * t, b.top * t, b.right * t, b.bottom * t);
}
if (b == null) {
final double k = 1.0 - t;
return RelativeRect.fromLTRB(b!.left * k, b.top * k, b.right * k, b.bottom * k);
......@@ -154,8 +156,9 @@ class RelativeRect {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
}
return other is RelativeRect
&& other.left == left
&& other.top == top
......@@ -221,8 +224,9 @@ class StackParentData extends ContainerBoxParentData<RenderBox> {
if (width != null) 'width=${debugFormatDouble(width)}',
if (height != null) 'height=${debugFormatDouble(height)}',
];
if (values.isEmpty)
if (values.isEmpty) {
values.add('not positioned');
}
values.add(super.toString());
return values.join('; ');
}
......@@ -333,15 +337,17 @@ class RenderStack extends RenderBox
@override
void setupParentData(RenderBox child) {
if (child.parentData is! StackParentData)
if (child.parentData is! StackParentData) {
child.parentData = StackParentData();
}
}
Alignment? _resolvedAlignment;
void _resolve() {
if (_resolvedAlignment != null)
if (_resolvedAlignment != null) {
return;
}
_resolvedAlignment = alignment.resolve(textDirection);
}
......@@ -369,8 +375,9 @@ class RenderStack extends RenderBox
AlignmentGeometry _alignment;
set alignment(AlignmentGeometry value) {
assert(value != null);
if (_alignment == value)
if (_alignment == value) {
return;
}
_alignment = value;
_markNeedResolution();
}
......@@ -382,8 +389,9 @@ class RenderStack extends RenderBox
TextDirection? get textDirection => _textDirection;
TextDirection? _textDirection;
set textDirection(TextDirection? value) {
if (_textDirection == value)
if (_textDirection == value) {
return;
}
_textDirection = value;
_markNeedResolution();
}
......@@ -423,8 +431,9 @@ class RenderStack extends RenderBox
RenderBox? child = firstChild;
while (child != null) {
final StackParentData childParentData = child.parentData! as StackParentData;
if (!childParentData.isPositioned)
if (!childParentData.isPositioned) {
extent = math.max(extent, mainChildSizeGetter(child));
}
assert(child.parentData == childParentData);
child = childParentData.nextSibling;
}
......@@ -466,15 +475,17 @@ class RenderStack extends RenderBox
bool hasVisualOverflow = false;
BoxConstraints childConstraints = const BoxConstraints();
if (childParentData.left != null && childParentData.right != null)
if (childParentData.left != null && childParentData.right != null) {
childConstraints = childConstraints.tighten(width: size.width - childParentData.right! - childParentData.left!);
else if (childParentData.width != null)
} else if (childParentData.width != null) {
childConstraints = childConstraints.tighten(width: childParentData.width);
}
if (childParentData.top != null && childParentData.bottom != null)
if (childParentData.top != null && childParentData.bottom != null) {
childConstraints = childConstraints.tighten(height: size.height - childParentData.bottom! - childParentData.top!);
else if (childParentData.height != null)
} else if (childParentData.height != null) {
childConstraints = childConstraints.tighten(height: childParentData.height);
}
child.layout(childConstraints, parentUsesSize: true);
......@@ -487,8 +498,9 @@ class RenderStack extends RenderBox
x = alignment.alongOffset(size - child.size as Offset).dx;
}
if (x < 0.0 || x + child.size.width > size.width)
if (x < 0.0 || x + child.size.width > size.width) {
hasVisualOverflow = true;
}
final double y;
if (childParentData.top != null) {
......@@ -499,8 +511,9 @@ class RenderStack extends RenderBox
y = alignment.alongOffset(size - child.size as Offset).dy;
}
if (y < 0.0 || y + child.size.height > size.height)
if (y < 0.0 || y + child.size.height > size.height) {
hasVisualOverflow = true;
}
childParentData.offset = Offset(x, y);
......@@ -675,9 +688,10 @@ class RenderIndexedStack extends RenderStack {
@override
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
if (index != null && firstChild != null)
if (index != null && firstChild != null) {
visitor(_childAtIndex());
}
}
/// The index of the child to show, null if nothing is to be displayed.
int? get index => _index;
......@@ -705,8 +719,9 @@ class RenderIndexedStack extends RenderStack {
@override
bool hitTestChildren(BoxHitTestResult result, { required Offset position }) {
if (firstChild == null || index == null)
if (firstChild == null || index == null) {
return false;
}
assert(position != null);
final RenderBox child = _childAtIndex();
final StackParentData childParentData = child.parentData! as StackParentData;
......@@ -722,8 +737,9 @@ class RenderIndexedStack extends RenderStack {
@override
void paintStack(PaintingContext context, Offset offset) {
if (firstChild == null || index == null)
if (firstChild == null || index == null) {
return;
}
final RenderBox child = _childAtIndex();
final StackParentData childParentData = child.parentData! as StackParentData;
context.paintChild(child, childParentData.offset + offset);
......
......@@ -99,24 +99,27 @@ class TableBorder {
bottom.color != topColor ||
left.color != topColor ||
horizontalInside.color != topColor ||
verticalInside.color != topColor)
verticalInside.color != topColor) {
return false;
}
final double topWidth = top.width;
if (right.width != topWidth ||
bottom.width != topWidth ||
left.width != topWidth ||
horizontalInside.width != topWidth ||
verticalInside.width != topWidth)
verticalInside.width != topWidth) {
return false;
}
final BorderStyle topStyle = top.style;
if (right.style != topStyle ||
bottom.style != topStyle ||
left.style != topStyle ||
horizontalInside.style != topStyle ||
verticalInside.style != topStyle)
verticalInside.style != topStyle) {
return false;
}
return true;
}
......@@ -155,12 +158,15 @@ class TableBorder {
/// {@macro dart.ui.shadow.lerp}
static TableBorder? lerp(TableBorder? a, TableBorder? b, double t) {
assert(t != null);
if (a == null && b == null)
if (a == null && b == null) {
return null;
if (a == null)
}
if (a == null) {
return b!.scale(t);
if (b == null)
}
if (b == null) {
return a.scale(1.0 - t);
}
return TableBorder(
top: BorderSide.lerp(a.top, b.top, t),
right: BorderSide.lerp(a.right, b.right, t),
......@@ -261,9 +267,9 @@ class TableBorder {
}
}
}
if(!isUniform || borderRadius == BorderRadius.zero)
if(!isUniform || borderRadius == BorderRadius.zero) {
paintBorder(canvas, rect, top: top, right: right, bottom: bottom, left: left);
else {
} else {
final RRect outer = borderRadius.toRRect(rect);
final RRect inner = outer.deflate(top.width);
final Paint paint = Paint()..color = top.color;
......@@ -273,10 +279,12 @@ class TableBorder {
@override
bool operator ==(Object other) {
if (identical(this, other))
if (identical(this, other)) {
return true;
if (other.runtimeType != runtimeType)
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is TableBorder
&& other.top == top
&& other.right == right
......
......@@ -40,8 +40,9 @@ class ViewConfiguration {
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType)
if (other.runtimeType != runtimeType) {
return false;
}
return other is ViewConfiguration
&& other.size == size
&& other.devicePixelRatio == devicePixelRatio;
......@@ -89,8 +90,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
/// Always call [prepareInitialFrame] before changing the configuration.
set configuration(ViewConfiguration value) {
assert(value != null);
if (configuration == value)
if (configuration == value) {
return;
}
final ViewConfiguration oldConfiguration = _configuration;
_configuration = value;
if (oldConfiguration.toMatrix() != _configuration.toMatrix()) {
......@@ -165,9 +167,10 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
_size = configuration.size;
assert(_size.isFinite);
if (child != null)
if (child != null) {
child!.layout(BoxConstraints.tight(_size));
}
}
/// Determines the set of render objects located at the given position.
///
......@@ -180,8 +183,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
/// coordinate system as that expected by the root [Layer], which will
/// normally be in physical (device) pixels.
bool hitTest(HitTestResult result, { required Offset position }) {
if (child != null)
if (child != null) {
child!.hitTest(BoxHitTestResult.wrap(result), position: position);
}
result.add(HitTestEntry(this));
return true;
}
......@@ -204,9 +208,10 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
@override
void paint(PaintingContext context, Offset offset) {
if (child != null)
if (child != null) {
context.paintChild(child!, offset);
}
}
@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
......@@ -225,13 +230,15 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
try {
final ui.SceneBuilder builder = ui.SceneBuilder();
final ui.Scene scene = layer!.buildScene(builder);
if (automaticSystemUiAdjustment)
if (automaticSystemUiAdjustment) {
_updateSystemChrome();
}
_window.render(scene);
scene.dispose();
assert(() {
if (debugRepaintRainbowEnabled || debugRepaintTextRainbowEnabled)
if (debugRepaintRainbowEnabled || debugRepaintTextRainbowEnabled) {
debugCurrentRepaintColor = debugCurrentRepaintColor.withHue((debugCurrentRepaintColor.hue + 2.0) % 360.0);
}
return true;
}());
} finally {
......@@ -334,7 +341,8 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
properties.add(DiagnosticsProperty<Size>('window size', _window.physicalSize, tooltip: 'in physical pixels'));
properties.add(DoubleProperty('device pixel ratio', _window.devicePixelRatio, tooltip: 'physical pixels per logical pixel'));
properties.add(DiagnosticsProperty<ViewConfiguration>('configuration', configuration, tooltip: 'in logical pixels'));
if (_window.platformDispatcher.semanticsEnabled)
if (_window.platformDispatcher.semanticsEnabled) {
properties.add(DiagnosticsNode.message('semantics enabled'));
}
}
}
......@@ -899,8 +899,9 @@ void main() {
editable.paintCount = 0;
final AbstractNode? parent = editable.parent;
if (parent is RenderConstrainedBox)
if (parent is RenderConstrainedBox) {
parent.child = null;
}
});
test('paints in the correct order', () {
......
......@@ -858,10 +858,12 @@ class _TestAnnotatedLayer extends Layer {
Offset localPosition, {
required bool onlyFirst,
}) {
if (S != int)
if (S != int) {
return false;
if (size != null && !(offset & size!).contains(localPosition))
}
if (size != null && !(offset & size!).contains(localPosition)) {
return false;
}
final Object untypedValue = value;
final S typedValue = untypedValue as S;
result.add(AnnotationEntry<S>(annotation: typedValue, localPosition: localPosition));
......
......@@ -463,10 +463,12 @@ class _CursorUpdateDetails extends MethodCall {
@override
bool operator ==(dynamic other) {
if (identical(other, this))
if (identical(other, this)) {
return true;
if (other.runtimeType != runtimeType)
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is _CursorUpdateDetails
&& other.method == method
&& other.arguments.length == arguments.length
......
......@@ -89,9 +89,10 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation
@override
void handleEvent(PointerEvent event, HitTestEntry entry) {
if (event is PointerHoverEvent)
if (event is PointerHoverEvent) {
onHover?.call(event);
}
}
}
// A hit test entry that can be assigned with a [TestAnnotationTarget] and an
......
......@@ -208,8 +208,9 @@ class _MethodCall implements Invocation {
}
String _valueName(Object? value) {
if (value is double)
if (value is double) {
return value.toStringAsFixed(1);
}
return value.toString();
}
......
......@@ -937,8 +937,9 @@ class TestRenderSliverBoxChildManager extends RenderSliverBoxChildManager {
@override
void createChild(int index, { required RenderBox? after }) {
if (index < 0 || index >= children.length)
if (index < 0 || index >= children.length) {
return;
}
try {
_currentlyUpdatingChildIndex = index;
_renderObject!.insert(children[index], after: after);
......
......@@ -175,8 +175,9 @@ class TestRenderSliverBoxChildManager extends RenderSliverBoxChildManager {
@override
void createChild(int index, { required RenderBox? after }) {
if (index < 0 || index >= children.length)
if (index < 0 || index >= children.length) {
return;
}
try {
_currentlyUpdatingChildIndex = index;
_renderObject!.insert(children[index], after: after);
......
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