Unverified Commit 00dcd5f4 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

migrate gestures to nullsafety (#62157)

parent 1d5a9ae2
...@@ -126,6 +126,7 @@ Future<void> main(List<String> arguments) async { ...@@ -126,6 +126,7 @@ Future<void> main(List<String> arguments) async {
final List<String> dartdocArgs = <String>[ final List<String> dartdocArgs = <String>[
...dartdocBaseArgs, ...dartdocBaseArgs,
'--allow-tools', '--allow-tools',
'--enable-experiment=non-nullable',
if (args['json'] as bool) '--json', if (args['json'] as bool) '--json',
if (args['validate-links'] as bool) '--validate-links' else '--no-validate-links', if (args['validate-links'] as bool) '--validate-links' else '--no-validate-links',
'--link-to-source-excludes', '../../bin/cache', '--link-to-source-excludes', '../../bin/cache',
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
/// The Flutter gesture recognizers. /// The Flutter gesture recognizers.
/// ///
/// To use, import `package:flutter/gestures.dart`. /// To use, import `package:flutter/gestures.dart`.
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
...@@ -65,7 +64,7 @@ class _GestureArena { ...@@ -65,7 +64,7 @@ class _GestureArena {
/// "eager winner". We look for an eager winner when closing the arena to new /// "eager winner". We look for an eager winner when closing the arena to new
/// participants, and if there is one, we resolve the arena in its favor at /// participants, and if there is one, we resolve the arena in its favor at
/// that time. /// that time.
GestureArenaMember eagerWinner; GestureArenaMember? eagerWinner;
void add(GestureArenaMember member) { void add(GestureArenaMember member) {
assert(isOpen); assert(isOpen);
...@@ -119,7 +118,7 @@ class GestureArenaManager { ...@@ -119,7 +118,7 @@ class GestureArenaManager {
/// ///
/// Called after the framework has finished dispatching the pointer down event. /// Called after the framework has finished dispatching the pointer down event.
void close(int pointer) { void close(int pointer) {
final _GestureArena state = _arenas[pointer]; final _GestureArena? state = _arenas[pointer];
if (state == null) if (state == null)
return; // This arena either never existed or has been resolved. return; // This arena either never existed or has been resolved.
state.isOpen = false; state.isOpen = false;
...@@ -141,7 +140,7 @@ class GestureArenaManager { ...@@ -141,7 +140,7 @@ class GestureArenaManager {
/// * [hold] /// * [hold]
/// * [release] /// * [release]
void sweep(int pointer) { void sweep(int pointer) {
final _GestureArena state = _arenas[pointer]; final _GestureArena? state = _arenas[pointer];
if (state == null) if (state == null)
return; // This arena either never existed or has been resolved. return; // This arena either never existed or has been resolved.
assert(!state.isOpen); assert(!state.isOpen);
...@@ -175,7 +174,7 @@ class GestureArenaManager { ...@@ -175,7 +174,7 @@ class GestureArenaManager {
/// * [sweep] /// * [sweep]
/// * [release] /// * [release]
void hold(int pointer) { void hold(int pointer) {
final _GestureArena state = _arenas[pointer]; final _GestureArena? state = _arenas[pointer];
if (state == null) if (state == null)
return; // This arena either never existed or has been resolved. return; // This arena either never existed or has been resolved.
state.isHeld = true; state.isHeld = true;
...@@ -192,7 +191,7 @@ class GestureArenaManager { ...@@ -192,7 +191,7 @@ class GestureArenaManager {
/// * [sweep] /// * [sweep]
/// * [hold] /// * [hold]
void release(int pointer) { void release(int pointer) {
final _GestureArena state = _arenas[pointer]; final _GestureArena? state = _arenas[pointer];
if (state == null) if (state == null)
return; // This arena either never existed or has been resolved. return; // This arena either never existed or has been resolved.
state.isHeld = false; state.isHeld = false;
...@@ -205,7 +204,7 @@ class GestureArenaManager { ...@@ -205,7 +204,7 @@ class GestureArenaManager {
/// ///
/// This is called by calling [GestureArenaEntry.resolve] on the object returned from [add]. /// This is called by calling [GestureArenaEntry.resolve] on the object returned from [add].
void _resolve(int pointer, GestureArenaMember member, GestureDisposition disposition) { void _resolve(int pointer, GestureArenaMember member, GestureDisposition disposition) {
final _GestureArena state = _arenas[pointer]; final _GestureArena? state = _arenas[pointer];
if (state == null) if (state == null)
return; // This arena has already resolved. return; // This arena has already resolved.
assert(_debugLogDiagnostic(pointer, '${ disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting" }: $member')); assert(_debugLogDiagnostic(pointer, '${ disposition == GestureDisposition.accepted ? "Accepting" : "Rejecting" }: $member'));
...@@ -236,7 +235,7 @@ class GestureArenaManager { ...@@ -236,7 +235,7 @@ class GestureArenaManager {
assert(_debugLogDiagnostic(pointer, 'Arena empty.')); assert(_debugLogDiagnostic(pointer, 'Arena empty.'));
} else if (state.eagerWinner != null) { } else if (state.eagerWinner != null) {
assert(_debugLogDiagnostic(pointer, 'Eager winner: ${state.eagerWinner}')); assert(_debugLogDiagnostic(pointer, 'Eager winner: ${state.eagerWinner}'));
_resolveInFavorOf(pointer, state, state.eagerWinner); _resolveInFavorOf(pointer, state, state.eagerWinner!);
} }
} }
...@@ -265,10 +264,10 @@ class GestureArenaManager { ...@@ -265,10 +264,10 @@ class GestureArenaManager {
member.acceptGesture(pointer); member.acceptGesture(pointer);
} }
bool _debugLogDiagnostic(int pointer, String message, [ _GestureArena state ]) { bool _debugLogDiagnostic(int pointer, String message, [ _GestureArena? state ]) {
assert(() { assert(() {
if (debugPrintGestureArenaDiagnostics) { if (debugPrintGestureArenaDiagnostics) {
final int count = state != null ? state.members.length : null; final int? count = state != null ? state.members.length : null;
final String s = count != 1 ? 's' : ''; final String s = count != 1 ? 's' : '';
debugPrint('Gesture arena ${pointer.toString().padRight(4)}$message${ count != null ? " with $count member$s." : ""}'); debugPrint('Gesture arena ${pointer.toString().padRight(4)}$message${ count != null ? " with $count member$s." : ""}');
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'dart:collection'; import 'dart:collection';
...@@ -75,8 +74,8 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H ...@@ -75,8 +74,8 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
} }
/// The singleton instance of this object. /// The singleton instance of this object.
static GestureBinding get instance => _instance; static GestureBinding? get instance => _instance;
static GestureBinding _instance; static GestureBinding? _instance;
final Queue<PointerEvent> _pendingPointerEvents = Queue<PointerEvent>(); final Queue<PointerEvent> _pendingPointerEvents = Queue<PointerEvent>();
...@@ -123,7 +122,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H ...@@ -123,7 +122,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
void _handlePointerEvent(PointerEvent event) { void _handlePointerEvent(PointerEvent event) {
assert(!locked); assert(!locked);
HitTestResult hitTestResult; HitTestResult? hitTestResult;
if (event is PointerDownEvent || event is PointerSignalEvent) { if (event is PointerDownEvent || event is PointerSignalEvent) {
assert(!_hitTests.containsKey(event.pointer)); assert(!_hitTests.containsKey(event.pointer));
hitTestResult = HitTestResult(); hitTestResult = HitTestResult();
...@@ -172,7 +171,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H ...@@ -172,7 +171,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
/// might throw. The [hitTestResult] argument may only be null for /// might throw. The [hitTestResult] argument may only be null for
/// [PointerHoverEvent], [PointerAddedEvent], or [PointerRemovedEvent] events. /// [PointerHoverEvent], [PointerAddedEvent], or [PointerRemovedEvent] events.
@override // from HitTestDispatcher @override // from HitTestDispatcher
void dispatchEvent(PointerEvent event, HitTestResult hitTestResult) { void dispatchEvent(PointerEvent event, HitTestResult? hitTestResult) {
assert(!locked); assert(!locked);
// No hit test information implies that this is a hover or pointer // No hit test information implies that this is a hover or pointer
// add/remove event. // add/remove event.
...@@ -243,12 +242,12 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails { ...@@ -243,12 +242,12 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
/// that will subsequently be reported using [FlutterError.onError]. /// that will subsequently be reported using [FlutterError.onError].
const FlutterErrorDetailsForPointerEventDispatcher({ const FlutterErrorDetailsForPointerEventDispatcher({
dynamic exception, dynamic exception,
StackTrace stack, StackTrace? stack,
String library, String? library,
DiagnosticsNode context, DiagnosticsNode? context,
this.event, this.event,
this.hitTestEntry, this.hitTestEntry,
InformationCollector informationCollector, InformationCollector? informationCollector,
bool silent = false, bool silent = false,
}) : super( }) : super(
exception: exception, exception: exception,
...@@ -260,7 +259,7 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails { ...@@ -260,7 +259,7 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
); );
/// The pointer event that was being routed when the exception was raised. /// The pointer event that was being routed when the exception was raised.
final PointerEvent event; final PointerEvent? event;
/// The hit test result entry for the object whose handleEvent method threw /// The hit test result entry for the object whose handleEvent method threw
/// the exception. May be null if no hit test entry is associated with the /// the exception. May be null if no hit test entry is associated with the
...@@ -268,5 +267,5 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails { ...@@ -268,5 +267,5 @@ class FlutterErrorDetailsForPointerEventDispatcher extends FlutterErrorDetails {
/// ///
/// The target object itself is given by the [HitTestEntry.target] property of /// The target object itself is given by the [HitTestEntry.target] property of
/// the hitTestEntry object. /// the hitTestEntry object.
final HitTestEntry hitTestEntry; final HitTestEntry? hitTestEntry;
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
// Modeled after Android's ViewConfiguration: // Modeled after Android's ViewConfiguration:
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java // https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui show PointerData, PointerChange, PointerSignalKind; import 'dart:ui' as ui show PointerData, PointerChange, PointerSignalKind;
...@@ -214,7 +213,7 @@ class PointerEventConverter { ...@@ -214,7 +213,7 @@ class PointerEventConverter {
break; break;
} }
} else { } else {
switch (datum.signalKind) { switch (datum.signalKind!) {
case ui.PointerSignalKind.scroll: case ui.PointerSignalKind.scroll:
final Offset scrollDelta = final Offset scrollDelta =
Offset(datum.scrollDeltaX, datum.scrollDeltaY) / devicePixelRatio; Offset(datum.scrollDeltaX, datum.scrollDeltaY) / devicePixelRatio;
...@@ -238,6 +237,5 @@ class PointerEventConverter { ...@@ -238,6 +237,5 @@ class PointerEventConverter {
} }
} }
static double _toLogicalPixels(double physicalPixels, double devicePixelRatio) => static double _toLogicalPixels(double physicalPixels, double devicePixelRatio) => physicalPixels / devicePixelRatio;
physicalPixels == null ? null : physicalPixels / devicePixelRatio;
} }
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'drag_details.dart'; import 'drag_details.dart';
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show Offset; import 'dart:ui' show Offset;
...@@ -24,7 +23,7 @@ class DragDownDetails { ...@@ -24,7 +23,7 @@ class DragDownDetails {
/// The [globalPosition] argument must not be null. /// The [globalPosition] argument must not be null.
DragDownDetails({ DragDownDetails({
this.globalPosition = Offset.zero, this.globalPosition = Offset.zero,
Offset localPosition, Offset? localPosition,
}) : assert(globalPosition != null), }) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition; localPosition = localPosition ?? globalPosition;
...@@ -71,7 +70,7 @@ class DragStartDetails { ...@@ -71,7 +70,7 @@ class DragStartDetails {
DragStartDetails({ DragStartDetails({
this.sourceTimeStamp, this.sourceTimeStamp,
this.globalPosition = Offset.zero, this.globalPosition = Offset.zero,
Offset localPosition, Offset? localPosition,
}) : assert(globalPosition != null), }) : assert(globalPosition != null),
localPosition = localPosition ?? globalPosition; localPosition = localPosition ?? globalPosition;
...@@ -79,7 +78,7 @@ class DragStartDetails { ...@@ -79,7 +78,7 @@ class DragStartDetails {
/// event. /// event.
/// ///
/// Could be null if triggered from proxied events such as accessibility. /// Could be null if triggered from proxied events such as accessibility.
final Duration sourceTimeStamp; final Duration? sourceTimeStamp;
/// The global position at which the pointer contacted the screen. /// The global position at which the pointer contacted the screen.
/// ///
...@@ -134,8 +133,8 @@ class DragUpdateDetails { ...@@ -134,8 +133,8 @@ class DragUpdateDetails {
this.sourceTimeStamp, this.sourceTimeStamp,
this.delta = Offset.zero, this.delta = Offset.zero,
this.primaryDelta, this.primaryDelta,
@required this.globalPosition, required this.globalPosition,
Offset localPosition, Offset? localPosition,
}) : assert(delta != null), }) : assert(delta != null),
assert(primaryDelta == null assert(primaryDelta == null
|| (primaryDelta == delta.dx && delta.dy == 0.0) || (primaryDelta == delta.dx && delta.dy == 0.0)
...@@ -146,7 +145,7 @@ class DragUpdateDetails { ...@@ -146,7 +145,7 @@ class DragUpdateDetails {
/// event. /// event.
/// ///
/// Could be null if triggered from proxied events such as accessibility. /// Could be null if triggered from proxied events such as accessibility.
final Duration sourceTimeStamp; final Duration? sourceTimeStamp;
/// The amount the pointer has moved in the coordinate space of the event /// The amount the pointer has moved in the coordinate space of the event
/// receiver since the previous update. /// receiver since the previous update.
...@@ -169,7 +168,7 @@ class DragUpdateDetails { ...@@ -169,7 +168,7 @@ class DragUpdateDetails {
/// two-dimensional drag (e.g., a pan), then this value is null. /// two-dimensional drag (e.g., a pan), then this value is null.
/// ///
/// Defaults to null if not specified in the constructor. /// Defaults to null if not specified in the constructor.
final double primaryDelta; final double? primaryDelta;
/// The pointer's global position when it triggered this update. /// The pointer's global position when it triggered this update.
/// ///
...@@ -233,7 +232,7 @@ class DragEndDetails { ...@@ -233,7 +232,7 @@ class DragEndDetails {
/// two-dimensional drag (e.g., a pan), then this value is null. /// two-dimensional drag (e.g., a pan), then this value is null.
/// ///
/// Defaults to null if not specified in the constructor. /// Defaults to null if not specified in the constructor.
final double primaryVelocity; final double? primaryVelocity;
@override @override
String toString() => '${objectRuntimeType(this, 'DragEndDetails')}($velocity)'; String toString() => '${objectRuntimeType(this, 'DragEndDetails')}($velocity)';
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'arena.dart'; import 'arena.dart';
import 'events.dart'; import 'events.dart';
...@@ -17,7 +16,7 @@ class EagerGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -17,7 +16,7 @@ class EagerGestureRecognizer extends OneSequenceGestureRecognizer {
/// Create an eager gesture recognizer. /// Create an eager gesture recognizer.
/// ///
/// {@macro flutter.gestures.gestureRecognizer.kind} /// {@macro flutter.gestures.gestureRecognizer.kind}
EagerGestureRecognizer({ PointerDeviceKind kind }) : super(kind: kind); EagerGestureRecognizer({ PointerDeviceKind? kind }) : super(kind: kind);
@override @override
void addAllowedPointer(PointerDownEvent event) { void addAllowedPointer(PointerDownEvent event) {
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show Offset; import 'dart:ui' show Offset;
...@@ -51,9 +50,9 @@ class ForcePressDetails { ...@@ -51,9 +50,9 @@ class ForcePressDetails {
/// ///
/// The [globalPosition] argument must not be null. /// The [globalPosition] argument must not be null.
ForcePressDetails({ ForcePressDetails({
@required this.globalPosition, required this.globalPosition,
Offset localPosition, Offset? localPosition,
@required this.pressure, required this.pressure,
}) : assert(globalPosition != null), }) : assert(globalPosition != null),
assert(pressure != null), assert(pressure != null),
localPosition = localPosition ?? globalPosition; localPosition = localPosition ?? globalPosition;
...@@ -128,8 +127,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -128,8 +127,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
this.startPressure = 0.4, this.startPressure = 0.4,
this.peakPressure = 0.85, this.peakPressure = 0.85,
this.interpolation = _inverseLerp, this.interpolation = _inverseLerp,
Object debugOwner, Object? debugOwner,
PointerDeviceKind kind, PointerDeviceKind? kind,
}) : assert(startPressure != null), }) : assert(startPressure != null),
assert(peakPressure != null), assert(peakPressure != null),
assert(interpolation != null), assert(interpolation != null),
...@@ -143,7 +142,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -143,7 +142,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// ///
/// The position of the pointer is provided in the callback's `details` /// The position of the pointer is provided in the callback's `details`
/// argument, which is a [ForcePressDetails] object. /// argument, which is a [ForcePressDetails] object.
GestureForcePressStartCallback onStart; GestureForcePressStartCallback? onStart;
/// A pointer is in contact with the screen and is either moving on the plane /// A pointer is in contact with the screen and is either moving on the plane
/// of the screen, pressing the screen with varying forces or both /// of the screen, pressing the screen with varying forces or both
...@@ -154,7 +153,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -154,7 +153,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// matter what the pressure is during this time period. The position and /// matter what the pressure is during this time period. The position and
/// pressure of the pointer is provided in the callback's `details` argument, /// pressure of the pointer is provided in the callback's `details` argument,
/// which is a [ForcePressDetails] object. /// which is a [ForcePressDetails] object.
GestureForcePressUpdateCallback onUpdate; GestureForcePressUpdateCallback? onUpdate;
/// A pointer is in contact with the screen and has just pressed with a force /// A pointer is in contact with the screen and has just pressed with a force
/// exceeding the [peakPressure]. This is an arbitrary second level action /// exceeding the [peakPressure]. This is an arbitrary second level action
...@@ -163,13 +162,13 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -163,13 +162,13 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// ///
/// The position of the pointer is provided in the callback's `details` /// The position of the pointer is provided in the callback's `details`
/// argument, which is a [ForcePressDetails] object. /// argument, which is a [ForcePressDetails] object.
GestureForcePressPeakCallback onPeak; GestureForcePressPeakCallback? onPeak;
/// A pointer is no longer in contact with the screen. /// A pointer is no longer in contact with the screen.
/// ///
/// The position of the pointer is provided in the callback's `details` /// The position of the pointer is provided in the callback's `details`
/// argument, which is a [ForcePressDetails] object. /// argument, which is a [ForcePressDetails] object.
GestureForcePressEndCallback onEnd; GestureForcePressEndCallback? onEnd;
/// The pressure of the press required to initiate a force press. /// The pressure of the press required to initiate a force press.
/// ///
...@@ -209,8 +208,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -209,8 +208,8 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
/// ``` /// ```
final GestureForceInterpolation interpolation; final GestureForceInterpolation interpolation;
OffsetPair _lastPosition; late OffsetPair _lastPosition;
double _lastPressure; late double _lastPressure;
_ForceState _state = _ForceState.ready; _ForceState _state = _ForceState.ready;
@override @override
...@@ -264,7 +263,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -264,7 +263,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
if (pressure > startPressure && _state == _ForceState.accepted) { if (pressure > startPressure && _state == _ForceState.accepted) {
_state = _ForceState.started; _state = _ForceState.started;
if (onStart != null) { if (onStart != null) {
invokeCallback<void>('onStart', () => onStart(ForcePressDetails( invokeCallback<void>('onStart', () => onStart!(ForcePressDetails(
pressure: pressure, pressure: pressure,
globalPosition: _lastPosition.global, globalPosition: _lastPosition.global,
localPosition: _lastPosition.local, localPosition: _lastPosition.local,
...@@ -275,7 +274,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -275,7 +274,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
(_state == _ForceState.started)) { (_state == _ForceState.started)) {
_state = _ForceState.peaked; _state = _ForceState.peaked;
if (onPeak != null) { if (onPeak != null) {
invokeCallback<void>('onPeak', () => onPeak(ForcePressDetails( invokeCallback<void>('onPeak', () => onPeak!(ForcePressDetails(
pressure: pressure, pressure: pressure,
globalPosition: event.position, globalPosition: event.position,
localPosition: event.localPosition, localPosition: event.localPosition,
...@@ -285,7 +284,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -285,7 +284,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
if (onUpdate != null && !pressure.isNaN && if (onUpdate != null && !pressure.isNaN &&
(_state == _ForceState.started || _state == _ForceState.peaked)) { (_state == _ForceState.started || _state == _ForceState.peaked)) {
if (onUpdate != null) { if (onUpdate != null) {
invokeCallback<void>('onUpdate', () => onUpdate(ForcePressDetails( invokeCallback<void>('onUpdate', () => onUpdate!(ForcePressDetails(
pressure: pressure, pressure: pressure,
globalPosition: event.position, globalPosition: event.position,
localPosition: event.localPosition, localPosition: event.localPosition,
...@@ -302,7 +301,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -302,7 +301,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
_state = _ForceState.accepted; _state = _ForceState.accepted;
if (onStart != null && _state == _ForceState.started) { if (onStart != null && _state == _ForceState.started) {
invokeCallback<void>('onStart', () => onStart(ForcePressDetails( invokeCallback<void>('onStart', () => onStart!(ForcePressDetails(
pressure: _lastPressure, pressure: _lastPressure,
globalPosition: _lastPosition.global, globalPosition: _lastPosition.global,
localPosition: _lastPosition.local, localPosition: _lastPosition.local,
...@@ -319,7 +318,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -319,7 +318,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
} }
if (wasAccepted && onEnd != null) { if (wasAccepted && onEnd != null) {
if (onEnd != null) { if (onEnd != null) {
invokeCallback<void>('onEnd', () => onEnd(ForcePressDetails( invokeCallback<void>('onEnd', () => onEnd!(ForcePressDetails(
pressure: 0.0, pressure: 0.0,
globalPosition: _lastPosition.global, globalPosition: _lastPosition.global,
localPosition: _lastPosition.local, localPosition: _lastPosition.local,
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
...@@ -13,8 +12,7 @@ import 'events.dart'; ...@@ -13,8 +12,7 @@ import 'events.dart';
abstract class HitTestable { abstract class HitTestable {
// This class is intended to be used as an interface, and should not be // This class is intended to be used as an interface, and should not be
// extended directly; this constructor prevents instantiation and extension. // extended directly; this constructor prevents instantiation and extension.
// ignore: unused_element HitTestable._();
factory HitTestable._() => null;
/// Check whether the given position hits this object. /// Check whether the given position hits this object.
/// ///
...@@ -27,8 +25,7 @@ abstract class HitTestable { ...@@ -27,8 +25,7 @@ abstract class HitTestable {
abstract class HitTestDispatcher { abstract class HitTestDispatcher {
// This class is intended to be used as an interface, and should not be // This class is intended to be used as an interface, and should not be
// extended directly; this constructor prevents instantiation and extension. // extended directly; this constructor prevents instantiation and extension.
// ignore: unused_element HitTestDispatcher._();
factory HitTestDispatcher._() => null;
/// Override this method to dispatch events. /// Override this method to dispatch events.
void dispatchEvent(PointerEvent event, HitTestResult result); void dispatchEvent(PointerEvent event, HitTestResult result);
...@@ -38,8 +35,7 @@ abstract class HitTestDispatcher { ...@@ -38,8 +35,7 @@ abstract class HitTestDispatcher {
abstract class HitTestTarget { abstract class HitTestTarget {
// This class is intended to be used as an interface, and should not be // This class is intended to be used as an interface, and should not be
// extended directly; this constructor prevents instantiation and extension. // extended directly; this constructor prevents instantiation and extension.
// ignore: unused_element HitTestTarget._();
factory HitTestTarget._() => null;
/// Override this method to receive events. /// Override this method to receive events.
void handleEvent(PointerEvent event, HitTestEntry entry); void handleEvent(PointerEvent event, HitTestEntry entry);
...@@ -67,8 +63,8 @@ class HitTestEntry { ...@@ -67,8 +63,8 @@ class HitTestEntry {
/// ///
/// * [BoxHitTestResult.addWithPaintTransform], which is used during hit testing /// * [BoxHitTestResult.addWithPaintTransform], which is used during hit testing
/// to build up this transform. /// to build up this transform.
Matrix4 get transform => _transform; Matrix4? get transform => _transform;
Matrix4 _transform; Matrix4? _transform;
} }
// A type of data that can be applied to a matrix by left-multiplication. // A type of data that can be applied to a matrix by left-multiplication.
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:typed_data'; import 'dart:typed_data';
...@@ -76,7 +75,7 @@ class PolynomialFit { ...@@ -76,7 +75,7 @@ class PolynomialFit {
/// An indicator of the quality of the fit. /// An indicator of the quality of the fit.
/// ///
/// Larger values indicate greater quality. /// Larger values indicate greater quality.
double confidence; late double confidence;
} }
/// Uses the least-squares algorithm to fit a polynomial to a set of data. /// Uses the least-squares algorithm to fit a polynomial to a set of data.
...@@ -98,7 +97,9 @@ class LeastSquaresSolver { ...@@ -98,7 +97,9 @@ class LeastSquaresSolver {
final List<double> w; final List<double> w;
/// Fits a polynomial of the given degree to the data points. /// Fits a polynomial of the given degree to the data points.
PolynomialFit solve(int degree) { ///
/// When there is not enough data to fit a curve null is returned.
PolynomialFit? solve(int degree) {
if (degree > x.length) // Not enough data to fit a curve. if (degree > x.length) // Not enough data to fit a curve.
return null; return null;
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
...@@ -14,8 +13,8 @@ typedef PointerRoute = void Function(PointerEvent event); ...@@ -14,8 +13,8 @@ typedef PointerRoute = void Function(PointerEvent event);
/// A routing table for [PointerEvent] events. /// A routing table for [PointerEvent] events.
class PointerRouter { class PointerRouter {
final Map<int, Map<PointerRoute, Matrix4>> _routeMap = <int, Map<PointerRoute, Matrix4>>{}; final Map<int, Map<PointerRoute, Matrix4?>> _routeMap = <int, Map<PointerRoute, Matrix4?>>{};
final Map<PointerRoute, Matrix4> _globalRoutes = <PointerRoute, Matrix4>{}; final Map<PointerRoute, Matrix4?> _globalRoutes = <PointerRoute, Matrix4?>{};
/// Adds a route to the routing table. /// Adds a route to the routing table.
/// ///
...@@ -24,10 +23,10 @@ class PointerRouter { ...@@ -24,10 +23,10 @@ class PointerRouter {
/// ///
/// Routes added reentrantly within [PointerRouter.route] will take effect when /// Routes added reentrantly within [PointerRouter.route] will take effect when
/// routing the next event. /// routing the next event.
void addRoute(int pointer, PointerRoute route, [Matrix4 transform]) { void addRoute(int pointer, PointerRoute route, [Matrix4? transform]) {
final Map<PointerRoute, Matrix4> routes = _routeMap.putIfAbsent( final Map<PointerRoute, Matrix4?> routes = _routeMap.putIfAbsent(
pointer, pointer,
() => <PointerRoute, Matrix4>{}, () => <PointerRoute, Matrix4?>{},
); );
assert(!routes.containsKey(route)); assert(!routes.containsKey(route));
routes[route] = transform; routes[route] = transform;
...@@ -42,7 +41,7 @@ class PointerRouter { ...@@ -42,7 +41,7 @@ class PointerRouter {
/// immediately. /// immediately.
void removeRoute(int pointer, PointerRoute route) { void removeRoute(int pointer, PointerRoute route) {
assert(_routeMap.containsKey(pointer)); assert(_routeMap.containsKey(pointer));
final Map<PointerRoute, Matrix4> routes = _routeMap[pointer]; final Map<PointerRoute, Matrix4?> routes = _routeMap[pointer]!;
assert(routes.containsKey(route)); assert(routes.containsKey(route));
routes.remove(route); routes.remove(route);
if (routes.isEmpty) if (routes.isEmpty)
...@@ -55,7 +54,7 @@ class PointerRouter { ...@@ -55,7 +54,7 @@ class PointerRouter {
/// ///
/// Routes added reentrantly within [PointerRouter.route] will take effect when /// Routes added reentrantly within [PointerRouter.route] will take effect when
/// routing the next event. /// routing the next event.
void addGlobalRoute(PointerRoute route, [Matrix4 transform]) { void addGlobalRoute(PointerRoute route, [Matrix4? transform]) {
assert(!_globalRoutes.containsKey(route)); assert(!_globalRoutes.containsKey(route));
_globalRoutes[route] = transform; _globalRoutes[route] = transform;
} }
...@@ -72,12 +71,12 @@ class PointerRouter { ...@@ -72,12 +71,12 @@ class PointerRouter {
_globalRoutes.remove(route); _globalRoutes.remove(route);
} }
void _dispatch(PointerEvent event, PointerRoute route, Matrix4 transform) { void _dispatch(PointerEvent event, PointerRoute route, Matrix4? transform) {
try { try {
event = event.transformed(transform); event = event.transformed(transform);
route(event); route(event);
} catch (exception, stack) { } catch (exception, stack) {
InformationCollector collector; InformationCollector? collector;
assert(() { assert(() {
collector = () sync* { collector = () sync* {
yield DiagnosticsProperty<PointerRouter>('router', this, level: DiagnosticLevel.debug); yield DiagnosticsProperty<PointerRouter>('router', this, level: DiagnosticLevel.debug);
...@@ -101,13 +100,13 @@ class PointerRouter { ...@@ -101,13 +100,13 @@ class PointerRouter {
/// Routes are called in the order in which they were added to the /// Routes are called in the order in which they were added to the
/// PointerRouter object. /// PointerRouter object.
void route(PointerEvent event) { void route(PointerEvent event) {
final Map<PointerRoute, Matrix4> routes = _routeMap[event.pointer]; final Map<PointerRoute, Matrix4?>? routes = _routeMap[event.pointer];
final Map<PointerRoute, Matrix4> copiedGlobalRoutes = Map<PointerRoute, Matrix4>.from(_globalRoutes); final Map<PointerRoute, Matrix4?> copiedGlobalRoutes = Map<PointerRoute, Matrix4?>.from(_globalRoutes);
if (routes != null) { if (routes != null) {
_dispatchEventToRoutes( _dispatchEventToRoutes(
event, event,
routes, routes,
Map<PointerRoute, Matrix4>.from(routes), Map<PointerRoute, Matrix4?>.from(routes),
); );
} }
_dispatchEventToRoutes(event, _globalRoutes, copiedGlobalRoutes); _dispatchEventToRoutes(event, _globalRoutes, copiedGlobalRoutes);
...@@ -115,10 +114,10 @@ class PointerRouter { ...@@ -115,10 +114,10 @@ class PointerRouter {
void _dispatchEventToRoutes( void _dispatchEventToRoutes(
PointerEvent event, PointerEvent event,
Map<PointerRoute, Matrix4> referenceRoutes, Map<PointerRoute, Matrix4?> referenceRoutes,
Map<PointerRoute, Matrix4> copiedRoutes, Map<PointerRoute, Matrix4?> copiedRoutes,
) { ) {
copiedRoutes.forEach((PointerRoute route, Matrix4 transform) { copiedRoutes.forEach((PointerRoute route, Matrix4? transform) {
if (referenceRoutes.containsKey(route)) { if (referenceRoutes.containsKey(route)) {
_dispatch(event, route, transform); _dispatch(event, route, transform);
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -27,15 +26,15 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { ...@@ -27,15 +26,15 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
/// at the end of event dispatch. The first callback registered will be the one /// at the end of event dispatch. The first callback registered will be the one
/// that is called. /// that is called.
class PointerSignalResolver { class PointerSignalResolver {
PointerSignalResolvedCallback _firstRegisteredCallback; PointerSignalResolvedCallback? _firstRegisteredCallback;
PointerSignalEvent _currentEvent; PointerSignalEvent? _currentEvent;
/// Registers interest in handling [event]. /// Registers interest in handling [event].
void register(PointerSignalEvent event, PointerSignalResolvedCallback callback) { void register(PointerSignalEvent event, PointerSignalResolvedCallback callback) {
assert(event != null); assert(event != null);
assert(callback != null); assert(callback != null);
assert(_currentEvent == null || _isSameEvent(_currentEvent, event)); assert(_currentEvent == null || _isSameEvent(_currentEvent!, event));
if (_firstRegisteredCallback != null) { if (_firstRegisteredCallback != null) {
return; return;
} }
...@@ -53,11 +52,11 @@ class PointerSignalResolver { ...@@ -53,11 +52,11 @@ class PointerSignalResolver {
assert(_currentEvent == null); assert(_currentEvent == null);
return; return;
} }
assert(_isSameEvent(_currentEvent, event)); assert(_isSameEvent(_currentEvent!, event));
try { try {
_firstRegisteredCallback(_currentEvent); _firstRegisteredCallback!(_currentEvent!);
} catch (exception, stack) { } catch (exception, stack) {
InformationCollector collector; InformationCollector? collector;
assert(() { assert(() {
collector = () sync* { collector = () sync* {
yield DiagnosticsProperty<PointerSignalEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty); yield DiagnosticsProperty<PointerSignalEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math; import 'dart:math' as math;
...@@ -38,7 +37,7 @@ class ScaleStartDetails { ...@@ -38,7 +37,7 @@ class ScaleStartDetails {
/// Creates details for [GestureScaleStartCallback]. /// Creates details for [GestureScaleStartCallback].
/// ///
/// The [focalPoint] argument must not be null. /// The [focalPoint] argument must not be null.
ScaleStartDetails({ this.focalPoint = Offset.zero, Offset localFocalPoint, }) ScaleStartDetails({ this.focalPoint = Offset.zero, Offset? localFocalPoint, })
: assert(focalPoint != null), localFocalPoint = localFocalPoint ?? focalPoint; : assert(focalPoint != null), localFocalPoint = localFocalPoint ?? focalPoint;
/// The initial focal point of the pointers in contact with the screen. /// The initial focal point of the pointers in contact with the screen.
...@@ -75,7 +74,7 @@ class ScaleUpdateDetails { ...@@ -75,7 +74,7 @@ class ScaleUpdateDetails {
/// argument must be greater than or equal to zero. /// argument must be greater than or equal to zero.
ScaleUpdateDetails({ ScaleUpdateDetails({
this.focalPoint = Offset.zero, this.focalPoint = Offset.zero,
Offset localFocalPoint, Offset? localFocalPoint,
this.scale = 1.0, this.scale = 1.0,
this.horizontalScale = 1.0, this.horizontalScale = 1.0,
this.verticalScale = 1.0, this.verticalScale = 1.0,
...@@ -225,37 +224,37 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -225,37 +224,37 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
/// ///
/// {@macro flutter.gestures.gestureRecognizer.kind} /// {@macro flutter.gestures.gestureRecognizer.kind}
ScaleGestureRecognizer({ ScaleGestureRecognizer({
Object debugOwner, Object? debugOwner,
PointerDeviceKind kind, PointerDeviceKind? kind,
}) : super(debugOwner: debugOwner, kind: kind); }) : super(debugOwner: debugOwner, kind: kind);
/// The pointers in contact with the screen have established a focal point and /// The pointers in contact with the screen have established a focal point and
/// initial scale of 1.0. /// initial scale of 1.0.
GestureScaleStartCallback onStart; GestureScaleStartCallback? onStart;
/// The pointers in contact with the screen have indicated a new focal point /// The pointers in contact with the screen have indicated a new focal point
/// and/or scale. /// and/or scale.
GestureScaleUpdateCallback onUpdate; GestureScaleUpdateCallback? onUpdate;
/// The pointers are no longer in contact with the screen. /// The pointers are no longer in contact with the screen.
GestureScaleEndCallback onEnd; GestureScaleEndCallback? onEnd;
_ScaleState _state = _ScaleState.ready; _ScaleState _state = _ScaleState.ready;
Matrix4 _lastTransform; Matrix4? _lastTransform;
Offset _initialFocalPoint; late Offset _initialFocalPoint;
Offset _currentFocalPoint; late Offset _currentFocalPoint;
double _initialSpan; late double _initialSpan;
double _currentSpan; late double _currentSpan;
double _initialHorizontalSpan; late double _initialHorizontalSpan;
double _currentHorizontalSpan; late double _currentHorizontalSpan;
double _initialVerticalSpan; late double _initialVerticalSpan;
double _currentVerticalSpan; late double _currentVerticalSpan;
_LineBetweenPointers _initialLine; _LineBetweenPointers? _initialLine;
_LineBetweenPointers _currentLine; _LineBetweenPointers? _currentLine;
Map<int, Offset> _pointerLocations; late Map<int, Offset> _pointerLocations;
List<int> _pointerQueue; // A queue to sort pointers in order of entrance late List<int> _pointerQueue; // A queue to sort pointers in order of entrance
final Map<int, VelocityTracker> _velocityTrackers = <int, VelocityTracker>{}; final Map<int, VelocityTracker> _velocityTrackers = <int, VelocityTracker>{};
double get _scaleFactor => _initialSpan > 0.0 ? _currentSpan / _initialSpan : 1.0; double get _scaleFactor => _initialSpan > 0.0 ? _currentSpan / _initialSpan : 1.0;
...@@ -268,15 +267,15 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -268,15 +267,15 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if (_initialLine == null || _currentLine == null) { if (_initialLine == null || _currentLine == null) {
return 0.0; return 0.0;
} }
final double fx = _initialLine.pointerStartLocation.dx; final double fx = _initialLine!.pointerStartLocation.dx;
final double fy = _initialLine.pointerStartLocation.dy; final double fy = _initialLine!.pointerStartLocation.dy;
final double sx = _initialLine.pointerEndLocation.dx; final double sx = _initialLine!.pointerEndLocation.dx;
final double sy = _initialLine.pointerEndLocation.dy; final double sy = _initialLine!.pointerEndLocation.dy;
final double nfx = _currentLine.pointerStartLocation.dx; final double nfx = _currentLine!.pointerStartLocation.dx;
final double nfy = _currentLine.pointerStartLocation.dy; final double nfy = _currentLine!.pointerStartLocation.dy;
final double nsx = _currentLine.pointerEndLocation.dx; final double nsx = _currentLine!.pointerEndLocation.dx;
final double nsy = _currentLine.pointerEndLocation.dy; final double nsy = _currentLine!.pointerEndLocation.dy;
final double angle1 = math.atan2(fy - sy, fx - sx); final double angle1 = math.atan2(fy - sy, fx - sx);
final double angle2 = math.atan2(nfy - nsy, nfx - nsx); final double angle2 = math.atan2(nfy - nsy, nfx - nsx);
...@@ -307,8 +306,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -307,8 +306,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
bool didChangeConfiguration = false; bool didChangeConfiguration = false;
bool shouldStartIfAccepted = false; bool shouldStartIfAccepted = false;
if (event is PointerMoveEvent) { if (event is PointerMoveEvent) {
final VelocityTracker tracker = _velocityTrackers[event.pointer]; final VelocityTracker tracker = _velocityTrackers[event.pointer]!;
assert(tracker != null);
if (!event.synthesized) if (!event.synthesized)
tracker.addPosition(event.timeStamp, event.position); tracker.addPosition(event.timeStamp, event.position);
_pointerLocations[event.pointer] = event.position; _pointerLocations[event.pointer] = event.position;
...@@ -341,7 +339,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -341,7 +339,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
// Compute the focal point // Compute the focal point
Offset focalPoint = Offset.zero; Offset focalPoint = Offset.zero;
for (final int pointer in _pointerLocations.keys) for (final int pointer in _pointerLocations.keys)
focalPoint += _pointerLocations[pointer]; focalPoint += _pointerLocations[pointer]!;
_currentFocalPoint = count > 0 ? focalPoint / count.toDouble() : Offset.zero; _currentFocalPoint = count > 0 ? focalPoint / count.toDouble() : Offset.zero;
// Span is the average deviation from focal point. Horizontal and vertical // Span is the average deviation from focal point. Horizontal and vertical
...@@ -351,9 +349,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -351,9 +349,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
double totalHorizontalDeviation = 0.0; double totalHorizontalDeviation = 0.0;
double totalVerticalDeviation = 0.0; double totalVerticalDeviation = 0.0;
for (final int pointer in _pointerLocations.keys) { for (final int pointer in _pointerLocations.keys) {
totalDeviation += (_currentFocalPoint - _pointerLocations[pointer]).distance; totalDeviation += (_currentFocalPoint - _pointerLocations[pointer]!).distance;
totalHorizontalDeviation += (_currentFocalPoint.dx - _pointerLocations[pointer].dx).abs(); totalHorizontalDeviation += (_currentFocalPoint.dx - _pointerLocations[pointer]!.dx).abs();
totalVerticalDeviation += (_currentFocalPoint.dy - _pointerLocations[pointer].dy).abs(); totalVerticalDeviation += (_currentFocalPoint.dy - _pointerLocations[pointer]!.dy).abs();
} }
_currentSpan = count > 0 ? totalDeviation / count : 0.0; _currentSpan = count > 0 ? totalDeviation / count : 0.0;
_currentHorizontalSpan = count > 0 ? totalHorizontalDeviation / count : 0.0; _currentHorizontalSpan = count > 0 ? totalHorizontalDeviation / count : 0.0;
...@@ -369,22 +367,22 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -369,22 +367,22 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if (count < 2) { if (count < 2) {
_initialLine = _currentLine; _initialLine = _currentLine;
} else if (_initialLine != null && } else if (_initialLine != null &&
_initialLine.pointerStartId == _pointerQueue[0] && _initialLine!.pointerStartId == _pointerQueue[0] &&
_initialLine.pointerEndId == _pointerQueue[1]) { _initialLine!.pointerEndId == _pointerQueue[1]) {
/// Rotation updated, set the [_currentLine] /// Rotation updated, set the [_currentLine]
_currentLine = _LineBetweenPointers( _currentLine = _LineBetweenPointers(
pointerStartId: _pointerQueue[0], pointerStartId: _pointerQueue[0],
pointerStartLocation: _pointerLocations[_pointerQueue[0]], pointerStartLocation: _pointerLocations[_pointerQueue[0]]!,
pointerEndId: _pointerQueue[1], pointerEndId: _pointerQueue[1],
pointerEndLocation: _pointerLocations[_pointerQueue[1]], pointerEndLocation: _pointerLocations[_pointerQueue[1]]!,
); );
} else { } else {
/// A new rotation process is on the way, set the [_initialLine] /// A new rotation process is on the way, set the [_initialLine]
_initialLine = _LineBetweenPointers( _initialLine = _LineBetweenPointers(
pointerStartId: _pointerQueue[0], pointerStartId: _pointerQueue[0],
pointerStartLocation: _pointerLocations[_pointerQueue[0]], pointerStartLocation: _pointerLocations[_pointerQueue[0]]!,
pointerEndId: _pointerQueue[1], pointerEndId: _pointerQueue[1],
pointerEndLocation: _pointerLocations[_pointerQueue[1]], pointerEndLocation: _pointerLocations[_pointerQueue[1]]!,
); );
_currentLine = null; _currentLine = null;
} }
...@@ -398,17 +396,16 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -398,17 +396,16 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
_initialVerticalSpan = _currentVerticalSpan; _initialVerticalSpan = _currentVerticalSpan;
if (_state == _ScaleState.started) { if (_state == _ScaleState.started) {
if (onEnd != null) { if (onEnd != null) {
final VelocityTracker tracker = _velocityTrackers[pointer]; final VelocityTracker tracker = _velocityTrackers[pointer]!;
assert(tracker != null);
Velocity velocity = tracker.getVelocity(); Velocity velocity = tracker.getVelocity();
if (_isFlingGesture(velocity)) { if (_isFlingGesture(velocity)) {
final Offset pixelsPerSecond = velocity.pixelsPerSecond; final Offset pixelsPerSecond = velocity.pixelsPerSecond;
if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * kMaxFlingVelocity) if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * kMaxFlingVelocity)
velocity = Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * kMaxFlingVelocity); velocity = Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * kMaxFlingVelocity);
invokeCallback<void>('onEnd', () => onEnd(ScaleEndDetails(velocity: velocity))); invokeCallback<void>('onEnd', () => onEnd!(ScaleEndDetails(velocity: velocity)));
} else { } else {
invokeCallback<void>('onEnd', () => onEnd(ScaleEndDetails(velocity: Velocity.zero))); invokeCallback<void>('onEnd', () => onEnd!(ScaleEndDetails(velocity: Velocity.zero)));
} }
} }
_state = _ScaleState.accepted; _state = _ScaleState.accepted;
...@@ -437,7 +434,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -437,7 +434,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if (_state == _ScaleState.started && onUpdate != null) if (_state == _ScaleState.started && onUpdate != null)
invokeCallback<void>('onUpdate', () { invokeCallback<void>('onUpdate', () {
onUpdate(ScaleUpdateDetails( onUpdate!(ScaleUpdateDetails(
scale: _scaleFactor, scale: _scaleFactor,
horizontalScale: _horizontalScaleFactor, horizontalScale: _horizontalScaleFactor,
verticalScale: _verticalScaleFactor, verticalScale: _verticalScaleFactor,
...@@ -452,7 +449,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -452,7 +449,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
assert(_state == _ScaleState.started); assert(_state == _ScaleState.started);
if (onStart != null) if (onStart != null)
invokeCallback<void>('onStart', () { invokeCallback<void>('onStart', () {
onStart(ScaleStartDetails( onStart!(ScaleStartDetails(
focalPoint: _currentFocalPoint, focalPoint: _currentFocalPoint,
localFocalPoint: PointerEvent.transformPosition(_lastTransform, _currentFocalPoint), localFocalPoint: PointerEvent.transformPosition(_lastTransform, _currentFocalPoint),
)); ));
......
This diff is collapsed.
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'arena.dart'; import 'arena.dart';
import 'binding.dart'; import 'binding.dart';
...@@ -27,8 +26,8 @@ class _CombiningGestureArenaMember extends GestureArenaMember { ...@@ -27,8 +26,8 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
final int _pointer; final int _pointer;
bool _resolved = false; bool _resolved = false;
GestureArenaMember _winner; GestureArenaMember? _winner;
GestureArenaEntry _entry; GestureArenaEntry? _entry;
@override @override
void acceptGesture(int pointer) { void acceptGesture(int pointer) {
...@@ -40,7 +39,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember { ...@@ -40,7 +39,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
if (member != _winner) if (member != _winner)
member.rejectGesture(pointer); member.rejectGesture(pointer);
} }
_winner.acceptGesture(pointer); _winner!.acceptGesture(pointer);
} }
@override @override
...@@ -54,7 +53,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember { ...@@ -54,7 +53,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
void _close() { void _close() {
assert(!_resolved); assert(!_resolved);
_resolved = true; _resolved = true;
final _CombiningGestureArenaMember combiner = _owner._combiners.remove(_pointer); final _CombiningGestureArenaMember? combiner = _owner._combiners.remove(_pointer);
assert(combiner == this); assert(combiner == this);
} }
...@@ -62,7 +61,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember { ...@@ -62,7 +61,7 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
assert(!_resolved); assert(!_resolved);
assert(_pointer == pointer); assert(_pointer == pointer);
_members.add(member); _members.add(member);
_entry ??= GestureBinding.instance.gestureArena.add(pointer, this); _entry ??= GestureBinding.instance!.gestureArena.add(pointer, this);
return _CombiningGestureArenaEntry(this, member); return _CombiningGestureArenaEntry(this, member);
} }
...@@ -73,11 +72,11 @@ class _CombiningGestureArenaMember extends GestureArenaMember { ...@@ -73,11 +72,11 @@ class _CombiningGestureArenaMember extends GestureArenaMember {
_members.remove(member); _members.remove(member);
member.rejectGesture(_pointer); member.rejectGesture(_pointer);
if (_members.isEmpty) if (_members.isEmpty)
_entry.resolve(disposition); _entry!.resolve(disposition);
} else { } else {
assert(disposition == GestureDisposition.accepted); assert(disposition == GestureDisposition.accepted);
_winner ??= _owner.captain ?? member; _winner ??= _owner.captain ?? member;
_entry.resolve(disposition); _entry!.resolve(disposition);
} }
} }
} }
...@@ -131,7 +130,7 @@ class GestureArenaTeam { ...@@ -131,7 +130,7 @@ class GestureArenaTeam {
/// If not null, when any one of the [GestureArenaTeam] members claims victory /// If not null, when any one of the [GestureArenaTeam] members claims victory
/// the captain accepts the gesture. /// the captain accepts the gesture.
/// If null, the member that claims a victory accepts the gesture. /// If null, the member that claims a victory accepts the gesture.
GestureArenaMember captain; GestureArenaMember? captain;
/// Adds a new member to the arena on behalf of this team. /// Adds a new member to the arena on behalf of this team.
/// ///
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show Offset; import 'dart:ui' show Offset;
...@@ -19,7 +18,7 @@ class Velocity { ...@@ -19,7 +18,7 @@ class Velocity {
/// ///
/// The [pixelsPerSecond] argument must not be null. /// The [pixelsPerSecond] argument must not be null.
const Velocity({ const Velocity({
@required this.pixelsPerSecond, required this.pixelsPerSecond,
}) : assert(pixelsPerSecond != null); }) : assert(pixelsPerSecond != null);
/// A velocity that isn't moving at all. /// A velocity that isn't moving at all.
...@@ -95,10 +94,10 @@ class VelocityEstimate { ...@@ -95,10 +94,10 @@ class VelocityEstimate {
/// ///
/// [pixelsPerSecond], [confidence], [duration], and [offset] must not be null. /// [pixelsPerSecond], [confidence], [duration], and [offset] must not be null.
const VelocityEstimate({ const VelocityEstimate({
@required this.pixelsPerSecond, required this.pixelsPerSecond,
@required this.confidence, required this.confidence,
@required this.duration, required this.duration,
@required this.offset, required this.offset,
}) : assert(pixelsPerSecond != null), }) : assert(pixelsPerSecond != null),
assert(confidence != null), assert(confidence != null),
assert(duration != null), assert(duration != null),
...@@ -154,7 +153,7 @@ class VelocityTracker { ...@@ -154,7 +153,7 @@ class VelocityTracker {
static const int _minSampleSize = 3; static const int _minSampleSize = 3;
// Circular buffer; current sample at _index. // Circular buffer; current sample at _index.
final List<_PointAtTime> _samples = List<_PointAtTime>(_historySize); final List<_PointAtTime?> _samples = List<_PointAtTime?>.filled(_historySize, null, growable: false);
int _index = 0; int _index = 0;
/// Adds a position as the given time to the tracker. /// Adds a position as the given time to the tracker.
...@@ -171,7 +170,7 @@ class VelocityTracker { ...@@ -171,7 +170,7 @@ class VelocityTracker {
/// Information is added using [addPosition]. /// Information is added using [addPosition].
/// ///
/// Returns null if there is no data on which to base an estimate. /// Returns null if there is no data on which to base an estimate.
VelocityEstimate getVelocityEstimate() { VelocityEstimate? getVelocityEstimate() {
final List<double> x = <double>[]; final List<double> x = <double>[];
final List<double> y = <double>[]; final List<double> y = <double>[];
final List<double> w = <double>[]; final List<double> w = <double>[];
...@@ -179,7 +178,7 @@ class VelocityTracker { ...@@ -179,7 +178,7 @@ class VelocityTracker {
int sampleCount = 0; int sampleCount = 0;
int index = _index; int index = _index;
final _PointAtTime newestSample = _samples[index]; final _PointAtTime? newestSample = _samples[index];
if (newestSample == null) if (newestSample == null)
return null; return null;
...@@ -189,7 +188,7 @@ class VelocityTracker { ...@@ -189,7 +188,7 @@ class VelocityTracker {
// Starting with the most recent PointAtTime sample, iterate backwards while // Starting with the most recent PointAtTime sample, iterate backwards while
// the samples represent continuous motion. // the samples represent continuous motion.
do { do {
final _PointAtTime sample = _samples[index]; final _PointAtTime? sample = _samples[index];
if (sample == null) if (sample == null)
break; break;
...@@ -212,10 +211,10 @@ class VelocityTracker { ...@@ -212,10 +211,10 @@ class VelocityTracker {
if (sampleCount >= _minSampleSize) { if (sampleCount >= _minSampleSize) {
final LeastSquaresSolver xSolver = LeastSquaresSolver(time, x, w); final LeastSquaresSolver xSolver = LeastSquaresSolver(time, x, w);
final PolynomialFit xFit = xSolver.solve(2); final PolynomialFit? xFit = xSolver.solve(2);
if (xFit != null) { if (xFit != null) {
final LeastSquaresSolver ySolver = LeastSquaresSolver(time, y, w); final LeastSquaresSolver ySolver = LeastSquaresSolver(time, y, w);
final PolynomialFit yFit = ySolver.solve(2); final PolynomialFit? yFit = ySolver.solve(2);
if (yFit != null) { if (yFit != null) {
return VelocityEstimate( // convert from pixels/ms to pixels/s return VelocityEstimate( // convert from pixels/ms to pixels/s
pixelsPerSecond: Offset(xFit.coefficients[1] * 1000, yFit.coefficients[1] * 1000), pixelsPerSecond: Offset(xFit.coefficients[1] * 1000, yFit.coefficients[1] * 1000),
...@@ -245,7 +244,7 @@ class VelocityTracker { ...@@ -245,7 +244,7 @@ class VelocityTracker {
/// Returns [Velocity.zero] if there is no data from which to compute an /// Returns [Velocity.zero] if there is no data from which to compute an
/// estimate or if the estimated velocity is zero. /// estimate or if the estimated velocity is zero.
Velocity getVelocity() { Velocity getVelocity() {
final VelocityEstimate estimate = getVelocityEstimate(); final VelocityEstimate? estimate = getVelocityEstimate();
if (estimate == null || estimate.pixelsPerSecond == Offset.zero) if (estimate == null || estimate.pixelsPerSecond == Offset.zero)
return Velocity.zero; return Velocity.zero;
return Velocity(pixelsPerSecond: estimate.pixelsPerSecond); return Velocity(pixelsPerSecond: estimate.pixelsPerSecond);
......
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