Unverified Commit 224e6aa1 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Remove unnecessary null checks in flutter/gestures (#118926)

parent 90ffb1c6
......@@ -266,7 +266,6 @@ class GestureArenaManager {
void _resolveInFavorOf(int pointer, _GestureArena state, GestureArenaMember member) {
assert(state == _arenas[pointer]);
assert(state != null);
assert(state.eagerWinner == null || state.eagerWinner == member);
assert(!state.isOpen);
_arenas.remove(pointer);
......
......@@ -83,8 +83,6 @@ class _Resampler {
// Add `event` for resampling or dispatch it directly if
// not a touch event.
void addOrDispatch(PointerEvent event) {
final SchedulerBinding scheduler = SchedulerBinding.instance;
assert(scheduler != null);
// Add touch event to resampler or dispatch pointer event directly.
if (event.kind == PointerDeviceKind.touch) {
// Save last event time for debugPrint of resampling margin.
......@@ -108,7 +106,6 @@ class _Resampler {
// The `samplingClock` is the clock used to determine frame time age.
void sample(Duration samplingOffset, SamplingClock clock) {
final SchedulerBinding scheduler = SchedulerBinding.instance;
assert(scheduler != null);
// Initialize `_frameTime` if needed. This will be used for periodic
// sampling when frame callbacks are not received.
......@@ -391,7 +388,6 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
if (hitTestResult != null ||
event is PointerAddedEvent ||
event is PointerRemovedEvent) {
assert(event.position != null);
dispatchEvent(event, hitTestResult);
}
}
......
......@@ -54,7 +54,6 @@ class PointerEventConverter {
.where((ui.PointerData datum) => datum.signalKind != ui.PointerSignalKind.unknown)
.map((ui.PointerData datum) {
final Offset position = Offset(datum.physicalX, datum.physicalY) / devicePixelRatio;
assert(position != null);
final Offset delta = Offset(datum.physicalDeltaX, datum.physicalDeltaY) / devicePixelRatio;
final double radiusMinor = _toLogicalPixels(datum.radiusMinor, devicePixelRatio);
final double radiusMajor = _toLogicalPixels(datum.radiusMajor, devicePixelRatio);
......@@ -62,7 +61,6 @@ class PointerEventConverter {
final double radiusMax = _toLogicalPixels(datum.radiusMax, devicePixelRatio);
final Duration timeStamp = datum.timeStamp;
final PointerDeviceKind kind = datum.kind;
assert(datum.change != null);
switch (datum.signalKind ?? ui.PointerSignalKind.none) {
case ui.PointerSignalKind.none:
switch (datum.change) {
......
......@@ -25,8 +25,7 @@ class DragDownDetails {
DragDownDetails({
this.globalPosition = Offset.zero,
Offset? localPosition,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the pointer contacted the screen.
///
......@@ -73,8 +72,7 @@ class DragStartDetails {
this.globalPosition = Offset.zero,
Offset? localPosition,
this.kind,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// Recorded timestamp of the source pointer event that triggered the drag
/// event.
......@@ -142,8 +140,7 @@ class DragUpdateDetails {
this.primaryDelta,
required this.globalPosition,
Offset? localPosition,
}) : assert(delta != null),
assert(
}) : assert(
primaryDelta == null
|| (primaryDelta == delta.dx && delta.dy == 0.0)
|| (primaryDelta == delta.dy && delta.dx == 0.0),
......@@ -223,8 +220,7 @@ class DragEndDetails {
DragEndDetails({
this.velocity = Velocity.zero,
this.primaryVelocity,
}) : assert(velocity != null),
assert(
}) : assert(
primaryVelocity == null
|| primaryVelocity == velocity.pixelsPerSecond.dx
|| primaryVelocity == velocity.pixelsPerSecond.dy,
......
......@@ -52,9 +52,7 @@ class ForcePressDetails {
required this.globalPosition,
Offset? localPosition,
required this.pressure,
}) : assert(globalPosition != null),
assert(pressure != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the function was called.
final Offset globalPosition;
......@@ -134,10 +132,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
super.kind,
super.supportedDevices,
super.allowedButtonsFilter,
}) : assert(startPressure != null),
assert(peakPressure != null),
assert(interpolation != null),
assert(peakPressure > startPressure);
}) : assert(peakPressure > startPressure);
/// A pointer is in contact with the screen and has just pressed with a force
/// exceeding the [startPressure]. Consequently, if there were other gesture
......
......@@ -215,7 +215,6 @@ class HitTestResult {
/// around this function for hit testing on [RenderBox]s.
@protected
void pushTransform(Matrix4 transform) {
assert(transform != null);
assert(
_debugVectorMoreOrLessEquals(transform.getRow(2), Vector4(0, 0, 1, 0)) &&
_debugVectorMoreOrLessEquals(transform.getColumn(2), Vector4(0, 0, 1, 0)),
......@@ -255,7 +254,6 @@ class HitTestResult {
/// around this function for hit testing on [RenderSliver]s.
@protected
void pushOffset(Offset offset) {
assert(offset != null);
_localTransforms.add(_OffsetTransformPart(offset));
}
......
......@@ -115,8 +115,7 @@ class LongPressDownDetails {
this.globalPosition = Offset.zero,
Offset? localPosition,
this.kind,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the pointer contacted the screen.
final Offset globalPosition;
......@@ -142,8 +141,7 @@ class LongPressStartDetails {
const LongPressStartDetails({
this.globalPosition = Offset.zero,
Offset? localPosition,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the pointer initially contacted the screen.
final Offset globalPosition;
......@@ -168,9 +166,7 @@ class LongPressMoveUpdateDetails {
Offset? localPosition,
this.offsetFromOrigin = Offset.zero,
Offset? localOffsetFromOrigin,
}) : assert(globalPosition != null),
assert(offsetFromOrigin != null),
localPosition = localPosition ?? globalPosition,
}) : localPosition = localPosition ?? globalPosition,
localOffsetFromOrigin = localOffsetFromOrigin ?? offsetFromOrigin;
/// The global position of the pointer when it triggered this update.
......@@ -205,8 +201,7 @@ class LongPressEndDetails {
this.globalPosition = Offset.zero,
Offset? localPosition,
this.velocity = Velocity.zero,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the pointer lifted from the screen.
final Offset globalPosition;
......
......@@ -84,7 +84,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
this.velocityTrackerBuilder = _defaultBuilder,
super.supportedDevices,
super.allowedButtonsFilter = _defaultButtonAcceptBehavior,
}) : assert(dragStartBehavior != null);
});
static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind);
......@@ -313,7 +313,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
event is PointerPanZoomStartEvent ||
event is PointerPanZoomUpdateEvent)) {
final VelocityTracker tracker = _velocityTrackers[event.pointer]!;
assert(tracker != null);
if (event is PointerPanZoomStartEvent) {
tracker.addPosition(event.timeStamp, Offset.zero);
} else if (event is PointerPanZoomUpdateEvent) {
......@@ -492,7 +491,6 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
}
final VelocityTracker tracker = _velocityTrackers[pointer]!;
assert(tracker != null);
final DragEndDetails details;
final String Function() debugReport;
......
......@@ -35,8 +35,7 @@ abstract class MultiDragPointerState {
///
/// The [initialPosition] argument must not be null.
MultiDragPointerState(this.initialPosition, this.kind, this.gestureSettings)
: assert(initialPosition != null),
_velocityTracker = VelocityTracker.withKind(kind);
: _velocityTracker = VelocityTracker.withKind(kind);
/// Device specific gesture configuration that should be preferred over
/// framework constants.
......@@ -133,7 +132,6 @@ abstract class MultiDragPointerState {
void _startDrag(Drag client) {
assert(_arenaEntry != null);
assert(_client == null);
assert(client != null);
assert(pendingDelta != null);
_client = client;
final DragUpdateDetails details = DragUpdateDetails(
......@@ -240,8 +238,6 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer {
@override
void addAllowedPointer(PointerDownEvent event) {
assert(_pointers != null);
assert(event.pointer != null);
assert(event.position != null);
assert(!_pointers!.containsKey(event.pointer));
final MultiDragPointerState state = createNewPointerState(event);
_pointers![event.pointer] = state;
......@@ -257,9 +253,6 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer {
void _handleEvent(PointerEvent event) {
assert(_pointers != null);
assert(event.pointer != null);
assert(event.timeStamp != null);
assert(event.position != null);
assert(_pointers!.containsKey(event.pointer));
final MultiDragPointerState state = _pointers![event.pointer]!;
if (event is PointerMoveEvent) {
......@@ -296,7 +289,6 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer {
Drag? _startDrag(Offset initialPosition, int pointer) {
assert(_pointers != null);
final MultiDragPointerState state = _pointers![pointer]!;
assert(state != null);
assert(state._pendingDelta != null);
Drag? drag;
if (onStart != null) {
......@@ -315,7 +307,6 @@ abstract class MultiDragGestureRecognizer extends GestureRecognizer {
assert(_pointers != null);
if (_pointers!.containsKey(pointer)) {
final MultiDragPointerState state = _pointers![pointer]!;
assert(state != null);
state.rejected();
_removeState(pointer);
} // else we already preemptively forgot about it (e.g. we got an up event)
......@@ -515,8 +506,7 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer {
}
class _DelayedPointerState extends MultiDragPointerState {
_DelayedPointerState(super.initialPosition, Duration delay, super.kind, super.deviceGestureSettings)
: assert(delay != null) {
_DelayedPointerState(super.initialPosition, Duration delay, super.kind, super.deviceGestureSettings) {
_timer = Timer(delay, _delayPassed);
}
......@@ -614,7 +604,7 @@ class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer {
super.kind,
super.supportedDevices,
super.allowedButtonsFilter,
}) : assert(delay != null);
});
/// The amount of time the pointer must remain in the same place for the drag
/// to be recognized.
......
......@@ -43,8 +43,7 @@ typedef GestureMultiTapCancelCallback = void Function(int pointer);
/// CountdownZoned tracks whether the specified duration has elapsed since
/// creation, honoring [Zone].
class _CountdownZoned {
_CountdownZoned({ required Duration duration })
: assert(duration != null) {
_CountdownZoned({ required Duration duration }) {
Timer(duration, _onTimeout);
}
......@@ -65,10 +64,7 @@ class _TapTracker {
required this.entry,
required Duration doubleTapMinTime,
required this.gestureSettings,
}) : assert(doubleTapMinTime != null),
assert(event != null),
assert(event.buttons != null),
pointer = event.pointer,
}) : pointer = event.pointer,
_initialGlobalPosition = event.position,
initialButtons = event.buttons,
_doubleTapMinTimeCountdown = _CountdownZoned(duration: doubleTapMinTime);
......@@ -684,8 +680,7 @@ class SerialTapCancelDetails {
/// The `count` argument must be greater than zero.
SerialTapCancelDetails({
this.count = 1,
}) : assert(count != null),
assert(count > 0);
}) : assert(count > 0);
/// The number of consecutive taps that were in progress when the gesture was
/// interrupted.
......
......@@ -64,8 +64,6 @@ class PointerSignalResolver {
/// See the documentation for the [PointerSignalResolver] class on when and
/// how this method should be used.
void register(PointerSignalEvent event, PointerSignalResolvedCallback callback) {
assert(event != null);
assert(callback != null);
assert(_currentEvent == null || _isSameEvent(_currentEvent!, event));
if (_firstRegisteredCallback != null) {
return;
......
......@@ -267,7 +267,6 @@ abstract class GestureRecognizer extends GestureArenaMember with DiagnosticableT
@protected
@pragma('vm:notify-debugger-on-exception')
T? invokeCallback<T>(String name, RecognizerCallback<T> callback, { String Function()? debugReport }) {
assert(callback != null);
T? result;
try {
assert(() {
......
......@@ -102,7 +102,7 @@ class ScaleStartDetails {
this.focalPoint = Offset.zero,
Offset? localFocalPoint,
this.pointerCount = 0,
}) : assert(focalPoint != null), localFocalPoint = localFocalPoint ?? focalPoint;
}) : localFocalPoint = localFocalPoint ?? focalPoint;
/// The initial focal point of the pointers in contact with the screen.
///
......@@ -151,12 +151,9 @@ class ScaleUpdateDetails {
this.rotation = 0.0,
this.pointerCount = 0,
this.focalPointDelta = Offset.zero,
}) : assert(focalPoint != null),
assert(focalPointDelta != null),
assert(scale != null && scale >= 0.0),
assert(horizontalScale != null && horizontalScale >= 0.0),
assert(verticalScale != null && verticalScale >= 0.0),
assert(rotation != null),
}) : assert(scale >= 0.0),
assert(horizontalScale >= 0.0),
assert(verticalScale >= 0.0),
localFocalPoint = localFocalPoint ?? focalPoint;
/// The amount the gesture's focal point has moved in the coordinate space of
......@@ -248,8 +245,7 @@ class ScaleEndDetails {
/// Creates details for [GestureScaleEndCallback].
///
/// The [velocity] argument must not be null.
ScaleEndDetails({ this.velocity = Velocity.zero, this.scaleVelocity = 0, this.pointerCount = 0 })
: assert(velocity != null);
ScaleEndDetails({ this.velocity = Velocity.zero, this.scaleVelocity = 0, this.pointerCount = 0 });
/// The velocity of the last pointer to be lifted off of the screen.
final Velocity velocity;
......@@ -279,7 +275,6 @@ typedef GestureScaleUpdateCallback = void Function(ScaleUpdateDetails details);
typedef GestureScaleEndCallback = void Function(ScaleEndDetails details);
bool _isFlingGesture(Velocity velocity) {
assert(velocity != null);
final double speedSquared = velocity.pixelsPerSecond.distanceSquared;
return speedSquared > kMinFlingVelocity * kMinFlingVelocity;
}
......@@ -299,9 +294,7 @@ class _LineBetweenPointers {
this.pointerStartId = 0,
this.pointerEndLocation = Offset.zero,
this.pointerEndId = 1,
}) : assert(pointerStartLocation != null && pointerEndLocation != null),
assert(pointerStartId != null && pointerEndId != null),
assert(pointerStartId != pointerEndId);
}) : assert(pointerStartId != pointerEndId);
// The location and the id of the pointer that marks the start of the line.
final Offset pointerStartLocation;
......@@ -338,7 +331,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
this.dragStartBehavior = DragStartBehavior.down,
this.trackpadScrollCausesScale = false,
this.trackpadScrollToScaleFactor = kDefaultTrackpadScrollToScaleFactor,
}) : assert(dragStartBehavior != null);
});
/// Determines what point is used as the starting point in all calculations
/// involving this gesture.
......
......@@ -32,8 +32,7 @@ class TapDownDetails {
this.globalPosition = Offset.zero,
Offset? localPosition,
this.kind,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the pointer contacted the screen.
final Offset globalPosition;
......@@ -71,8 +70,7 @@ class TapUpDetails {
required this.kind,
this.globalPosition = Offset.zero,
Offset? localPosition,
}) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition;
}) : localPosition = localPosition ?? globalPosition;
/// The global position at which the pointer contacted the screen.
final Offset globalPosition;
......@@ -206,7 +204,6 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
@override
void addAllowedPointer(PointerDownEvent event) {
assert(event != null);
if (state == GestureRecognizerState.ready) {
// If there is no result in the previous gesture arena,
// we ignore them and prepare to accept a new pointer.
......
......@@ -18,7 +18,7 @@ class Velocity {
/// The [pixelsPerSecond] argument must not be null.
const Velocity({
required this.pixelsPerSecond,
}) : assert(pixelsPerSecond != null);
});
/// A velocity that isn't moving at all.
static const Velocity zero = Velocity(pixelsPerSecond: Offset.zero);
......@@ -50,8 +50,8 @@ class Velocity {
/// If the magnitude of this Velocity is within the specified bounds then
/// just return this.
Velocity clampMagnitude(double minValue, double maxValue) {
assert(minValue != null && minValue >= 0.0);
assert(maxValue != null && maxValue >= 0.0 && maxValue >= minValue);
assert(minValue >= 0.0);
assert(maxValue >= 0.0 && maxValue >= minValue);
final double valueSquared = pixelsPerSecond.distanceSquared;
if (valueSquared > maxValue * maxValue) {
return Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * maxValue);
......@@ -97,10 +97,7 @@ class VelocityEstimate {
required this.confidence,
required this.duration,
required this.offset,
}) : assert(pixelsPerSecond != null),
assert(confidence != null),
assert(duration != null),
assert(offset != null);
});
/// The number of pixels per second of velocity in the x and y directions.
final Offset pixelsPerSecond;
......@@ -124,9 +121,7 @@ class VelocityEstimate {
}
class _PointAtTime {
const _PointAtTime(this.point, this.time)
: assert(point != null),
assert(time != null);
const _PointAtTime(this.point, this.time);
final Duration time;
final Offset point;
......
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