[flutter] use null aware operators for function invocations (#79003)
diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart
index aca0a99..bb3595d 100644
--- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart
+++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart
@@ -985,8 +985,7 @@
unselectedLabelStyle: effectiveUnselectedLabelStyle,
enableFeedback: widget.enableFeedback ?? bottomTheme.enableFeedback ?? true,
onTap: () {
- if (widget.onTap != null)
- widget.onTap!(i);
+ widget.onTap?.call(i);
},
colorTween: colorTween,
flex: _evaluateFlex(_animations[i]),
diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart
index 2987e12..9c20486 100644
--- a/packages/flutter/lib/src/material/data_table.dart
+++ b/packages/flutter/lib/src/material/data_table.dart
@@ -1018,7 +1018,7 @@
tableRows[rowIndex].children![0] = _buildCheckbox(
context: context,
checked: row.selected,
- onRowTap: () => row.onSelectChanged != null ? row.onSelectChanged!(!row.selected) : null ,
+ onRowTap: () => row.onSelectChanged?.call(!row.selected),
onCheckboxChanged: row.onSelectChanged,
overlayColor: row.color ?? effectiveDataRowColor,
tristate: false,
@@ -1084,7 +1084,7 @@
onLongPress: cell.onLongPress,
onTapCancel: cell.onTapCancel,
onTapDown: cell.onTapDown,
- onSelectChanged: () => row.onSelectChanged != null ? row.onSelectChanged!(!row.selected) : null,
+ onSelectChanged: () => row.onSelectChanged?.call(!row.selected),
overlayColor: row.color ?? effectiveDataRowColor,
);
rowIndex += 1;
diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart
index 56cb976..cf9d1b0 100644
--- a/packages/flutter/lib/src/material/drawer.dart
+++ b/packages/flutter/lib/src/material/drawer.dart
@@ -460,13 +460,11 @@
switch (Directionality.of(context)) {
case TextDirection.rtl:
_controller.fling(velocity: -visualVelocity);
- if (widget.drawerCallback != null)
- widget.drawerCallback!(visualVelocity < 0.0);
+ widget.drawerCallback?.call(visualVelocity < 0.0);
break;
case TextDirection.ltr:
_controller.fling(velocity: visualVelocity);
- if (widget.drawerCallback != null)
- widget.drawerCallback!(visualVelocity > 0.0);
+ widget.drawerCallback?.call(visualVelocity > 0.0);
break;
}
} else if (_controller.value < 0.5) {
@@ -481,15 +479,13 @@
/// Typically called by [ScaffoldState.openDrawer].
void open() {
_controller.fling(velocity: 1.0);
- if (widget.drawerCallback != null)
- widget.drawerCallback!(true);
+ widget.drawerCallback?.call(true);
}
/// Starts an animation to close the drawer.
void close() {
_controller.fling(velocity: -1.0);
- if (widget.drawerCallback != null)
- widget.drawerCallback!(false);
+ widget.drawerCallback?.call(false);
}
late ColorTween _scrimColorTween;
diff --git a/packages/flutter/lib/src/material/ink_well.dart b/packages/flutter/lib/src/material/ink_well.dart
index 7c54573..a13f7e9 100644
--- a/packages/flutter/lib/src/material/ink_well.dart
+++ b/packages/flutter/lib/src/material/ink_well.dart
@@ -865,12 +865,11 @@
switch (type) {
case _HighlightType.pressed:
- if (widget.onHighlightChanged != null)
- widget.onHighlightChanged!(value);
+ widget.onHighlightChanged?.call(value);
break;
case _HighlightType.hover:
- if (callOnHover && widget.onHover != null)
- widget.onHover!(value);
+ if (callOnHover)
+ widget.onHover?.call(value);
break;
case _HighlightType.focus:
break;
@@ -951,18 +950,14 @@
void _handleFocusUpdate(bool hasFocus) {
_hasFocus = hasFocus;
_updateFocusHighlights();
- if (widget.onFocusChange != null) {
- widget.onFocusChange!(hasFocus);
- }
+ widget.onFocusChange?.call(hasFocus);
}
void _handleTapDown(TapDownDetails details) {
if (_anyChildInkResponsePressed)
return;
_startSplash(details: details);
- if (widget.onTapDown != null) {
- widget.onTapDown!(details);
- }
+ widget.onTapDown?.call(details);
}
void _startSplash({TapDownDetails? details, BuildContext? context}) {
@@ -991,24 +986,21 @@
if (widget.onTap != null) {
if (widget.enableFeedback)
Feedback.forTap(context);
- widget.onTap!();
+ widget.onTap?.call();
}
}
void _handleTapCancel() {
_currentSplash?.cancel();
_currentSplash = null;
- if (widget.onTapCancel != null) {
- widget.onTapCancel!();
- }
+ widget.onTapCancel?.call();
updateHighlight(_HighlightType.pressed, value: false);
}
void _handleDoubleTap() {
_currentSplash?.confirm();
_currentSplash = null;
- if (widget.onDoubleTap != null)
- widget.onDoubleTap!();
+ widget.onDoubleTap?.call();
}
void _handleLongPress() {
diff --git a/packages/flutter/lib/src/material/selectable_text.dart b/packages/flutter/lib/src/material/selectable_text.dart
index 2088be8..5b846d4 100644
--- a/packages/flutter/lib/src/material/selectable_text.dart
+++ b/packages/flutter/lib/src/material/selectable_text.dart
@@ -94,8 +94,7 @@
break;
}
}
- if (_state.widget.onTap != null)
- _state.widget.onTap!();
+ _state.widget.onTap?.call();
}
@override
diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart
index 6afdfe0..4208bb3 100644
--- a/packages/flutter/lib/src/rendering/object.dart
+++ b/packages/flutter/lib/src/rendering/object.dart
@@ -176,8 +176,7 @@
assert(() {
if (debugProfilePaintsEnabled)
Timeline.startSync('${child.runtimeType}', arguments: timelineArgumentsIndicatingLandmarkEvent);
- if (debugOnProfilePaint != null)
- debugOnProfilePaint!(child);
+ debugOnProfilePaint?.call(child);
return true;
}());
@@ -830,8 +829,7 @@
/// Used to notify the pipeline owner that an associated render object wishes
/// to update its visual appearance.
void requestVisualUpdate() {
- if (onNeedVisualUpdate != null)
- onNeedVisualUpdate!();
+ onNeedVisualUpdate?.call();
}
/// The unique object managed by this pipeline that has no parent.
@@ -1029,8 +1027,7 @@
if (_outstandingSemanticsHandles == 1) {
assert(_semanticsOwner == null);
_semanticsOwner = SemanticsOwner();
- if (onSemanticsOwnerCreated != null)
- onSemanticsOwnerCreated!();
+ onSemanticsOwnerCreated?.call();
}
return SemanticsHandle._(this, listener);
}
@@ -1041,8 +1038,7 @@
if (_outstandingSemanticsHandles == 0) {
_semanticsOwner!.dispose();
_semanticsOwner = null;
- if (onSemanticsOwnerDisposed != null)
- onSemanticsOwnerDisposed!();
+ onSemanticsOwnerDisposed?.call();
}
}