Avoiding using ! operator with call and cascade operator. Closes #1423 (#1499)

* Avoiding using ! operator with call and cascade operator. Closes #1423

* Format
pull/1503/head
Guillermo Bueno Vargas 1 year ago committed by GitHub
parent dc6724868f
commit 96f15ce7db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      lib/src/widgets/text_selection.dart

@ -498,9 +498,7 @@ class _TextSelectionHandleOverlayState
} }
void _handleTap() { void _handleTap() {
if (widget.onSelectionHandleTapped != null) { widget.onSelectionHandleTapped?.call();
widget.onSelectionHandleTapped!();
}
} }
@override @override
@ -756,9 +754,8 @@ class _EditorTextSelectionGestureDetectorState
// 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 // 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, // depending on whether it's a single tap, the first tap of a double tap,
@ -767,9 +764,8 @@ class _EditorTextSelectionGestureDetectorState
_isWithinDoubleTapTolerance(details.globalPosition)) { _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!(details); widget.onDoubleTapDown?.call(details);
}
_doubleTapTimer!.cancel(); _doubleTapTimer!.cancel();
_doubleTapTimeout(); _doubleTapTimeout();
@ -779,9 +775,7 @@ class _EditorTextSelectionGestureDetectorState
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);
} }
@ -789,21 +783,17 @@ class _EditorTextSelectionGestureDetectorState
} }
void _handleTapCancel() { void _handleTapCancel() {
if (widget.onSingleTapCancel != null) { widget.onSingleTapCancel?.call();
widget.onSingleTapCancel!();
}
} }
// added secondary tap function for mouse right click to show toolbar // added secondary tap function for mouse right click to show toolbar
void _handleSecondaryTapDown(TapDownDetails details) { void _handleSecondaryTapDown(TapDownDetails details) {
if (widget.onSecondaryTapDown != null) { if (widget.onSecondaryTapDown != null) {
widget.onSecondaryTapDown!(details); widget.onSecondaryTapDown?.call(details);
} }
if (_doubleTapTimer != null && if (_doubleTapTimer != null &&
_isWithinDoubleTapTolerance(details.globalPosition)) { _isWithinDoubleTapTolerance(details.globalPosition)) {
if (widget.onSecondaryDoubleTapDown != null) { widget.onSecondaryDoubleTapDown?.call(details);
widget.onSecondaryDoubleTapDown!(details);
}
_doubleTapTimer!.cancel(); _doubleTapTimer!.cancel();
_doubleTapTimeout(); _doubleTapTimeout();
@ -813,9 +803,7 @@ class _EditorTextSelectionGestureDetectorState
void _handleSecondaryTapUp(TapUpDetails details) { void _handleSecondaryTapUp(TapUpDetails details) {
if (!_isSecondaryDoubleTap) { if (!_isSecondaryDoubleTap) {
if (widget.onSecondarySingleTapUp != null) { widget.onSecondarySingleTapUp?.call(details);
widget.onSecondarySingleTapUp!(details);
}
_lastTapOffset = details.globalPosition; _lastTapOffset = details.globalPosition;
_doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout); _doubleTapTimer = Timer(kDoubleTapTimeout, _doubleTapTimeout);
} }
@ -823,9 +811,7 @@ class _EditorTextSelectionGestureDetectorState
} }
void _handleSecondaryTapCancel() { void _handleSecondaryTapCancel() {
if (widget.onSecondarySingleTapCancel != null) { widget.onSecondarySingleTapCancel?.call();
widget.onSecondarySingleTapCancel!();
}
} }
DragStartDetails? _lastDragStartDetails; DragStartDetails? _lastDragStartDetails;
@ -835,9 +821,7 @@ class _EditorTextSelectionGestureDetectorState
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) {
@ -874,9 +858,9 @@ class _EditorTextSelectionGestureDetectorState
_dragUpdateThrottleTimer!.cancel(); _dragUpdateThrottleTimer!.cancel();
_handleDragUpdateThrottled(); _handleDragUpdateThrottled();
} }
if (widget.onDragSelectionEnd != null) {
widget.onDragSelectionEnd!(details); widget.onDragSelectionEnd?.call(details);
}
_dragUpdateThrottleTimer = null; _dragUpdateThrottleTimer = null;
_lastDragStartDetails = null; _lastDragStartDetails = null;
_lastDragUpdateDetails = null; _lastDragUpdateDetails = null;
@ -885,32 +869,30 @@ class _EditorTextSelectionGestureDetectorState
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) { if (widget.onForcePressEnd != null) {
widget.onForcePressEnd!(details); widget.onForcePressEnd?.call(details);
} }
} }
void _handleLongPressStart(LongPressStartDetails details) { void _handleLongPressStart(LongPressStartDetails details) {
if (!_isDoubleTap && widget.onSingleLongTapStart != null) { if (!_isDoubleTap) {
widget.onSingleLongTapStart!(details); widget.onSingleLongTapStart?.call(details);
} }
} }
void _handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) { void _handleLongPressMoveUpdate(LongPressMoveUpdateDetails details) {
if (!_isDoubleTap && widget.onSingleLongTapMoveUpdate != null) { if (!_isDoubleTap) {
widget.onSingleLongTapMoveUpdate!(details); widget.onSingleLongTapMoveUpdate?.call(details);
} }
} }
void _handleLongPressEnd(LongPressEndDetails details) { void _handleLongPressEnd(LongPressEndDetails details) {
if (!_isDoubleTap && widget.onSingleLongTapEnd != null) { if (!_isDoubleTap) {
widget.onSingleLongTapEnd!(details); widget.onSingleLongTapEnd?.call(details);
} }
_isDoubleTap = false; _isDoubleTap = false;
} }

Loading…
Cancel
Save