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 ...@@ -985,8 +985,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
unselectedLabelStyle: effectiveUnselectedLabelStyle, unselectedLabelStyle: effectiveUnselectedLabelStyle,
enableFeedback: widget.enableFeedback ?? bottomTheme.enableFeedback ?? true, enableFeedback: widget.enableFeedback ?? bottomTheme.enableFeedback ?? true,
onTap: () { onTap: () {
if (widget.onTap != null) widget.onTap?.call(i);
widget.onTap!(i);
}, },
colorTween: colorTween, colorTween: colorTween,
flex: _evaluateFlex(_animations[i]), flex: _evaluateFlex(_animations[i]),
......
...@@ -1018,7 +1018,7 @@ class DataTable extends StatelessWidget { ...@@ -1018,7 +1018,7 @@ class DataTable extends StatelessWidget {
tableRows[rowIndex].children![0] = _buildCheckbox( tableRows[rowIndex].children![0] = _buildCheckbox(
context: context, context: context,
checked: row.selected, checked: row.selected,
onRowTap: () => row.onSelectChanged != null ? row.onSelectChanged!(!row.selected) : null , onRowTap: () => row.onSelectChanged?.call(!row.selected),
onCheckboxChanged: row.onSelectChanged, onCheckboxChanged: row.onSelectChanged,
overlayColor: row.color ?? effectiveDataRowColor, overlayColor: row.color ?? effectiveDataRowColor,
tristate: false, tristate: false,
...@@ -1084,7 +1084,7 @@ class DataTable extends StatelessWidget { ...@@ -1084,7 +1084,7 @@ class DataTable extends StatelessWidget {
onLongPress: cell.onLongPress, onLongPress: cell.onLongPress,
onTapCancel: cell.onTapCancel, onTapCancel: cell.onTapCancel,
onTapDown: cell.onTapDown, onTapDown: cell.onTapDown,
onSelectChanged: () => row.onSelectChanged != null ? row.onSelectChanged!(!row.selected) : null, onSelectChanged: () => row.onSelectChanged?.call(!row.selected),
overlayColor: row.color ?? effectiveDataRowColor, overlayColor: row.color ?? effectiveDataRowColor,
); );
rowIndex += 1; rowIndex += 1;
......
...@@ -460,13 +460,11 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro ...@@ -460,13 +460,11 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
switch (Directionality.of(context)) { switch (Directionality.of(context)) {
case TextDirection.rtl: case TextDirection.rtl:
_controller.fling(velocity: -visualVelocity); _controller.fling(velocity: -visualVelocity);
if (widget.drawerCallback != null) widget.drawerCallback?.call(visualVelocity < 0.0);
widget.drawerCallback!(visualVelocity < 0.0);
break; break;
case TextDirection.ltr: case TextDirection.ltr:
_controller.fling(velocity: visualVelocity); _controller.fling(velocity: visualVelocity);
if (widget.drawerCallback != null) widget.drawerCallback?.call(visualVelocity > 0.0);
widget.drawerCallback!(visualVelocity > 0.0);
break; break;
} }
} else if (_controller.value < 0.5) { } else if (_controller.value < 0.5) {
...@@ -481,15 +479,13 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro ...@@ -481,15 +479,13 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
/// Typically called by [ScaffoldState.openDrawer]. /// Typically called by [ScaffoldState.openDrawer].
void open() { void open() {
_controller.fling(velocity: 1.0); _controller.fling(velocity: 1.0);
if (widget.drawerCallback != null) widget.drawerCallback?.call(true);
widget.drawerCallback!(true);
} }
/// Starts an animation to close the drawer. /// Starts an animation to close the drawer.
void close() { void close() {
_controller.fling(velocity: -1.0); _controller.fling(velocity: -1.0);
if (widget.drawerCallback != null) widget.drawerCallback?.call(false);
widget.drawerCallback!(false);
} }
late ColorTween _scrimColorTween; late ColorTween _scrimColorTween;
......
...@@ -865,12 +865,11 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -865,12 +865,11 @@ class _InkResponseState extends State<_InkResponseStateWidget>
switch (type) { switch (type) {
case _HighlightType.pressed: case _HighlightType.pressed:
if (widget.onHighlightChanged != null) widget.onHighlightChanged?.call(value);
widget.onHighlightChanged!(value);
break; break;
case _HighlightType.hover: case _HighlightType.hover:
if (callOnHover && widget.onHover != null) if (callOnHover)
widget.onHover!(value); widget.onHover?.call(value);
break; break;
case _HighlightType.focus: case _HighlightType.focus:
break; break;
...@@ -951,18 +950,14 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -951,18 +950,14 @@ class _InkResponseState extends State<_InkResponseStateWidget>
void _handleFocusUpdate(bool hasFocus) { void _handleFocusUpdate(bool hasFocus) {
_hasFocus = hasFocus; _hasFocus = hasFocus;
_updateFocusHighlights(); _updateFocusHighlights();
if (widget.onFocusChange != null) { widget.onFocusChange?.call(hasFocus);
widget.onFocusChange!(hasFocus);
}
} }
void _handleTapDown(TapDownDetails details) { void _handleTapDown(TapDownDetails details) {
if (_anyChildInkResponsePressed) if (_anyChildInkResponsePressed)
return; return;
_startSplash(details: details); _startSplash(details: details);
if (widget.onTapDown != null) { widget.onTapDown?.call(details);
widget.onTapDown!(details);
}
} }
void _startSplash({TapDownDetails? details, BuildContext? context}) { void _startSplash({TapDownDetails? details, BuildContext? context}) {
...@@ -991,24 +986,21 @@ class _InkResponseState extends State<_InkResponseStateWidget> ...@@ -991,24 +986,21 @@ class _InkResponseState extends State<_InkResponseStateWidget>
if (widget.onTap != null) { if (widget.onTap != null) {
if (widget.enableFeedback) if (widget.enableFeedback)
Feedback.forTap(context); Feedback.forTap(context);
widget.onTap!(); widget.onTap?.call();
} }
} }
void _handleTapCancel() { void _handleTapCancel() {
_currentSplash?.cancel(); _currentSplash?.cancel();
_currentSplash = null; _currentSplash = null;
if (widget.onTapCancel != null) { widget.onTapCancel?.call();
widget.onTapCancel!();
}
updateHighlight(_HighlightType.pressed, value: false); updateHighlight(_HighlightType.pressed, value: false);
} }
void _handleDoubleTap() { void _handleDoubleTap() {
_currentSplash?.confirm(); _currentSplash?.confirm();
_currentSplash = null; _currentSplash = null;
if (widget.onDoubleTap != null) widget.onDoubleTap?.call();
widget.onDoubleTap!();
} }
void _handleLongPress() { void _handleLongPress() {
......
...@@ -94,8 +94,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur ...@@ -94,8 +94,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur
break; break;
} }
} }
if (_state.widget.onTap != null) _state.widget.onTap?.call();
_state.widget.onTap!();
} }
@override @override
......
...@@ -176,8 +176,7 @@ class PaintingContext extends ClipContext { ...@@ -176,8 +176,7 @@ class PaintingContext extends ClipContext {
assert(() { assert(() {
if (debugProfilePaintsEnabled) if (debugProfilePaintsEnabled)
Timeline.startSync('${child.runtimeType}', arguments: timelineArgumentsIndicatingLandmarkEvent); Timeline.startSync('${child.runtimeType}', arguments: timelineArgumentsIndicatingLandmarkEvent);
if (debugOnProfilePaint != null) debugOnProfilePaint?.call(child);
debugOnProfilePaint!(child);
return true; return true;
}()); }());
...@@ -830,8 +829,7 @@ class PipelineOwner { ...@@ -830,8 +829,7 @@ class PipelineOwner {
/// Used to notify the pipeline owner that an associated render object wishes /// Used to notify the pipeline owner that an associated render object wishes
/// to update its visual appearance. /// to update its visual appearance.
void requestVisualUpdate() { void requestVisualUpdate() {
if (onNeedVisualUpdate != null) onNeedVisualUpdate?.call();
onNeedVisualUpdate!();
} }
/// The unique object managed by this pipeline that has no parent. /// The unique object managed by this pipeline that has no parent.
...@@ -1029,8 +1027,7 @@ class PipelineOwner { ...@@ -1029,8 +1027,7 @@ class PipelineOwner {
if (_outstandingSemanticsHandles == 1) { if (_outstandingSemanticsHandles == 1) {
assert(_semanticsOwner == null); assert(_semanticsOwner == null);
_semanticsOwner = SemanticsOwner(); _semanticsOwner = SemanticsOwner();
if (onSemanticsOwnerCreated != null) onSemanticsOwnerCreated?.call();
onSemanticsOwnerCreated!();
} }
return SemanticsHandle._(this, listener); return SemanticsHandle._(this, listener);
} }
...@@ -1041,8 +1038,7 @@ class PipelineOwner { ...@@ -1041,8 +1038,7 @@ class PipelineOwner {
if (_outstandingSemanticsHandles == 0) { if (_outstandingSemanticsHandles == 0) {
_semanticsOwner!.dispose(); _semanticsOwner!.dispose();
_semanticsOwner = null; _semanticsOwner = null;
if (onSemanticsOwnerDisposed != null) onSemanticsOwnerDisposed?.call();
onSemanticsOwnerDisposed!();
} }
} }
......
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