diff --git a/dev/integration_tests/flutter_gallery/lib/demo/shrine/category_menu_page.dart b/dev/integration_tests/flutter_gallery/lib/demo/shrine/category_menu_page.dart index 891ee40a781..c7068d031f8 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/shrine/category_menu_page.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/shrine/category_menu_page.dart @@ -25,9 +25,7 @@ class CategoryMenuPage extends StatelessWidget { GestureDetector( onTap: () { model.setCategory(category); - if (onCategoryTap != null) { - onCategoryTap!(); - } + onCategoryTap?.call(); }, child: model.selectedCategory == category ? Column( diff --git a/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_color_picker.dart b/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_color_picker.dart index d2a1b69dcc9..62c9126c3cf 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_color_picker.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_color_picker.dart @@ -27,9 +27,7 @@ class ColorPicker extends StatelessWidget { color: color, selected: color == selectedColor, onTap: () { - if (onColorSelection != null) { - onColorSelection!(color); - } + onColorSelection?.call(color); }, ); }).toList(), @@ -59,9 +57,7 @@ class _ColorPickerSwatch extends StatelessWidget { child: RawMaterialButton( fillColor: color, onPressed: () { - if (onTap != null) { - onTap!(); - } + onTap?.call(); }, child: !selected ? null : const Icon( Icons.check, diff --git a/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_gesture_transformable.dart b/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_gesture_transformable.dart index b3d3f137e7a..d1f5b629a75 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_gesture_transformable.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/transformations/transformations_demo_gesture_transformable.dart @@ -392,9 +392,7 @@ class _GestureTransformableState extends State with Ticker // Handle the start of a gesture of _GestureType. void _onScaleStart(ScaleStartDetails details) { - if (widget.onScaleStart != null) { - widget.onScaleStart!(details); - } + widget.onScaleStart?.call(details); if (_controller.isAnimating) { _controller.stop(); @@ -417,13 +415,11 @@ class _GestureTransformableState extends State with Ticker // Handle an update to an ongoing gesture of _GestureType. void _onScaleUpdate(ScaleUpdateDetails details) { double scale = _transform.getMaxScaleOnAxis(); - if (widget.onScaleUpdate != null) { - widget.onScaleUpdate!(ScaleUpdateDetails( - focalPoint: fromViewport(details.focalPoint, _transform), - scale: details.scale, - rotation: details.rotation, - )); - } + widget.onScaleUpdate?.call(ScaleUpdateDetails( + focalPoint: fromViewport(details.focalPoint, _transform), + scale: details.scale, + rotation: details.rotation, + )); final Offset focalPointScene = fromViewport( details.focalPoint, _transform, @@ -476,9 +472,7 @@ class _GestureTransformableState extends State with Ticker // Handle the end of a gesture of _GestureType. void _onScaleEnd(ScaleEndDetails details) { - if (widget.onScaleEnd != null) { - widget.onScaleEnd!(details); - } + widget.onScaleEnd?.call(details); setState(() { _scaleStart = null; _rotationStart = null; diff --git a/packages/flutter/lib/src/cupertino/picker.dart b/packages/flutter/lib/src/cupertino/picker.dart index a0c6b58983e..b7124d515e9 100644 --- a/packages/flutter/lib/src/cupertino/picker.dart +++ b/packages/flutter/lib/src/cupertino/picker.dart @@ -255,9 +255,7 @@ class _CupertinoPickerState extends State { HapticFeedback.selectionClick(); } - if (widget.onSelectedItemChanged != null) { - widget.onSelectedItemChanged!(index); - } + widget.onSelectedItemChanged?.call(index); } /// Draws the selectionOverlay. diff --git a/packages/flutter/lib/src/cupertino/slider.dart b/packages/flutter/lib/src/cupertino/slider.dart index 4e6a826c941..71a0fcc0626 100644 --- a/packages/flutter/lib/src/cupertino/slider.dart +++ b/packages/flutter/lib/src/cupertino/slider.dart @@ -475,18 +475,14 @@ class _RenderCupertinoSlider extends RenderConstrainedBox { void _startInteraction(Offset globalPosition) { if (isInteractive) { - if (onChangeStart != null) { - onChangeStart!(_discretizedCurrentDragValue); - } + onChangeStart?.call(_discretizedCurrentDragValue); _currentDragValue = _value; onChanged!(_discretizedCurrentDragValue); } } void _endInteraction() { - if (onChangeEnd != null) { - onChangeEnd!(_discretizedCurrentDragValue); - } + onChangeEnd?.call(_discretizedCurrentDragValue); _currentDragValue = 0.0; } diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 9b58ac40c94..96922650a70 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -116,8 +116,7 @@ class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGe } super.onSingleTapUp(details); _state._requestKeyboard(); - if (_state.widget.onTap != null) - _state.widget.onTap!(); + _state.widget.onTap?.call(); } @override diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index f10da582ee3..72d8e70fb21 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -1104,9 +1104,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti static void reportError(FlutterErrorDetails details) { assert(details != null); assert(details.exception != null); - if (onError != null) { - onError!(details); - } + onError?.call(details); } } diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 0f926ac45e1..d02a1318693 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -193,9 +193,7 @@ class _BottomSheetState extends State { bool get _dismissUnderway => widget.animationController!.status == AnimationStatus.reverse; void _handleDragStart(DragStartDetails details) { - if (widget.onDragStart != null) { - widget.onDragStart!(details); - } + widget.onDragStart?.call(details); } void _handleDragUpdate(DragUpdateDetails details) { @@ -226,12 +224,10 @@ class _BottomSheetState extends State { widget.animationController!.forward(); } - if (widget.onDragEnd != null) { - widget.onDragEnd!( - details, - isClosing: isClosing, - ); - } + widget.onDragEnd?.call( + details, + isClosing: isClosing, + ); if (isClosing) { widget.onClosing(); diff --git a/packages/flutter/lib/src/material/button.dart b/packages/flutter/lib/src/material/button.dart index d8a329458a4..8033f35d552 100644 --- a/packages/flutter/lib/src/material/button.dart +++ b/packages/flutter/lib/src/material/button.dart @@ -330,9 +330,7 @@ class _RawMaterialButtonState extends State { if (_pressed != value) { setState(() { _updateState(MaterialState.pressed, value); - if (widget.onHighlightChanged != null) { - widget.onHighlightChanged!(value); - } + widget.onHighlightChanged?.call(value); }); } } diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index c4f27e1d8ea..3f4621a0c5d 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -150,9 +150,7 @@ class _DropdownMenuItemButtonState extends State<_DropdownMenuItemButton> void _handleOnTap() { final DropdownMenuItem dropdownMenuItem = widget.route.items[widget.itemIndex].item!; - if (dropdownMenuItem.onTap != null) { - dropdownMenuItem.onTap!(); - } + dropdownMenuItem.onTap?.call(); Navigator.pop( context, @@ -1270,13 +1268,10 @@ class _DropdownButtonState extends State> with WidgetsBindi _removeDropdownRoute(); if (!mounted || newValue == null) return; - if (widget.onChanged != null) - widget.onChanged!(newValue.result); + widget.onChanged?.call(newValue.result); }); - if (widget.onTap != null) { - widget.onTap!(); - } + widget.onTap?.call(); } // When isDense is true, reduce the height of this button from _kMenuItemHeight to diff --git a/packages/flutter/lib/src/material/expand_icon.dart b/packages/flutter/lib/src/material/expand_icon.dart index 1f9fba1426d..23e0a1f0a27 100644 --- a/packages/flutter/lib/src/material/expand_icon.dart +++ b/packages/flutter/lib/src/material/expand_icon.dart @@ -137,8 +137,7 @@ class _ExpandIconState extends State with SingleTickerProviderStateM } void _handlePressed() { - if (widget.onPressed != null) - widget.onPressed!(widget.isExpanded); + widget.onPressed?.call(widget.isExpanded); } /// Default icon colors and opacities for when [Theme.brightness] is set to diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index bc5b340f74d..ea9d0e3e6ac 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -442,8 +442,7 @@ class _ExpansionPanelListState extends State { } void _handlePressed(bool isExpanded, int index) { - if (widget.expansionCallback != null) - widget.expansionCallback!(index, isExpanded); + widget.expansionCallback?.call(index, isExpanded); if (widget._allowOnlyOnePanelOpen) { final ExpansionPanelRadio pressedChild = widget.children[index] as ExpansionPanelRadio; diff --git a/packages/flutter/lib/src/material/expansion_tile.dart b/packages/flutter/lib/src/material/expansion_tile.dart index c4207e93799..05c55ab437d 100644 --- a/packages/flutter/lib/src/material/expansion_tile.dart +++ b/packages/flutter/lib/src/material/expansion_tile.dart @@ -241,8 +241,7 @@ class _ExpansionTileState extends State with SingleTickerProvider } PageStorage.of(context)?.writeState(context, _isExpanded); }); - if (widget.onExpansionChanged != null) - widget.onExpansionChanged!(_isExpanded); + widget.onExpansionChanged?.call(_isExpanded); } Widget _buildChildren(BuildContext context, Widget? child) { diff --git a/packages/flutter/lib/src/material/material.dart b/packages/flutter/lib/src/material/material.dart index d95b4c621f5..1e85a905450 100644 --- a/packages/flutter/lib/src/material/material.dart +++ b/packages/flutter/lib/src/material/material.dart @@ -626,8 +626,7 @@ abstract class InkFeature { return true; }()); _controller._removeFeature(this); - if (onRemoved != null) - onRemoved!(); + onRemoved?.call(); } void _paint(Canvas canvas) { diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 2ad823e2728..1ebc93d7e89 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -1110,12 +1110,10 @@ class PopupMenuButtonState extends State> { if (!mounted) return null; if (newValue == null) { - if (widget.onCanceled != null) - widget.onCanceled!(); + widget.onCanceled?.call(); return null; } - if (widget.onSelected != null) - widget.onSelected!(newValue); + widget.onSelected?.call(newValue); }); } } diff --git a/packages/flutter/lib/src/material/range_slider.dart b/packages/flutter/lib/src/material/range_slider.dart index 508de17db72..213d730b609 100644 --- a/packages/flutter/lib/src/material/range_slider.dart +++ b/packages/flutter/lib/src/material/range_slider.dart @@ -1131,9 +1131,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix } _updateLabelPainter(_lastThumbSelection!); - if (onChangeStart != null) { - onChangeStart!(currentValues); - } + onChangeStart?.call(currentValues); onChanged!(_discretizeRangeValues(_newValues)); @@ -1202,9 +1200,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix if (_active && _state.mounted && _lastThumbSelection != null) { final RangeValues discreteValues = _discretizeRangeValues(_newValues); - if (onChangeEnd != null) { - onChangeEnd!(discreteValues); - } + onChangeEnd?.call(discreteValues); _active = false; } _state.overlayController.reverse(); @@ -1710,12 +1706,8 @@ class _RenderValueIndicator extends RenderBox with RelayoutWhenSystemFontsChange @override void paint(PaintingContext context, Offset offset) { - if (_state.paintBottomValueIndicator != null) { - _state.paintBottomValueIndicator!(context, offset); - } - if (_state.paintTopValueIndicator != null) { - _state.paintTopValueIndicator!(context, offset); - } + _state.paintBottomValueIndicator?.call(context, offset); + _state.paintTopValueIndicator?.call(context, offset); } @override diff --git a/packages/flutter/lib/src/material/slider.dart b/packages/flutter/lib/src/material/slider.dart index 7d1b4cb7001..2cfa277bb23 100644 --- a/packages/flutter/lib/src/material/slider.dart +++ b/packages/flutter/lib/src/material/slider.dart @@ -1230,9 +1230,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { // We supply the *current* value as the start location, so that if we have // a tap, it consists of a call to onChangeStart with the previous value and // a call to onChangeEnd with the new value. - if (onChangeStart != null) { - onChangeStart!(_discretize(value)); - } + onChangeStart?.call(_discretize(value)); _currentDragValue = _getValueFromGlobalPosition(globalPosition); onChanged!(_discretize(_currentDragValue)); _state.overlayController.forward(); @@ -1256,9 +1254,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { } if (_active && _state.mounted) { - if (onChangeEnd != null) { - onChangeEnd!(_discretize(_currentDragValue)); - } + onChangeEnd?.call(_discretize(_currentDragValue)); _active = false; _currentDragValue = 0.0; _state.overlayController.reverse(); @@ -1584,9 +1580,7 @@ class _RenderValueIndicator extends RenderBox with RelayoutWhenSystemFontsChange @override void paint(PaintingContext context, Offset offset) { - if (_state.paintValueIndicator != null) { - _state.paintValueIndicator!(context, offset); - } + _state.paintValueIndicator?.call(context, offset); } @override diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 161ea1a6209..2e3729440cb 100755 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -648,8 +648,7 @@ class _StepperState extends State with TickerProviderStateMixin { duration: kThemeAnimationDuration, ); - if (widget.onStepTapped != null) - widget.onStepTapped!(i); + widget.onStepTapped?.call(i); } : null, canRequestFocus: widget.steps[i].state != StepState.disabled, child: _buildVerticalHeader(i), @@ -666,8 +665,7 @@ class _StepperState extends State with TickerProviderStateMixin { for (int i = 0; i < widget.steps.length; i += 1) ...[ InkResponse( onTap: widget.steps[i].state != StepState.disabled ? () { - if (widget.onStepTapped != null) - widget.onStepTapped!(i); + widget.onStepTapped?.call(i); } : null, canRequestFocus: widget.steps[i].state != StepState.disabled, child: Row( diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 819ef2bd32d..db64b38439e 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -1123,9 +1123,7 @@ class _TabBarState extends State { void _handleTap(int index) { assert(index >= 0 && index < widget.tabs.length); _controller!.animateTo(index); - if (widget.onTap != null) { - widget.onTap!(index); - } + widget.onTap?.call(index); } Widget _buildStyledTab(Widget child, bool selected, Animation animation) { diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 8b908e8f17a..1e9dd92e76b 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -114,8 +114,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete } } _state._requestKeyboard(); - if (_state.widget.onTap != null) - _state.widget.onTap!(); + _state.widget.onTap?.call(); } @override diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index 06cd038f699..b6c270b6812 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -1074,9 +1074,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { _center = null; _animateTo(_getThetaForTime(widget.selectedTime)); if (widget.mode == _TimePickerMode.hour) { - if (widget.onHourSelected != null) { - widget.onHourSelected!(); - } + widget.onHourSelected?.call(); } } @@ -1092,9 +1090,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { } else { _announceToAccessibility(context, localizations.formatDecimal(newTime.hourOfPeriod)); } - if (widget.onHourSelected != null) { - widget.onHourSelected!(); - } + widget.onHourSelected?.call(); } else { _announceToAccessibility(context, localizations.formatDecimal(newTime.minute)); } diff --git a/packages/flutter/lib/src/painting/decoration_image.dart b/packages/flutter/lib/src/painting/decoration_image.dart index 64e21e654dd..a9cdff7a475 100644 --- a/packages/flutter/lib/src/painting/decoration_image.dart +++ b/packages/flutter/lib/src/painting/decoration_image.dart @@ -534,9 +534,7 @@ void paintImage({ if (existingSizeInfo == null || existingSizeInfo.displaySizeInBytes < sizeInfo.displaySizeInBytes) { _pendingImageSizeInfo[sizeInfo.source!] = sizeInfo; } - if (debugOnPaintImage != null) { - debugOnPaintImage!(sizeInfo); - } + debugOnPaintImage?.call(sizeInfo); SchedulerBinding.instance!.addPostFrameCallback((Duration timeStamp) { _lastFrameImageSizeInfo = _pendingImageSizeInfo.values.toSet(); if (_pendingImageSizeInfo.isEmpty) { diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index 86c3ed2b2c5..21f8a5a9f0e 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -598,9 +598,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin { if (nextSelection == selection && cause != SelectionChangedCause.keyboard && !focusingEmpty) { return; } - if (onSelectionChanged != null) { - onSelectionChanged!(nextSelection, this, cause); - } + onSelectionChanged?.call(nextSelection, this, cause); } static final Set _movementKeys = { diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index f29f20e00d5..a23ed4521f5 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -4760,103 +4760,83 @@ class RenderSemanticsAnnotations extends RenderProxyBox { } void _performTap() { - if (onTap != null) - onTap!(); + onTap?.call(); } void _performLongPress() { - if (onLongPress != null) - onLongPress!(); + onLongPress?.call(); } void _performDismiss() { - if (onDismiss != null) - onDismiss!(); + onDismiss?.call(); } void _performScrollLeft() { - if (onScrollLeft != null) - onScrollLeft!(); + onScrollLeft?.call(); } void _performScrollRight() { - if (onScrollRight != null) - onScrollRight!(); + onScrollRight?.call(); } void _performScrollUp() { - if (onScrollUp != null) - onScrollUp!(); + onScrollUp?.call(); } void _performScrollDown() { - if (onScrollDown != null) - onScrollDown!(); + onScrollDown?.call(); } void _performIncrease() { - if (onIncrease != null) - onIncrease!(); + onIncrease?.call(); } void _performDecrease() { - if (onDecrease != null) - onDecrease!(); + onDecrease?.call(); } void _performCopy() { - if (onCopy != null) - onCopy!(); + onCopy?.call(); } void _performCut() { - if (onCut != null) - onCut!(); + onCut?.call(); } void _performPaste() { - if (onPaste != null) - onPaste!(); + onPaste?.call(); } void _performMoveCursorForwardByCharacter(bool extendSelection) { - if (onMoveCursorForwardByCharacter != null) - onMoveCursorForwardByCharacter!(extendSelection); + onMoveCursorForwardByCharacter?.call(extendSelection); } void _performMoveCursorBackwardByCharacter(bool extendSelection) { - if (onMoveCursorBackwardByCharacter != null) - onMoveCursorBackwardByCharacter!(extendSelection); + onMoveCursorBackwardByCharacter?.call(extendSelection); } void _performMoveCursorForwardByWord(bool extendSelection) { - if (onMoveCursorForwardByWord != null) - onMoveCursorForwardByWord!(extendSelection); + onMoveCursorForwardByWord?.call(extendSelection); } void _performMoveCursorBackwardByWord(bool extendSelection) { - if (onMoveCursorBackwardByWord != null) - onMoveCursorBackwardByWord!(extendSelection); + onMoveCursorBackwardByWord?.call(extendSelection); } void _performSetSelection(TextSelection selection) { - if (onSetSelection != null) - onSetSelection!(selection); + onSetSelection?.call(selection); } void _performSetText(String text) { - if (onSetText != null) - onSetText!(text); + onSetText?.call(text); } void _performDidGainAccessibilityFocus() { - if (onDidGainAccessibilityFocus != null) - onDidGainAccessibilityFocus!(); + onDidGainAccessibilityFocus?.call(); } void _performDidLoseAccessibilityFocus() { - if (onDidLoseAccessibilityFocus != null) - onDidLoseAccessibilityFocus!(); + onDidLoseAccessibilityFocus?.call(); } } diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 0675e498e37..26cc5008bcb 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -6178,8 +6178,7 @@ class WidgetToRenderBoxAdapter extends LeafRenderObjectWidget { @override void updateRenderObject(BuildContext context, RenderBox renderObject) { - if (onBuild != null) - onBuild!(); + onBuild?.call(); } } diff --git a/packages/flutter/lib/src/widgets/dismissible.dart b/packages/flutter/lib/src/widgets/dismissible.dart index bfc5662d2dc..5ce3aacbb98 100644 --- a/packages/flutter/lib/src/widgets/dismissible.dart +++ b/packages/flutter/lib/src/widgets/dismissible.dart @@ -543,13 +543,9 @@ class _DismissibleState extends State with TickerProviderStateMixin void _handleResizeProgressChanged() { if (_resizeController!.isCompleted) { - if (widget.onDismissed != null) { - final DismissDirection direction = _dismissDirection; - widget.onDismissed!(direction); - } + widget.onDismissed?.call(_dismissDirection); } else { - if (widget.onResize != null) - widget.onResize!(); + widget.onResize?.call(); } } diff --git a/packages/flutter/lib/src/widgets/drag_target.dart b/packages/flutter/lib/src/widgets/drag_target.dart index 22e7e553610..b5f35d1ed50 100644 --- a/packages/flutter/lib/src/widgets/drag_target.dart +++ b/packages/flutter/lib/src/widgets/drag_target.dart @@ -576,8 +576,7 @@ class _DraggableState extends State> { widget.onDraggableCanceled!(velocity, offset); }, ); - if (widget.onDragStarted != null) - widget.onDragStarted!(); + widget.onDragStarted?.call(); return avatar; } @@ -754,8 +753,7 @@ class _DragTargetState extends State> { _candidateAvatars.remove(avatar); _rejectedAvatars.remove(avatar); }); - if (widget.onLeave != null) - widget.onLeave!(avatar.data as T?); + widget.onLeave?.call(avatar.data as T?); } void didDrop(_DragAvatar avatar) { @@ -765,17 +763,14 @@ class _DragTargetState extends State> { setState(() { _candidateAvatars.remove(avatar); }); - if (widget.onAccept != null) - widget.onAccept!(avatar.data! as T); - if (widget.onAcceptWithDetails != null) - widget.onAcceptWithDetails!(DragTargetDetails(data: avatar.data! as T, offset: avatar._lastOffset!)); + widget.onAccept?.call(avatar.data! as T); + widget.onAcceptWithDetails?.call(DragTargetDetails(data: avatar.data! as T, offset: avatar._lastOffset!)); } void didMove(_DragAvatar avatar) { if (!mounted) return; - if (widget.onMove != null) - widget.onMove!(DragTargetDetails(data: avatar.data! as T, offset: avatar._lastOffset!)); + widget.onMove?.call(DragTargetDetails(data: avatar.data! as T, offset: avatar._lastOffset!)); } @override @@ -937,8 +932,7 @@ class _DragAvatar extends Drag { _entry!.remove(); _entry = null; // TODO(ianh): consider passing _entry as well so the client can perform an animation. - if (onDragEnd != null) - onDragEnd!(velocity ?? Velocity.zero, _lastOffset!, wasAccepted); + onDragEnd?.call(velocity ?? Velocity.zero, _lastOffset!, wasAccepted); } Widget _build(BuildContext context) { diff --git a/packages/flutter/lib/src/widgets/focus_scope.dart b/packages/flutter/lib/src/widgets/focus_scope.dart index 3ca2358f03a..55b43543657 100644 --- a/packages/flutter/lib/src/widgets/focus_scope.dart +++ b/packages/flutter/lib/src/widgets/focus_scope.dart @@ -670,9 +670,7 @@ class _FocusState extends State { final bool hasPrimaryFocus = focusNode.hasPrimaryFocus; final bool canRequestFocus = focusNode.canRequestFocus; final bool descendantsAreFocusable = focusNode.descendantsAreFocusable; - if (widget.onFocusChange != null) { - widget.onFocusChange!(focusNode.hasFocus); - } + widget.onFocusChange?.call(focusNode.hasFocus); if (_hasPrimaryFocus != hasPrimaryFocus) { setState(() { _hasPrimaryFocus = hasPrimaryFocus; diff --git a/packages/flutter/lib/src/widgets/form.dart b/packages/flutter/lib/src/widgets/form.dart index f8af252cd4d..b0ef599e0fa 100644 --- a/packages/flutter/lib/src/widgets/form.dart +++ b/packages/flutter/lib/src/widgets/form.dart @@ -167,9 +167,7 @@ class FormState extends State
{ // Called when a form field has changed. This will cause all form fields // to rebuild, useful if form fields have interdependencies. void _fieldDidChange() { - if (widget.onChanged != null) - widget.onChanged!(); - + widget.onChanged?.call(); _hasInteractedByUser = _fields .any((FormFieldState field) => field._hasInteractedByUser); @@ -435,8 +433,7 @@ class FormFieldState extends State> { /// Calls the [FormField]'s onSaved method with the current value. void save() { - if (widget.onSaved != null) - widget.onSaved!(value); + widget.onSaved?.call(value); } /// Resets the field to its initial value. diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 313ab39208d..d3b343caf34 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -4241,9 +4241,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext { if (_lifecycleState != _ElementLifecycle.active || !_dirty) return; assert(() { - if (debugOnRebuildDirtyWidget != null) { - debugOnRebuildDirtyWidget!(this, _debugBuiltOnce); - } + debugOnRebuildDirtyWidget?.call(this, _debugBuiltOnce); if (debugPrintRebuildDirtyWidgets) { if (!_debugBuiltOnce) { debugPrint('Building $this'); diff --git a/packages/flutter/lib/src/widgets/gesture_detector.dart b/packages/flutter/lib/src/widgets/gesture_detector.dart index a5756d46204..d6425d74c50 100644 --- a/packages/flutter/lib/src/widgets/gesture_detector.dart +++ b/packages/flutter/lib/src/widgets/gesture_detector.dart @@ -1332,12 +1332,9 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate { return () { assert(tap != null); - if (tap.onTapDown != null) - tap.onTapDown!(TapDownDetails()); - if (tap.onTapUp != null) - tap.onTapUp!(TapUpDetails(kind: PointerDeviceKind.unknown)); - if (tap.onTap != null) - tap.onTap!(); + tap.onTapDown?.call(TapDownDetails()); + tap.onTapUp?.call(TapUpDetails(kind: PointerDeviceKind.unknown)); + tap.onTap?.call(); }; } @@ -1347,14 +1344,10 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate { return null; return () { - if (longPress.onLongPressStart != null) - longPress.onLongPressStart!(const LongPressStartDetails()); - if (longPress.onLongPress != null) - longPress.onLongPress!(); - if (longPress.onLongPressEnd != null) - longPress.onLongPressEnd!(const LongPressEndDetails()); - if (longPress.onLongPressUp != null) - longPress.onLongPressUp!(); + longPress.onLongPressStart?.call(const LongPressStartDetails()); + longPress.onLongPress?.call(); + longPress.onLongPressEnd?.call(const LongPressEndDetails()); + longPress.onLongPressUp?.call(); }; } @@ -1365,27 +1358,19 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate { final GestureDragUpdateCallback? horizontalHandler = horizontal == null ? null : (DragUpdateDetails details) { - if (horizontal.onDown != null) - horizontal.onDown!(DragDownDetails()); - if (horizontal.onStart != null) - horizontal.onStart!(DragStartDetails()); - if (horizontal.onUpdate != null) - horizontal.onUpdate!(details); - if (horizontal.onEnd != null) - horizontal.onEnd!(DragEndDetails(primaryVelocity: 0.0)); + horizontal.onDown?.call(DragDownDetails()); + horizontal.onStart?.call(DragStartDetails()); + horizontal.onUpdate?.call(details); + horizontal.onEnd?.call(DragEndDetails(primaryVelocity: 0.0)); }; final GestureDragUpdateCallback? panHandler = pan == null ? null : (DragUpdateDetails details) { - if (pan.onDown != null) - pan.onDown!(DragDownDetails()); - if (pan.onStart != null) - pan.onStart!(DragStartDetails()); - if (pan.onUpdate != null) - pan.onUpdate!(details); - if (pan.onEnd != null) - pan.onEnd!(DragEndDetails()); + pan.onDown?.call(DragDownDetails()); + pan.onStart?.call(DragStartDetails()); + pan.onUpdate?.call(details); + pan.onEnd?.call(DragEndDetails()); }; if (horizontalHandler == null && panHandler == null) @@ -1405,27 +1390,19 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate { final GestureDragUpdateCallback? verticalHandler = vertical == null ? null : (DragUpdateDetails details) { - if (vertical.onDown != null) - vertical.onDown!(DragDownDetails()); - if (vertical.onStart != null) - vertical.onStart!(DragStartDetails()); - if (vertical.onUpdate != null) - vertical.onUpdate!(details); - if (vertical.onEnd != null) - vertical.onEnd!(DragEndDetails(primaryVelocity: 0.0)); + vertical.onDown?.call(DragDownDetails()); + vertical.onStart?.call(DragStartDetails()); + vertical.onUpdate?.call(details); + vertical.onEnd?.call(DragEndDetails(primaryVelocity: 0.0)); }; final GestureDragUpdateCallback? panHandler = pan == null ? null : (DragUpdateDetails details) { - if (pan.onDown != null) - pan.onDown!(DragDownDetails()); - if (pan.onStart != null) - pan.onStart!(DragStartDetails()); - if (pan.onUpdate != null) - pan.onUpdate!(details); - if (pan.onEnd != null) - pan.onEnd!(DragEndDetails()); + pan.onDown?.call(DragDownDetails()); + pan.onStart?.call(DragStartDetails()); + pan.onUpdate?.call(details); + pan.onEnd?.call(DragEndDetails()); }; if (verticalHandler == null && panHandler == null) diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 263c5ea8d29..84c9fe28964 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -370,8 +370,7 @@ abstract class ImplicitlyAnimatedWidgetState _controller.addStatusListener((AnimationStatus status) { switch (status) { case AnimationStatus.completed: - if (widget.onEnd != null) - widget.onEnd!(); + widget.onEnd?.call(); break; case AnimationStatus.dismissed: case AnimationStatus.forward: diff --git a/packages/flutter/lib/src/widgets/modal_barrier.dart b/packages/flutter/lib/src/widgets/modal_barrier.dart index 527a53fede7..fea4a7c7605 100644 --- a/packages/flutter/lib/src/widgets/modal_barrier.dart +++ b/packages/flutter/lib/src/widgets/modal_barrier.dart @@ -228,8 +228,7 @@ class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer { @protected @override void handleTapUp({PointerDownEvent? down, PointerUpEvent? up}) { - if (onAnyTapUp != null) - onAnyTapUp!(); + onAnyTapUp?.call(); } @protected diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index f88d407b8fc..d6fabc63b6b 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -5968,9 +5968,7 @@ class RestorableRouteFuture extends RestorableProperty { _route?.restorationScopeId.removeListener(notifyListeners); _route = null; notifyListeners(); - if (onComplete != null) { - onComplete!(result as T); - } + onComplete?.call(result as T); }); } diff --git a/packages/flutter/lib/src/widgets/platform_view.dart b/packages/flutter/lib/src/widgets/platform_view.dart index f45f0637ec2..a9e9856b196 100644 --- a/packages/flutter/lib/src/widgets/platform_view.dart +++ b/packages/flutter/lib/src/widgets/platform_view.dart @@ -638,9 +638,7 @@ class _UiKitViewState extends State { controller.dispose(); return; } - if (widget.onPlatformViewCreated != null) { - widget.onPlatformViewCreated!(id); - } + widget.onPlatformViewCreated?.call(id); setState(() { _controller = controller; }); } } diff --git a/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart b/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart index 3c7cdebc413..58d49a42044 100644 --- a/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart +++ b/packages/flutter/lib/src/widgets/raw_keyboard_listener.dart @@ -121,8 +121,7 @@ class _RawKeyboardListenerState extends State { } void _handleRawKeyEvent(RawKeyEvent event) { - if (widget.onKey != null) - widget.onKey!(event); + widget.onKey?.call(event); } @override diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index b9f3c555a57..aa5ac7a2a4d 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -445,8 +445,7 @@ class LocalHistoryEntry { } void _notifyRemoved() { - if (onRemove != null) - onRemove!(); + onRemove?.call(); } } diff --git a/packages/flutter/lib/src/widgets/scroll_activity.dart b/packages/flutter/lib/src/widgets/scroll_activity.dart index 2cd116b89d1..5aee86ad1ed 100644 --- a/packages/flutter/lib/src/widgets/scroll_activity.dart +++ b/packages/flutter/lib/src/widgets/scroll_activity.dart @@ -214,8 +214,7 @@ class HoldScrollActivity extends ScrollActivity implements ScrollHoldController @override void dispose() { - if (onHoldCanceled != null) - onHoldCanceled!(); + onHoldCanceled?.call(); super.dispose(); } } @@ -406,8 +405,7 @@ class ScrollDragController implements Drag { @mustCallSuper void dispose() { _lastDetails = null; - if (onDragCanceled != null) - onDragCanceled!(); + onDragCanceled?.call(); } /// The most recently observed [DragStartDetails], [DragUpdateDetails], or diff --git a/packages/flutter/lib/src/widgets/text_selection.dart b/packages/flutter/lib/src/widgets/text_selection.dart index 15783a7ae62..dff23372ca8 100644 --- a/packages/flutter/lib/src/widgets/text_selection.dart +++ b/packages/flutter/lib/src/widgets/text_selection.dart @@ -782,8 +782,7 @@ class _TextSelectionHandleOverlayState } void _handleTap() { - if (widget.onSelectionHandleTapped != null) - widget.onSelectionHandleTapped!(); + widget.onSelectionHandleTapped?.call(); } @override @@ -1386,9 +1385,7 @@ class _TextSelectionGestureDetectorState extends State localListeners = listeners.toList(); for (final ImageStreamListener listener in localListeners) { - if (listener.onError != null) { - listener.onError!(exception, stackTrace); - } + listener.onError?.call(exception, stackTrace); } } } diff --git a/packages/flutter/test/widgets/image_test.dart b/packages/flutter/test/widgets/image_test.dart index e0b450598d5..ea86c2b2235 100644 --- a/packages/flutter/test/widgets/image_test.dart +++ b/packages/flutter/test/widgets/image_test.dart @@ -2026,9 +2026,7 @@ class _TestImageStreamCompleter extends ImageStreamCompleter { }) { final List localListeners = listeners.toList(); for (final ImageStreamListener listener in localListeners) { - if (listener.onError != null) { - listener.onError!(exception, stackTrace); - } + listener.onError?.call(exception, stackTrace); } } } diff --git a/packages/flutter/test/widgets/independent_widget_layout_test.dart b/packages/flutter/test/widgets/independent_widget_layout_test.dart index fb156523136..44c160191b0 100644 --- a/packages/flutter/test/widgets/independent_widget_layout_test.dart +++ b/packages/flutter/test/widgets/independent_widget_layout_test.dart @@ -86,8 +86,7 @@ class Counter { class Trigger { VoidCallback? callback; void fire() { - if (callback != null) - callback!(); + callback?.call(); } } diff --git a/packages/flutter/test/widgets/mouse_region_test.dart b/packages/flutter/test/widgets/mouse_region_test.dart index 121dafb4be7..d039f9b704c 100644 --- a/packages/flutter/test/widgets/mouse_region_test.dart +++ b/packages/flutter/test/widgets/mouse_region_test.dart @@ -29,21 +29,13 @@ class HoverClient extends StatefulWidget { class HoverClientState extends State { void _onExit(PointerExitEvent details) { - if (widget.onExit != null) { - widget.onExit!(); - } - if (widget.onHover != null) { - widget.onHover!(false); - } + widget.onExit?.call(); + widget.onHover?.call(false); } void _onEnter(PointerEnterEvent details) { - if (widget.onEnter != null) { - widget.onEnter!(); - } - if (widget.onHover != null) { - widget.onHover!(true); - } + widget.onEnter?.call(); + widget.onHover?.call(true); } @override diff --git a/packages/flutter/test/widgets/navigator_test.dart b/packages/flutter/test/widgets/navigator_test.dart index 20f503c9e08..8839ba16d6f 100644 --- a/packages/flutter/test/widgets/navigator_test.dart +++ b/packages/flutter/test/widgets/navigator_test.dart @@ -3587,22 +3587,19 @@ class RouteAnnouncementSpy extends Route { @override void didChangeNext(Route? nextRoute) { super.didChangeNext(nextRoute); - if (onDidChangeNext != null) - onDidChangeNext!(nextRoute); + onDidChangeNext?.call(nextRoute); } @override void didChangePrevious(Route? previousRoute) { super.didChangePrevious(previousRoute); - if (onDidChangePrevious != null) - onDidChangePrevious!(previousRoute); + onDidChangePrevious?.call(previousRoute); } @override void didPopNext(Route nextRoute) { super.didPopNext(nextRoute); - if (onDidPopNext != null) - onDidPopNext!(nextRoute); + onDidPopNext?.call(nextRoute); } } @@ -3728,9 +3725,7 @@ class HeroControllerSpy extends HeroController { OnObservation? onPushed; @override void didPush(Route? route, Route? previousRoute) { - if (onPushed != null) { - onPushed!(route, previousRoute); - } + onPushed?.call(route, previousRoute); } } diff --git a/packages/flutter/test/widgets/observer_tester.dart b/packages/flutter/test/widgets/observer_tester.dart index f2ccbf872bd..e26e0bf1c8a 100644 --- a/packages/flutter/test/widgets/observer_tester.dart +++ b/packages/flutter/test/widgets/observer_tester.dart @@ -16,33 +16,26 @@ class TestObserver extends NavigatorObserver { @override void didPush(Route route, Route? previousRoute) { - if (onPushed != null) { - onPushed!(route, previousRoute); - } + onPushed?.call(route, previousRoute); } @override void didPop(Route route, Route? previousRoute) { - if (onPopped != null) { - onPopped!(route, previousRoute); - } + onPopped?.call(route, previousRoute); } @override void didRemove(Route route, Route? previousRoute) { - if (onRemoved != null) - onRemoved!(route, previousRoute); + onRemoved?.call(route, previousRoute); } @override void didReplace({ Route? oldRoute, Route? newRoute }) { - if (onReplaced != null) - onReplaced!(newRoute, oldRoute); + onReplaced?.call(newRoute, oldRoute); } @override void didStartUserGesture(Route route, Route? previousRoute) { - if (onStartUserGesture != null) - onStartUserGesture!(route, previousRoute); + onStartUserGesture?.call(route, previousRoute); } } diff --git a/packages/flutter_test/lib/src/test_text_input.dart b/packages/flutter_test/lib/src/test_text_input.dart index 1ae2be908f8..aedf3883246 100644 --- a/packages/flutter_test/lib/src/test_text_input.dart +++ b/packages/flutter_test/lib/src/test_text_input.dart @@ -102,8 +102,7 @@ class TestTextInput { case 'TextInput.clearClient': _client = 0; _isVisible = false; - if (onCleared != null) - onCleared!(); + onCleared?.call(); break; case 'TextInput.setEditingState': editingState = methodCall.arguments as Map;