Unverified Commit 5344ed71 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter] use null aware operators for function invocations (#79003)

parent 8893e89d
......@@ -985,8 +985,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
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]),
......
......@@ -1018,7 +1018,7 @@ class DataTable extends StatelessWidget {
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 @@ class DataTable extends StatelessWidget {
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;
......
......@@ -460,13 +460,11 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
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 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
/// 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;
......
......@@ -865,12 +865,11 @@ class _InkResponseState extends State<_InkResponseStateWidget>
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 @@ class _InkResponseState extends State<_InkResponseStateWidget>
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 @@ class _InkResponseState extends State<_InkResponseStateWidget>
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() {
......
......@@ -94,8 +94,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur
break;
}
}
if (_state.widget.onTap != null)
_state.widget.onTap!();
_state.widget.onTap?.call();
}
@override
......
......@@ -176,8 +176,7 @@ class PaintingContext extends ClipContext {
assert(() {
if (debugProfilePaintsEnabled)
Timeline.startSync('${child.runtimeType}', arguments: timelineArgumentsIndicatingLandmarkEvent);
if (debugOnProfilePaint != null)
debugOnProfilePaint!(child);
debugOnProfilePaint?.call(child);
return true;
}());
......@@ -830,8 +829,7 @@ class PipelineOwner {
/// 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 @@ class PipelineOwner {
if (_outstandingSemanticsHandles == 1) {
assert(_semanticsOwner == null);
_semanticsOwner = SemanticsOwner();
if (onSemanticsOwnerCreated != null)
onSemanticsOwnerCreated!();
onSemanticsOwnerCreated?.call();
}
return SemanticsHandle._(this, listener);
}
......@@ -1041,8 +1038,7 @@ class PipelineOwner {
if (_outstandingSemanticsHandles == 0) {
_semanticsOwner!.dispose();
_semanticsOwner = null;
if (onSemanticsOwnerDisposed != null)
onSemanticsOwnerDisposed!();
onSemanticsOwnerDisposed?.call();
}
}
......
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