use null aware operators for function invocations (#79049)

This commit is contained in:
Alexandre Ardhuin 2021-03-26 17:34:03 +01:00 committed by GitHub
parent bc2c7954db
commit e384ca7979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 138 additions and 320 deletions

View file

@ -25,9 +25,7 @@ class CategoryMenuPage extends StatelessWidget {
GestureDetector( GestureDetector(
onTap: () { onTap: () {
model.setCategory(category); model.setCategory(category);
if (onCategoryTap != null) { onCategoryTap?.call();
onCategoryTap!();
}
}, },
child: model.selectedCategory == category child: model.selectedCategory == category
? Column( ? Column(

View file

@ -27,9 +27,7 @@ class ColorPicker extends StatelessWidget {
color: color, color: color,
selected: color == selectedColor, selected: color == selectedColor,
onTap: () { onTap: () {
if (onColorSelection != null) { onColorSelection?.call(color);
onColorSelection!(color);
}
}, },
); );
}).toList(), }).toList(),
@ -59,9 +57,7 @@ class _ColorPickerSwatch extends StatelessWidget {
child: RawMaterialButton( child: RawMaterialButton(
fillColor: color, fillColor: color,
onPressed: () { onPressed: () {
if (onTap != null) { onTap?.call();
onTap!();
}
}, },
child: !selected ? null : const Icon( child: !selected ? null : const Icon(
Icons.check, Icons.check,

View file

@ -392,9 +392,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Handle the start of a gesture of _GestureType. // Handle the start of a gesture of _GestureType.
void _onScaleStart(ScaleStartDetails details) { void _onScaleStart(ScaleStartDetails details) {
if (widget.onScaleStart != null) { widget.onScaleStart?.call(details);
widget.onScaleStart!(details);
}
if (_controller.isAnimating) { if (_controller.isAnimating) {
_controller.stop(); _controller.stop();
@ -417,13 +415,11 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Handle an update to an ongoing gesture of _GestureType. // Handle an update to an ongoing gesture of _GestureType.
void _onScaleUpdate(ScaleUpdateDetails details) { void _onScaleUpdate(ScaleUpdateDetails details) {
double scale = _transform.getMaxScaleOnAxis(); double scale = _transform.getMaxScaleOnAxis();
if (widget.onScaleUpdate != null) { widget.onScaleUpdate?.call(ScaleUpdateDetails(
widget.onScaleUpdate!(ScaleUpdateDetails( focalPoint: fromViewport(details.focalPoint, _transform),
focalPoint: fromViewport(details.focalPoint, _transform), scale: details.scale,
scale: details.scale, rotation: details.rotation,
rotation: details.rotation, ));
));
}
final Offset focalPointScene = fromViewport( final Offset focalPointScene = fromViewport(
details.focalPoint, details.focalPoint,
_transform, _transform,
@ -476,9 +472,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Handle the end of a gesture of _GestureType. // Handle the end of a gesture of _GestureType.
void _onScaleEnd(ScaleEndDetails details) { void _onScaleEnd(ScaleEndDetails details) {
if (widget.onScaleEnd != null) { widget.onScaleEnd?.call(details);
widget.onScaleEnd!(details);
}
setState(() { setState(() {
_scaleStart = null; _scaleStart = null;
_rotationStart = null; _rotationStart = null;

View file

@ -255,9 +255,7 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
HapticFeedback.selectionClick(); HapticFeedback.selectionClick();
} }
if (widget.onSelectedItemChanged != null) { widget.onSelectedItemChanged?.call(index);
widget.onSelectedItemChanged!(index);
}
} }
/// Draws the selectionOverlay. /// Draws the selectionOverlay.

View file

@ -475,18 +475,14 @@ class _RenderCupertinoSlider extends RenderConstrainedBox {
void _startInteraction(Offset globalPosition) { void _startInteraction(Offset globalPosition) {
if (isInteractive) { if (isInteractive) {
if (onChangeStart != null) { onChangeStart?.call(_discretizedCurrentDragValue);
onChangeStart!(_discretizedCurrentDragValue);
}
_currentDragValue = _value; _currentDragValue = _value;
onChanged!(_discretizedCurrentDragValue); onChanged!(_discretizedCurrentDragValue);
} }
} }
void _endInteraction() { void _endInteraction() {
if (onChangeEnd != null) { onChangeEnd?.call(_discretizedCurrentDragValue);
onChangeEnd!(_discretizedCurrentDragValue);
}
_currentDragValue = 0.0; _currentDragValue = 0.0;
} }

View file

@ -116,8 +116,7 @@ class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGe
} }
super.onSingleTapUp(details); super.onSingleTapUp(details);
_state._requestKeyboard(); _state._requestKeyboard();
if (_state.widget.onTap != null) _state.widget.onTap?.call();
_state.widget.onTap!();
} }
@override @override

View file

@ -1104,9 +1104,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
static void reportError(FlutterErrorDetails details) { static void reportError(FlutterErrorDetails details) {
assert(details != null); assert(details != null);
assert(details.exception != null); assert(details.exception != null);
if (onError != null) { onError?.call(details);
onError!(details);
}
} }
} }

View file

@ -193,9 +193,7 @@ class _BottomSheetState extends State<BottomSheet> {
bool get _dismissUnderway => widget.animationController!.status == AnimationStatus.reverse; bool get _dismissUnderway => widget.animationController!.status == AnimationStatus.reverse;
void _handleDragStart(DragStartDetails details) { void _handleDragStart(DragStartDetails details) {
if (widget.onDragStart != null) { widget.onDragStart?.call(details);
widget.onDragStart!(details);
}
} }
void _handleDragUpdate(DragUpdateDetails details) { void _handleDragUpdate(DragUpdateDetails details) {
@ -226,12 +224,10 @@ class _BottomSheetState extends State<BottomSheet> {
widget.animationController!.forward(); widget.animationController!.forward();
} }
if (widget.onDragEnd != null) { widget.onDragEnd?.call(
widget.onDragEnd!( details,
details, isClosing: isClosing,
isClosing: isClosing, );
);
}
if (isClosing) { if (isClosing) {
widget.onClosing(); widget.onClosing();

View file

@ -330,9 +330,7 @@ class _RawMaterialButtonState extends State<RawMaterialButton> {
if (_pressed != value) { if (_pressed != value) {
setState(() { setState(() {
_updateState(MaterialState.pressed, value); _updateState(MaterialState.pressed, value);
if (widget.onHighlightChanged != null) { widget.onHighlightChanged?.call(value);
widget.onHighlightChanged!(value);
}
}); });
} }
} }

View file

@ -150,9 +150,7 @@ class _DropdownMenuItemButtonState<T> extends State<_DropdownMenuItemButton<T>>
void _handleOnTap() { void _handleOnTap() {
final DropdownMenuItem<T> dropdownMenuItem = widget.route.items[widget.itemIndex].item!; final DropdownMenuItem<T> dropdownMenuItem = widget.route.items[widget.itemIndex].item!;
if (dropdownMenuItem.onTap != null) { dropdownMenuItem.onTap?.call();
dropdownMenuItem.onTap!();
}
Navigator.pop( Navigator.pop(
context, context,
@ -1270,13 +1268,10 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
_removeDropdownRoute(); _removeDropdownRoute();
if (!mounted || newValue == null) if (!mounted || newValue == null)
return; return;
if (widget.onChanged != null) widget.onChanged?.call(newValue.result);
widget.onChanged!(newValue.result);
}); });
if (widget.onTap != null) { widget.onTap?.call();
widget.onTap!();
}
} }
// When isDense is true, reduce the height of this button from _kMenuItemHeight to // When isDense is true, reduce the height of this button from _kMenuItemHeight to

View file

@ -137,8 +137,7 @@ class _ExpandIconState extends State<ExpandIcon> with SingleTickerProviderStateM
} }
void _handlePressed() { void _handlePressed() {
if (widget.onPressed != null) widget.onPressed?.call(widget.isExpanded);
widget.onPressed!(widget.isExpanded);
} }
/// Default icon colors and opacities for when [Theme.brightness] is set to /// Default icon colors and opacities for when [Theme.brightness] is set to

View file

@ -442,8 +442,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
} }
void _handlePressed(bool isExpanded, int index) { void _handlePressed(bool isExpanded, int index) {
if (widget.expansionCallback != null) widget.expansionCallback?.call(index, isExpanded);
widget.expansionCallback!(index, isExpanded);
if (widget._allowOnlyOnePanelOpen) { if (widget._allowOnlyOnePanelOpen) {
final ExpansionPanelRadio pressedChild = widget.children[index] as ExpansionPanelRadio; final ExpansionPanelRadio pressedChild = widget.children[index] as ExpansionPanelRadio;

View file

@ -241,8 +241,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
} }
PageStorage.of(context)?.writeState(context, _isExpanded); PageStorage.of(context)?.writeState(context, _isExpanded);
}); });
if (widget.onExpansionChanged != null) widget.onExpansionChanged?.call(_isExpanded);
widget.onExpansionChanged!(_isExpanded);
} }
Widget _buildChildren(BuildContext context, Widget? child) { Widget _buildChildren(BuildContext context, Widget? child) {

View file

@ -626,8 +626,7 @@ abstract class InkFeature {
return true; return true;
}()); }());
_controller._removeFeature(this); _controller._removeFeature(this);
if (onRemoved != null) onRemoved?.call();
onRemoved!();
} }
void _paint(Canvas canvas) { void _paint(Canvas canvas) {

View file

@ -1110,12 +1110,10 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
if (!mounted) if (!mounted)
return null; return null;
if (newValue == null) { if (newValue == null) {
if (widget.onCanceled != null) widget.onCanceled?.call();
widget.onCanceled!();
return null; return null;
} }
if (widget.onSelected != null) widget.onSelected?.call(newValue);
widget.onSelected!(newValue);
}); });
} }
} }

View file

@ -1131,9 +1131,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
} }
_updateLabelPainter(_lastThumbSelection!); _updateLabelPainter(_lastThumbSelection!);
if (onChangeStart != null) { onChangeStart?.call(currentValues);
onChangeStart!(currentValues);
}
onChanged!(_discretizeRangeValues(_newValues)); onChanged!(_discretizeRangeValues(_newValues));
@ -1202,9 +1200,7 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix
if (_active && _state.mounted && _lastThumbSelection != null) { if (_active && _state.mounted && _lastThumbSelection != null) {
final RangeValues discreteValues = _discretizeRangeValues(_newValues); final RangeValues discreteValues = _discretizeRangeValues(_newValues);
if (onChangeEnd != null) { onChangeEnd?.call(discreteValues);
onChangeEnd!(discreteValues);
}
_active = false; _active = false;
} }
_state.overlayController.reverse(); _state.overlayController.reverse();
@ -1710,12 +1706,8 @@ class _RenderValueIndicator extends RenderBox with RelayoutWhenSystemFontsChange
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (_state.paintBottomValueIndicator != null) { _state.paintBottomValueIndicator?.call(context, offset);
_state.paintBottomValueIndicator!(context, offset); _state.paintTopValueIndicator?.call(context, offset);
}
if (_state.paintTopValueIndicator != null) {
_state.paintTopValueIndicator!(context, offset);
}
} }
@override @override

View file

@ -1230,9 +1230,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
// We supply the *current* value as the start location, so that if we have // 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 tap, it consists of a call to onChangeStart with the previous value and
// a call to onChangeEnd with the new value. // a call to onChangeEnd with the new value.
if (onChangeStart != null) { onChangeStart?.call(_discretize(value));
onChangeStart!(_discretize(value));
}
_currentDragValue = _getValueFromGlobalPosition(globalPosition); _currentDragValue = _getValueFromGlobalPosition(globalPosition);
onChanged!(_discretize(_currentDragValue)); onChanged!(_discretize(_currentDragValue));
_state.overlayController.forward(); _state.overlayController.forward();
@ -1256,9 +1254,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
} }
if (_active && _state.mounted) { if (_active && _state.mounted) {
if (onChangeEnd != null) { onChangeEnd?.call(_discretize(_currentDragValue));
onChangeEnd!(_discretize(_currentDragValue));
}
_active = false; _active = false;
_currentDragValue = 0.0; _currentDragValue = 0.0;
_state.overlayController.reverse(); _state.overlayController.reverse();
@ -1584,9 +1580,7 @@ class _RenderValueIndicator extends RenderBox with RelayoutWhenSystemFontsChange
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (_state.paintValueIndicator != null) { _state.paintValueIndicator?.call(context, offset);
_state.paintValueIndicator!(context, offset);
}
} }
@override @override

View file

@ -648,8 +648,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
duration: kThemeAnimationDuration, duration: kThemeAnimationDuration,
); );
if (widget.onStepTapped != null) widget.onStepTapped?.call(i);
widget.onStepTapped!(i);
} : null, } : null,
canRequestFocus: widget.steps[i].state != StepState.disabled, canRequestFocus: widget.steps[i].state != StepState.disabled,
child: _buildVerticalHeader(i), child: _buildVerticalHeader(i),
@ -666,8 +665,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
for (int i = 0; i < widget.steps.length; i += 1) ...<Widget>[ for (int i = 0; i < widget.steps.length; i += 1) ...<Widget>[
InkResponse( InkResponse(
onTap: widget.steps[i].state != StepState.disabled ? () { onTap: widget.steps[i].state != StepState.disabled ? () {
if (widget.onStepTapped != null) widget.onStepTapped?.call(i);
widget.onStepTapped!(i);
} : null, } : null,
canRequestFocus: widget.steps[i].state != StepState.disabled, canRequestFocus: widget.steps[i].state != StepState.disabled,
child: Row( child: Row(

View file

@ -1123,9 +1123,7 @@ class _TabBarState extends State<TabBar> {
void _handleTap(int index) { void _handleTap(int index) {
assert(index >= 0 && index < widget.tabs.length); assert(index >= 0 && index < widget.tabs.length);
_controller!.animateTo(index); _controller!.animateTo(index);
if (widget.onTap != null) { widget.onTap?.call(index);
widget.onTap!(index);
}
} }
Widget _buildStyledTab(Widget child, bool selected, Animation<double> animation) { Widget _buildStyledTab(Widget child, bool selected, Animation<double> animation) {

View file

@ -114,8 +114,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
} }
} }
_state._requestKeyboard(); _state._requestKeyboard();
if (_state.widget.onTap != null) _state.widget.onTap?.call();
_state.widget.onTap!();
} }
@override @override

View file

@ -1074,9 +1074,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
_center = null; _center = null;
_animateTo(_getThetaForTime(widget.selectedTime)); _animateTo(_getThetaForTime(widget.selectedTime));
if (widget.mode == _TimePickerMode.hour) { if (widget.mode == _TimePickerMode.hour) {
if (widget.onHourSelected != null) { widget.onHourSelected?.call();
widget.onHourSelected!();
}
} }
} }
@ -1092,9 +1090,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
} else { } else {
_announceToAccessibility(context, localizations.formatDecimal(newTime.hourOfPeriod)); _announceToAccessibility(context, localizations.formatDecimal(newTime.hourOfPeriod));
} }
if (widget.onHourSelected != null) { widget.onHourSelected?.call();
widget.onHourSelected!();
}
} else { } else {
_announceToAccessibility(context, localizations.formatDecimal(newTime.minute)); _announceToAccessibility(context, localizations.formatDecimal(newTime.minute));
} }

View file

@ -534,9 +534,7 @@ void paintImage({
if (existingSizeInfo == null || existingSizeInfo.displaySizeInBytes < sizeInfo.displaySizeInBytes) { if (existingSizeInfo == null || existingSizeInfo.displaySizeInBytes < sizeInfo.displaySizeInBytes) {
_pendingImageSizeInfo[sizeInfo.source!] = sizeInfo; _pendingImageSizeInfo[sizeInfo.source!] = sizeInfo;
} }
if (debugOnPaintImage != null) { debugOnPaintImage?.call(sizeInfo);
debugOnPaintImage!(sizeInfo);
}
SchedulerBinding.instance!.addPostFrameCallback((Duration timeStamp) { SchedulerBinding.instance!.addPostFrameCallback((Duration timeStamp) {
_lastFrameImageSizeInfo = _pendingImageSizeInfo.values.toSet(); _lastFrameImageSizeInfo = _pendingImageSizeInfo.values.toSet();
if (_pendingImageSizeInfo.isEmpty) { if (_pendingImageSizeInfo.isEmpty) {

View file

@ -598,9 +598,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
if (nextSelection == selection && cause != SelectionChangedCause.keyboard && !focusingEmpty) { if (nextSelection == selection && cause != SelectionChangedCause.keyboard && !focusingEmpty) {
return; return;
} }
if (onSelectionChanged != null) { onSelectionChanged?.call(nextSelection, this, cause);
onSelectionChanged!(nextSelection, this, cause);
}
} }
static final Set<LogicalKeyboardKey> _movementKeys = <LogicalKeyboardKey>{ static final Set<LogicalKeyboardKey> _movementKeys = <LogicalKeyboardKey>{

View file

@ -4760,103 +4760,83 @@ class RenderSemanticsAnnotations extends RenderProxyBox {
} }
void _performTap() { void _performTap() {
if (onTap != null) onTap?.call();
onTap!();
} }
void _performLongPress() { void _performLongPress() {
if (onLongPress != null) onLongPress?.call();
onLongPress!();
} }
void _performDismiss() { void _performDismiss() {
if (onDismiss != null) onDismiss?.call();
onDismiss!();
} }
void _performScrollLeft() { void _performScrollLeft() {
if (onScrollLeft != null) onScrollLeft?.call();
onScrollLeft!();
} }
void _performScrollRight() { void _performScrollRight() {
if (onScrollRight != null) onScrollRight?.call();
onScrollRight!();
} }
void _performScrollUp() { void _performScrollUp() {
if (onScrollUp != null) onScrollUp?.call();
onScrollUp!();
} }
void _performScrollDown() { void _performScrollDown() {
if (onScrollDown != null) onScrollDown?.call();
onScrollDown!();
} }
void _performIncrease() { void _performIncrease() {
if (onIncrease != null) onIncrease?.call();
onIncrease!();
} }
void _performDecrease() { void _performDecrease() {
if (onDecrease != null) onDecrease?.call();
onDecrease!();
} }
void _performCopy() { void _performCopy() {
if (onCopy != null) onCopy?.call();
onCopy!();
} }
void _performCut() { void _performCut() {
if (onCut != null) onCut?.call();
onCut!();
} }
void _performPaste() { void _performPaste() {
if (onPaste != null) onPaste?.call();
onPaste!();
} }
void _performMoveCursorForwardByCharacter(bool extendSelection) { void _performMoveCursorForwardByCharacter(bool extendSelection) {
if (onMoveCursorForwardByCharacter != null) onMoveCursorForwardByCharacter?.call(extendSelection);
onMoveCursorForwardByCharacter!(extendSelection);
} }
void _performMoveCursorBackwardByCharacter(bool extendSelection) { void _performMoveCursorBackwardByCharacter(bool extendSelection) {
if (onMoveCursorBackwardByCharacter != null) onMoveCursorBackwardByCharacter?.call(extendSelection);
onMoveCursorBackwardByCharacter!(extendSelection);
} }
void _performMoveCursorForwardByWord(bool extendSelection) { void _performMoveCursorForwardByWord(bool extendSelection) {
if (onMoveCursorForwardByWord != null) onMoveCursorForwardByWord?.call(extendSelection);
onMoveCursorForwardByWord!(extendSelection);
} }
void _performMoveCursorBackwardByWord(bool extendSelection) { void _performMoveCursorBackwardByWord(bool extendSelection) {
if (onMoveCursorBackwardByWord != null) onMoveCursorBackwardByWord?.call(extendSelection);
onMoveCursorBackwardByWord!(extendSelection);
} }
void _performSetSelection(TextSelection selection) { void _performSetSelection(TextSelection selection) {
if (onSetSelection != null) onSetSelection?.call(selection);
onSetSelection!(selection);
} }
void _performSetText(String text) { void _performSetText(String text) {
if (onSetText != null) onSetText?.call(text);
onSetText!(text);
} }
void _performDidGainAccessibilityFocus() { void _performDidGainAccessibilityFocus() {
if (onDidGainAccessibilityFocus != null) onDidGainAccessibilityFocus?.call();
onDidGainAccessibilityFocus!();
} }
void _performDidLoseAccessibilityFocus() { void _performDidLoseAccessibilityFocus() {
if (onDidLoseAccessibilityFocus != null) onDidLoseAccessibilityFocus?.call();
onDidLoseAccessibilityFocus!();
} }
} }

View file

@ -6178,8 +6178,7 @@ class WidgetToRenderBoxAdapter extends LeafRenderObjectWidget {
@override @override
void updateRenderObject(BuildContext context, RenderBox renderObject) { void updateRenderObject(BuildContext context, RenderBox renderObject) {
if (onBuild != null) onBuild?.call();
onBuild!();
} }
} }

View file

@ -543,13 +543,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
void _handleResizeProgressChanged() { void _handleResizeProgressChanged() {
if (_resizeController!.isCompleted) { if (_resizeController!.isCompleted) {
if (widget.onDismissed != null) { widget.onDismissed?.call(_dismissDirection);
final DismissDirection direction = _dismissDirection;
widget.onDismissed!(direction);
}
} else { } else {
if (widget.onResize != null) widget.onResize?.call();
widget.onResize!();
} }
} }

View file

@ -576,8 +576,7 @@ class _DraggableState<T extends Object> extends State<Draggable<T>> {
widget.onDraggableCanceled!(velocity, offset); widget.onDraggableCanceled!(velocity, offset);
}, },
); );
if (widget.onDragStarted != null) widget.onDragStarted?.call();
widget.onDragStarted!();
return avatar; return avatar;
} }
@ -754,8 +753,7 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
_candidateAvatars.remove(avatar); _candidateAvatars.remove(avatar);
_rejectedAvatars.remove(avatar); _rejectedAvatars.remove(avatar);
}); });
if (widget.onLeave != null) widget.onLeave?.call(avatar.data as T?);
widget.onLeave!(avatar.data as T?);
} }
void didDrop(_DragAvatar<Object> avatar) { void didDrop(_DragAvatar<Object> avatar) {
@ -765,17 +763,14 @@ class _DragTargetState<T extends Object> extends State<DragTarget<T>> {
setState(() { setState(() {
_candidateAvatars.remove(avatar); _candidateAvatars.remove(avatar);
}); });
if (widget.onAccept != null) widget.onAccept?.call(avatar.data! as T);
widget.onAccept!(avatar.data! as T); widget.onAcceptWithDetails?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
if (widget.onAcceptWithDetails != null)
widget.onAcceptWithDetails!(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
} }
void didMove(_DragAvatar<Object> avatar) { void didMove(_DragAvatar<Object> avatar) {
if (!mounted) if (!mounted)
return; return;
if (widget.onMove != null) widget.onMove?.call(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
widget.onMove!(DragTargetDetails<T>(data: avatar.data! as T, offset: avatar._lastOffset!));
} }
@override @override
@ -937,8 +932,7 @@ class _DragAvatar<T extends Object> extends Drag {
_entry!.remove(); _entry!.remove();
_entry = null; _entry = null;
// TODO(ianh): consider passing _entry as well so the client can perform an animation. // TODO(ianh): consider passing _entry as well so the client can perform an animation.
if (onDragEnd != null) onDragEnd?.call(velocity ?? Velocity.zero, _lastOffset!, wasAccepted);
onDragEnd!(velocity ?? Velocity.zero, _lastOffset!, wasAccepted);
} }
Widget _build(BuildContext context) { Widget _build(BuildContext context) {

View file

@ -670,9 +670,7 @@ class _FocusState extends State<Focus> {
final bool hasPrimaryFocus = focusNode.hasPrimaryFocus; final bool hasPrimaryFocus = focusNode.hasPrimaryFocus;
final bool canRequestFocus = focusNode.canRequestFocus; final bool canRequestFocus = focusNode.canRequestFocus;
final bool descendantsAreFocusable = focusNode.descendantsAreFocusable; final bool descendantsAreFocusable = focusNode.descendantsAreFocusable;
if (widget.onFocusChange != null) { widget.onFocusChange?.call(focusNode.hasFocus);
widget.onFocusChange!(focusNode.hasFocus);
}
if (_hasPrimaryFocus != hasPrimaryFocus) { if (_hasPrimaryFocus != hasPrimaryFocus) {
setState(() { setState(() {
_hasPrimaryFocus = hasPrimaryFocus; _hasPrimaryFocus = hasPrimaryFocus;

View file

@ -167,9 +167,7 @@ class FormState extends State<Form> {
// Called when a form field has changed. This will cause all form fields // Called when a form field has changed. This will cause all form fields
// to rebuild, useful if form fields have interdependencies. // to rebuild, useful if form fields have interdependencies.
void _fieldDidChange() { void _fieldDidChange() {
if (widget.onChanged != null) widget.onChanged?.call();
widget.onChanged!();
_hasInteractedByUser = _fields _hasInteractedByUser = _fields
.any((FormFieldState<dynamic> field) => field._hasInteractedByUser); .any((FormFieldState<dynamic> field) => field._hasInteractedByUser);
@ -435,8 +433,7 @@ class FormFieldState<T> extends State<FormField<T>> {
/// Calls the [FormField]'s onSaved method with the current value. /// Calls the [FormField]'s onSaved method with the current value.
void save() { void save() {
if (widget.onSaved != null) widget.onSaved?.call(value);
widget.onSaved!(value);
} }
/// Resets the field to its initial value. /// Resets the field to its initial value.

View file

@ -4241,9 +4241,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
if (_lifecycleState != _ElementLifecycle.active || !_dirty) if (_lifecycleState != _ElementLifecycle.active || !_dirty)
return; return;
assert(() { assert(() {
if (debugOnRebuildDirtyWidget != null) { debugOnRebuildDirtyWidget?.call(this, _debugBuiltOnce);
debugOnRebuildDirtyWidget!(this, _debugBuiltOnce);
}
if (debugPrintRebuildDirtyWidgets) { if (debugPrintRebuildDirtyWidgets) {
if (!_debugBuiltOnce) { if (!_debugBuiltOnce) {
debugPrint('Building $this'); debugPrint('Building $this');

View file

@ -1332,12 +1332,9 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
return () { return () {
assert(tap != null); assert(tap != null);
if (tap.onTapDown != null) tap.onTapDown?.call(TapDownDetails());
tap.onTapDown!(TapDownDetails()); tap.onTapUp?.call(TapUpDetails(kind: PointerDeviceKind.unknown));
if (tap.onTapUp != null) tap.onTap?.call();
tap.onTapUp!(TapUpDetails(kind: PointerDeviceKind.unknown));
if (tap.onTap != null)
tap.onTap!();
}; };
} }
@ -1347,14 +1344,10 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
return null; return null;
return () { return () {
if (longPress.onLongPressStart != null) longPress.onLongPressStart?.call(const LongPressStartDetails());
longPress.onLongPressStart!(const LongPressStartDetails()); longPress.onLongPress?.call();
if (longPress.onLongPress != null) longPress.onLongPressEnd?.call(const LongPressEndDetails());
longPress.onLongPress!(); longPress.onLongPressUp?.call();
if (longPress.onLongPressEnd != null)
longPress.onLongPressEnd!(const LongPressEndDetails());
if (longPress.onLongPressUp != null)
longPress.onLongPressUp!();
}; };
} }
@ -1365,27 +1358,19 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
final GestureDragUpdateCallback? horizontalHandler = horizontal == null ? final GestureDragUpdateCallback? horizontalHandler = horizontal == null ?
null : null :
(DragUpdateDetails details) { (DragUpdateDetails details) {
if (horizontal.onDown != null) horizontal.onDown?.call(DragDownDetails());
horizontal.onDown!(DragDownDetails()); horizontal.onStart?.call(DragStartDetails());
if (horizontal.onStart != null) horizontal.onUpdate?.call(details);
horizontal.onStart!(DragStartDetails()); horizontal.onEnd?.call(DragEndDetails(primaryVelocity: 0.0));
if (horizontal.onUpdate != null)
horizontal.onUpdate!(details);
if (horizontal.onEnd != null)
horizontal.onEnd!(DragEndDetails(primaryVelocity: 0.0));
}; };
final GestureDragUpdateCallback? panHandler = pan == null ? final GestureDragUpdateCallback? panHandler = pan == null ?
null : null :
(DragUpdateDetails details) { (DragUpdateDetails details) {
if (pan.onDown != null) pan.onDown?.call(DragDownDetails());
pan.onDown!(DragDownDetails()); pan.onStart?.call(DragStartDetails());
if (pan.onStart != null) pan.onUpdate?.call(details);
pan.onStart!(DragStartDetails()); pan.onEnd?.call(DragEndDetails());
if (pan.onUpdate != null)
pan.onUpdate!(details);
if (pan.onEnd != null)
pan.onEnd!(DragEndDetails());
}; };
if (horizontalHandler == null && panHandler == null) if (horizontalHandler == null && panHandler == null)
@ -1405,27 +1390,19 @@ class _DefaultSemanticsGestureDelegate extends SemanticsGestureDelegate {
final GestureDragUpdateCallback? verticalHandler = vertical == null ? final GestureDragUpdateCallback? verticalHandler = vertical == null ?
null : null :
(DragUpdateDetails details) { (DragUpdateDetails details) {
if (vertical.onDown != null) vertical.onDown?.call(DragDownDetails());
vertical.onDown!(DragDownDetails()); vertical.onStart?.call(DragStartDetails());
if (vertical.onStart != null) vertical.onUpdate?.call(details);
vertical.onStart!(DragStartDetails()); vertical.onEnd?.call(DragEndDetails(primaryVelocity: 0.0));
if (vertical.onUpdate != null)
vertical.onUpdate!(details);
if (vertical.onEnd != null)
vertical.onEnd!(DragEndDetails(primaryVelocity: 0.0));
}; };
final GestureDragUpdateCallback? panHandler = pan == null ? final GestureDragUpdateCallback? panHandler = pan == null ?
null : null :
(DragUpdateDetails details) { (DragUpdateDetails details) {
if (pan.onDown != null) pan.onDown?.call(DragDownDetails());
pan.onDown!(DragDownDetails()); pan.onStart?.call(DragStartDetails());
if (pan.onStart != null) pan.onUpdate?.call(details);
pan.onStart!(DragStartDetails()); pan.onEnd?.call(DragEndDetails());
if (pan.onUpdate != null)
pan.onUpdate!(details);
if (pan.onEnd != null)
pan.onEnd!(DragEndDetails());
}; };
if (verticalHandler == null && panHandler == null) if (verticalHandler == null && panHandler == null)

View file

@ -370,8 +370,7 @@ abstract class ImplicitlyAnimatedWidgetState<T extends ImplicitlyAnimatedWidget>
_controller.addStatusListener((AnimationStatus status) { _controller.addStatusListener((AnimationStatus status) {
switch (status) { switch (status) {
case AnimationStatus.completed: case AnimationStatus.completed:
if (widget.onEnd != null) widget.onEnd?.call();
widget.onEnd!();
break; break;
case AnimationStatus.dismissed: case AnimationStatus.dismissed:
case AnimationStatus.forward: case AnimationStatus.forward:

View file

@ -228,8 +228,7 @@ class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer {
@protected @protected
@override @override
void handleTapUp({PointerDownEvent? down, PointerUpEvent? up}) { void handleTapUp({PointerDownEvent? down, PointerUpEvent? up}) {
if (onAnyTapUp != null) onAnyTapUp?.call();
onAnyTapUp!();
} }
@protected @protected

View file

@ -5968,9 +5968,7 @@ class RestorableRouteFuture<T> extends RestorableProperty<String?> {
_route?.restorationScopeId.removeListener(notifyListeners); _route?.restorationScopeId.removeListener(notifyListeners);
_route = null; _route = null;
notifyListeners(); notifyListeners();
if (onComplete != null) { onComplete?.call(result as T);
onComplete!(result as T);
}
}); });
} }

View file

@ -638,9 +638,7 @@ class _UiKitViewState extends State<UiKitView> {
controller.dispose(); controller.dispose();
return; return;
} }
if (widget.onPlatformViewCreated != null) { widget.onPlatformViewCreated?.call(id);
widget.onPlatformViewCreated!(id);
}
setState(() { _controller = controller; }); setState(() { _controller = controller; });
} }
} }

View file

@ -121,8 +121,7 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> {
} }
void _handleRawKeyEvent(RawKeyEvent event) { void _handleRawKeyEvent(RawKeyEvent event) {
if (widget.onKey != null) widget.onKey?.call(event);
widget.onKey!(event);
} }
@override @override

View file

@ -445,8 +445,7 @@ class LocalHistoryEntry {
} }
void _notifyRemoved() { void _notifyRemoved() {
if (onRemove != null) onRemove?.call();
onRemove!();
} }
} }

View file

@ -214,8 +214,7 @@ class HoldScrollActivity extends ScrollActivity implements ScrollHoldController
@override @override
void dispose() { void dispose() {
if (onHoldCanceled != null) onHoldCanceled?.call();
onHoldCanceled!();
super.dispose(); super.dispose();
} }
} }
@ -406,8 +405,7 @@ class ScrollDragController implements Drag {
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
_lastDetails = null; _lastDetails = null;
if (onDragCanceled != null) onDragCanceled?.call();
onDragCanceled!();
} }
/// The most recently observed [DragStartDetails], [DragUpdateDetails], or /// The most recently observed [DragStartDetails], [DragUpdateDetails], or

View file

@ -782,8 +782,7 @@ class _TextSelectionHandleOverlayState
} }
void _handleTap() { void _handleTap() {
if (widget.onSelectionHandleTapped != null) widget.onSelectionHandleTapped?.call();
widget.onSelectionHandleTapped!();
} }
@override @override
@ -1386,9 +1385,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
// The down handler is force-run on success of a single tap and optimistically // The down handler is force-run on success of a single tap and optimistically
// run before a long press success. // run before a long press success.
void _handleTapDown(TapDownDetails details) { void _handleTapDown(TapDownDetails details) {
if (widget.onTapDown != null) { widget.onTapDown?.call(details);
widget.onTapDown!(details);
}
// This isn't detected as a double tap gesture in the gesture recognizer // This isn't detected as a double tap gesture in the gesture recognizer
// because it's 2 single taps, each of which may do different things depending // because it's 2 single taps, each of which may do different things depending
// on whether it's a single tap, the first tap of a double tap, the second // on whether it's a single tap, the first tap of a double tap, the second
@ -1396,9 +1393,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
if (_doubleTapTimer != null && _isWithinDoubleTapTolerance(details.globalPosition)) { if (_doubleTapTimer != null && _isWithinDoubleTapTolerance(details.globalPosition)) {
// If there was already a previous tap, the second down hold/tap is a // If there was already a previous tap, the second down hold/tap is a
// double tap down. // double tap down.
if (widget.onDoubleTapDown != null) { widget.onDoubleTapDown?.call(details);
widget.onDoubleTapDown!(details);
}
_doubleTapTimer!.cancel(); _doubleTapTimer!.cancel();
_doubleTapTimeout(); _doubleTapTimeout();
@ -1408,9 +1403,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
void _handleTapUp(TapUpDetails details) { void _handleTapUp(TapUpDetails details) {
if (!_isDoubleTap) { if (!_isDoubleTap) {
if (widget.onSingleTapUp != null) { widget.onSingleTapUp?.call(details);
widget.onSingleTapUp!(details);
}
_lastTapOffset = details.globalPosition; _lastTapOffset = details.globalPosition;
_doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout); _doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout);
} }
@ -1418,9 +1411,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
} }
void _handleTapCancel() { void _handleTapCancel() {
if (widget.onSingleTapCancel != null) { widget.onSingleTapCancel?.call();
widget.onSingleTapCancel!();
}
} }
DragStartDetails? _lastDragStartDetails; DragStartDetails? _lastDragStartDetails;
@ -1430,9 +1421,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
void _handleDragStart(DragStartDetails details) { void _handleDragStart(DragStartDetails details) {
assert(_lastDragStartDetails == null); assert(_lastDragStartDetails == null);
_lastDragStartDetails = details; _lastDragStartDetails = details;
if (widget.onDragSelectionStart != null) { widget.onDragSelectionStart?.call(details);
widget.onDragSelectionStart!(details);
}
} }
void _handleDragUpdate(DragUpdateDetails details) { void _handleDragUpdate(DragUpdateDetails details) {
@ -1450,9 +1439,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
void _handleDragUpdateThrottled() { void _handleDragUpdateThrottled() {
assert(_lastDragStartDetails != null); assert(_lastDragStartDetails != null);
assert(_lastDragUpdateDetails != null); assert(_lastDragUpdateDetails != null);
if (widget.onDragSelectionUpdate != null) { widget.onDragSelectionUpdate?.call(_lastDragStartDetails!, _lastDragUpdateDetails!);
widget.onDragSelectionUpdate!(_lastDragStartDetails!, _lastDragUpdateDetails!);
}
_dragUpdateThrottleTimer = null; _dragUpdateThrottleTimer = null;
_lastDragUpdateDetails = null; _lastDragUpdateDetails = null;
} }
@ -1465,9 +1452,7 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
_dragUpdateThrottleTimer!.cancel(); _dragUpdateThrottleTimer!.cancel();
_handleDragUpdateThrottled(); _handleDragUpdateThrottled();
} }
if (widget.onDragSelectionEnd != null) { widget.onDragSelectionEnd?.call(details);
widget.onDragSelectionEnd!(details);
}
_dragUpdateThrottleTimer = null; _dragUpdateThrottleTimer = null;
_lastDragStartDetails = null; _lastDragStartDetails = null;
_lastDragUpdateDetails = null; _lastDragUpdateDetails = null;
@ -1476,13 +1461,11 @@ class _TextSelectionGestureDetectorState extends State<TextSelectionGestureDetec
void _forcePressStarted(ForcePressDetails details) { void _forcePressStarted(ForcePressDetails details) {
_doubleTapTimer?.cancel(); _doubleTapTimer?.cancel();
_doubleTapTimer = null; _doubleTapTimer = null;
if (widget.onForcePressStart != null) widget.onForcePressStart?.call(details);
widget.onForcePressStart!(details);
} }
void _forcePressEnded(ForcePressDetails details) { void _forcePressEnded(ForcePressDetails details) {
if (widget.onForcePressEnd != null) widget.onForcePressEnd?.call(details);
widget.onForcePressEnd!(details);
} }
void _handleLongPressStart(LongPressStartDetails details) { void _handleLongPressStart(LongPressStartDetails details) {

View file

@ -130,9 +130,7 @@ class PassiveGestureRecognizer extends OneSequenceGestureRecognizer {
@override @override
void acceptGesture(int pointer) { void acceptGesture(int pointer) {
if (onGestureAccepted != null) { onGestureAccepted?.call();
onGestureAccepted!();
}
} }
@override @override

View file

@ -89,8 +89,7 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation
@override @override
void handleEvent(PointerEvent event, HitTestEntry entry) { void handleEvent(PointerEvent event, HitTestEntry entry) {
if (event is PointerHoverEvent) if (event is PointerHoverEvent)
if (onHover != null) onHover?.call(event);
onHover!(event);
} }
} }

View file

@ -111,9 +111,7 @@ class _TestImageStreamCompleter extends ImageStreamCompleter {
}) { }) {
final List<ImageStreamListener> localListeners = listeners.toList(); final List<ImageStreamListener> localListeners = listeners.toList();
for (final ImageStreamListener listener in localListeners) { for (final ImageStreamListener listener in localListeners) {
if (listener.onError != null) { listener.onError?.call(exception, stackTrace);
listener.onError!(exception, stackTrace);
}
} }
} }
} }

View file

@ -2026,9 +2026,7 @@ class _TestImageStreamCompleter extends ImageStreamCompleter {
}) { }) {
final List<ImageStreamListener> localListeners = listeners.toList(); final List<ImageStreamListener> localListeners = listeners.toList();
for (final ImageStreamListener listener in localListeners) { for (final ImageStreamListener listener in localListeners) {
if (listener.onError != null) { listener.onError?.call(exception, stackTrace);
listener.onError!(exception, stackTrace);
}
} }
} }
} }

View file

@ -86,8 +86,7 @@ class Counter {
class Trigger { class Trigger {
VoidCallback? callback; VoidCallback? callback;
void fire() { void fire() {
if (callback != null) callback?.call();
callback!();
} }
} }

View file

@ -29,21 +29,13 @@ class HoverClient extends StatefulWidget {
class HoverClientState extends State<HoverClient> { class HoverClientState extends State<HoverClient> {
void _onExit(PointerExitEvent details) { void _onExit(PointerExitEvent details) {
if (widget.onExit != null) { widget.onExit?.call();
widget.onExit!(); widget.onHover?.call(false);
}
if (widget.onHover != null) {
widget.onHover!(false);
}
} }
void _onEnter(PointerEnterEvent details) { void _onEnter(PointerEnterEvent details) {
if (widget.onEnter != null) { widget.onEnter?.call();
widget.onEnter!(); widget.onHover?.call(true);
}
if (widget.onHover != null) {
widget.onHover!(true);
}
} }
@override @override

View file

@ -3587,22 +3587,19 @@ class RouteAnnouncementSpy extends Route<void> {
@override @override
void didChangeNext(Route<dynamic>? nextRoute) { void didChangeNext(Route<dynamic>? nextRoute) {
super.didChangeNext(nextRoute); super.didChangeNext(nextRoute);
if (onDidChangeNext != null) onDidChangeNext?.call(nextRoute);
onDidChangeNext!(nextRoute);
} }
@override @override
void didChangePrevious(Route<dynamic>? previousRoute) { void didChangePrevious(Route<dynamic>? previousRoute) {
super.didChangePrevious(previousRoute); super.didChangePrevious(previousRoute);
if (onDidChangePrevious != null) onDidChangePrevious?.call(previousRoute);
onDidChangePrevious!(previousRoute);
} }
@override @override
void didPopNext(Route<dynamic> nextRoute) { void didPopNext(Route<dynamic> nextRoute) {
super.didPopNext(nextRoute); super.didPopNext(nextRoute);
if (onDidPopNext != null) onDidPopNext?.call(nextRoute);
onDidPopNext!(nextRoute);
} }
} }
@ -3728,9 +3725,7 @@ class HeroControllerSpy extends HeroController {
OnObservation? onPushed; OnObservation? onPushed;
@override @override
void didPush(Route<dynamic>? route, Route<dynamic>? previousRoute) { void didPush(Route<dynamic>? route, Route<dynamic>? previousRoute) {
if (onPushed != null) { onPushed?.call(route, previousRoute);
onPushed!(route, previousRoute);
}
} }
} }

View file

@ -16,33 +16,26 @@ class TestObserver extends NavigatorObserver {
@override @override
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) { void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onPushed != null) { onPushed?.call(route, previousRoute);
onPushed!(route, previousRoute);
}
} }
@override @override
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) { void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onPopped != null) { onPopped?.call(route, previousRoute);
onPopped!(route, previousRoute);
}
} }
@override @override
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) { void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onRemoved != null) onRemoved?.call(route, previousRoute);
onRemoved!(route, previousRoute);
} }
@override @override
void didReplace({ Route<dynamic>? oldRoute, Route<dynamic>? newRoute }) { void didReplace({ Route<dynamic>? oldRoute, Route<dynamic>? newRoute }) {
if (onReplaced != null) onReplaced?.call(newRoute, oldRoute);
onReplaced!(newRoute, oldRoute);
} }
@override @override
void didStartUserGesture(Route<dynamic> route, Route<dynamic>? previousRoute) { void didStartUserGesture(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (onStartUserGesture != null) onStartUserGesture?.call(route, previousRoute);
onStartUserGesture!(route, previousRoute);
} }
} }

View file

@ -102,8 +102,7 @@ class TestTextInput {
case 'TextInput.clearClient': case 'TextInput.clearClient':
_client = 0; _client = 0;
_isVisible = false; _isVisible = false;
if (onCleared != null) onCleared?.call();
onCleared!();
break; break;
case 'TextInput.setEditingState': case 'TextInput.setEditingState':
editingState = methodCall.arguments as Map<String, dynamic>; editingState = methodCall.arguments as Map<String, dynamic>;