Unverified Commit 01e8c395 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Migrate gestures, physics and scheduler tests to null safety. (#62701)

parent f3d9bf7b
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import '../flutter_test_alternative.dart';
......@@ -34,12 +32,12 @@ class GestureTester {
TestGestureArenaMember first = TestGestureArenaMember();
TestGestureArenaMember second = TestGestureArenaMember();
GestureArenaEntry firstEntry;
late GestureArenaEntry firstEntry;
void addFirst() {
firstEntry = arena.add(primaryKey, first);
}
GestureArenaEntry secondEntry;
late GestureArenaEntry secondEntry;
void addSecond() {
secondEntry = arena.add(primaryKey, second);
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -14,7 +12,7 @@ void main() {
debugPrintGestureArenaDiagnostics = true;
final DebugPrintCallback oldCallback = debugPrint;
final List<String> log = <String>[];
debugPrint = (String s, { int wrapWidth }) { log.add(s); };
debugPrint = (String? s, { int? wrapWidth }) { log.add(s ?? ''); };
final TapGestureRecognizer tap = TapGestureRecognizer()
..onTapDown = (TapDownDetails details) { }
......@@ -30,19 +28,19 @@ void main() {
expect(log[1], equalsIgnoringHashCodes('Gesture arena 1 ❙ Adding: TapGestureRecognizer#00000(state: ready, button: 1)'));
log.clear();
GestureBinding.instance.gestureArena.close(1);
GestureBinding.instance!.gestureArena.close(1);
expect(log, hasLength(1));
expect(log[0], equalsIgnoringHashCodes('Gesture arena 1 ❙ Closing with 1 member.'));
log.clear();
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
expect(log, isEmpty);
event = const PointerUpEvent(pointer: 1, position: Offset(12.0, 8.0));
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
expect(log, isEmpty);
GestureBinding.instance.gestureArena.sweep(1);
GestureBinding.instance!.gestureArena.sweep(1);
expect(log, hasLength(2));
expect(log[0], equalsIgnoringHashCodes('Gesture arena 1 ❙ Sweeping with 1 member.'));
expect(log[1], equalsIgnoringHashCodes('Gesture arena 1 ❙ Winner: TapGestureRecognizer#00000(state: ready, finalPosition: Offset(12.0, 8.0), button: 1)'));
......@@ -60,7 +58,7 @@ void main() {
debugPrintRecognizerCallbacksTrace = true;
final DebugPrintCallback oldCallback = debugPrint;
final List<String> log = <String>[];
debugPrint = (String s, { int wrapWidth }) { log.add(s); };
debugPrint = (String? s, { int? wrapWidth }) { log.add(s ?? ''); };
final TapGestureRecognizer tap = TapGestureRecognizer()
..onTapDown = (TapDownDetails details) { }
......@@ -73,17 +71,17 @@ void main() {
tap.addPointer(event as PointerDownEvent);
expect(log, isEmpty);
GestureBinding.instance.gestureArena.close(1);
GestureBinding.instance!.gestureArena.close(1);
expect(log, isEmpty);
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
expect(log, isEmpty);
event = const PointerUpEvent(pointer: 1, position: Offset(12.0, 8.0));
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
expect(log, isEmpty);
GestureBinding.instance.gestureArena.sweep(1);
GestureBinding.instance!.gestureArena.sweep(1);
expect(log, hasLength(3));
expect(log[0], equalsIgnoringHashCodes('TapGestureRecognizer#00000(state: ready, finalPosition: Offset(12.0, 8.0), button: 1) calling onTapDown callback.'));
expect(log[1], equalsIgnoringHashCodes('TapGestureRecognizer#00000(state: ready, won arena, finalPosition: Offset(12.0, 8.0), button: 1, sent tap down) calling onTapUp callback.'));
......@@ -103,7 +101,7 @@ void main() {
debugPrintRecognizerCallbacksTrace = true;
final DebugPrintCallback oldCallback = debugPrint;
final List<String> log = <String>[];
debugPrint = (String s, { int wrapWidth }) { log.add(s); };
debugPrint = (String? s, { int? wrapWidth }) { log.add(s ?? ''); };
final TapGestureRecognizer tap = TapGestureRecognizer()
..onTapDown = (TapDownDetails details) { }
......@@ -119,19 +117,19 @@ void main() {
expect(log[1], equalsIgnoringHashCodes('Gesture arena 1 ❙ Adding: TapGestureRecognizer#00000(state: ready, button: 1)'));
log.clear();
GestureBinding.instance.gestureArena.close(1);
GestureBinding.instance!.gestureArena.close(1);
expect(log, hasLength(1));
expect(log[0], equalsIgnoringHashCodes('Gesture arena 1 ❙ Closing with 1 member.'));
log.clear();
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
expect(log, isEmpty);
event = const PointerUpEvent(pointer: 1, position: Offset(12.0, 8.0));
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
expect(log, isEmpty);
GestureBinding.instance.gestureArena.sweep(1);
GestureBinding.instance!.gestureArena.sweep(1);
expect(log, hasLength(5));
expect(log[0], equalsIgnoringHashCodes('Gesture arena 1 ❙ Sweeping with 1 member.'));
expect(log[1], equalsIgnoringHashCodes('Gesture arena 1 ❙ Winner: TapGestureRecognizer#00000(state: ready, finalPosition: Offset(12.0, 8.0), button: 1)'));
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart';
......@@ -801,10 +799,10 @@ void main() {
}
void _expectTransformedEvent({
@required PointerEvent original,
@required Matrix4 transform,
Offset localDelta,
Offset localPosition,
required PointerEvent original,
required Matrix4 transform,
Offset? localDelta,
Offset? localPosition,
}) {
expect(original.position, original.localPosition);
expect(original.delta, original.localDelta);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
......@@ -28,7 +26,7 @@ void main() {
int updated = 0;
int ended = 0;
Offset startGlobalPosition;
Offset? startGlobalPosition;
void onStart(ForcePressDetails details) {
startGlobalPosition = details.globalPosition;
......@@ -411,7 +409,7 @@ void main() {
int updated = 0;
int ended = 0;
Offset startGlobalPosition;
Offset? startGlobalPosition;
void onStart(ForcePressDetails details) {
startGlobalPosition = details.globalPosition;
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
......@@ -15,21 +13,21 @@ import '../flutter_test_alternative.dart';
typedef HandleEventCallback = void Function(PointerEvent event);
class TestGestureFlutterBinding extends BindingBase with GestureBinding, SchedulerBinding {
HandleEventCallback callback;
FrameCallback frameCallback;
Duration frameTime;
HandleEventCallback? callback;
FrameCallback? frameCallback;
Duration? frameTime;
@override
void handleEvent(PointerEvent event, HitTestEntry entry) {
super.handleEvent(event, entry);
if (callback != null)
callback(event);
callback?.call(event);
}
@override
Duration get currentSystemFrameTimeStamp {
assert(frameTime != null);
return frameTime;
return frameTime!;
}
@override
......@@ -39,7 +37,7 @@ class TestGestureFlutterBinding extends BindingBase with GestureBinding, Schedul
}
}
TestGestureFlutterBinding _binding = TestGestureFlutterBinding();
TestGestureFlutterBinding? _binding;
void ensureTestGestureBinding() {
_binding ??= TestGestureFlutterBinding();
......@@ -59,9 +57,9 @@ void main() {
);
final List<PointerEvent> events = <PointerEvent>[];
_binding.callback = events.add;
_binding!.callback = events.add;
ui.window.onPointerDataPacket(packet);
ui.window.onPointerDataPacket?.call(packet);
expect(events.length, 2);
expect(events[0], isA<PointerDownEvent>());
expect(events[1], isA<PointerUpEvent>());
......@@ -77,9 +75,9 @@ void main() {
);
final List<PointerEvent> events = <PointerEvent>[];
_binding.callback = events.add;
_binding!.callback = events.add;
ui.window.onPointerDataPacket(packet);
ui.window.onPointerDataPacket?.call(packet);
expect(events.length, 3);
expect(events[0], isA<PointerDownEvent>());
expect(events[1], isA<PointerMoveEvent>());
......@@ -99,12 +97,12 @@ void main() {
);
final List<PointerEvent> pointerRouterEvents = <PointerEvent>[];
GestureBinding.instance.pointerRouter.addGlobalRoute(pointerRouterEvents.add);
GestureBinding.instance!.pointerRouter.addGlobalRoute(pointerRouterEvents.add);
final List<PointerEvent> events = <PointerEvent>[];
_binding.callback = events.add;
_binding!.callback = events.add;
ui.window.onPointerDataPacket(packet);
ui.window.onPointerDataPacket?.call(packet);
expect(events.length, 3);
expect(events[0], isA<PointerHoverEvent>());
expect(events[1], isA<PointerHoverEvent>());
......@@ -128,9 +126,9 @@ void main() {
);
final List<PointerEvent> events = <PointerEvent>[];
_binding.callback = events.add;
_binding!.callback = events.add;
ui.window.onPointerDataPacket(packet);
ui.window.onPointerDataPacket?.call(packet);
expect(events.length, 2);
expect(events[0], isA<PointerDownEvent>());
expect(events[1], isA<PointerCancelEvent>());
......@@ -145,13 +143,13 @@ void main() {
);
final List<PointerEvent> events = <PointerEvent>[];
_binding.callback = (PointerEvent event) {
_binding!.callback = (PointerEvent event) {
events.add(event);
if (event is PointerDownEvent)
_binding.cancelPointer(event.pointer);
_binding!.cancelPointer(event.pointer);
};
ui.window.onPointerDataPacket(packet);
ui.window.onPointerDataPacket?.call(packet);
expect(events.length, 2);
expect(events[0], isA<PointerDownEvent>());
expect(events[1], isA<PointerCancelEvent>());
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:meta/meta.dart';
......@@ -25,11 +23,11 @@ class GestureTester {
final FakeAsync async;
void closeArena(int pointer) {
GestureBinding.instance.gestureArena.close(pointer);
GestureBinding.instance!.gestureArena.close(pointer);
}
void route(PointerEvent event) {
GestureBinding.instance.pointerRouter.route(event);
GestureBinding.instance!.pointerRouter.route(event);
async.flushMicrotasks();
}
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import 'package:vector_math/vector_math_64.dart';
......@@ -38,7 +36,7 @@ void main() {
});
test('HitTestResult should correctly push and pop transforms', () {
Matrix4 currentTransform(HitTestResult targetResult) {
Matrix4? currentTransform(HitTestResult targetResult) {
final HitTestEntry entry = HitTestEntry(_DummyHitTestTarget());
targetResult.add(entry);
return entry.transform;
......@@ -78,7 +76,7 @@ void main() {
});
test('HitTestResult should correctly push and pop offsets', () {
Matrix4 currentTransform(HitTestResult targetResult) {
Matrix4? currentTransform(HitTestResult targetResult) {
final HitTestEntry entry = HitTestEntry(_DummyHitTestTarget());
targetResult.add(entry);
return entry.transform;
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
......@@ -14,12 +12,12 @@ import '../flutter_test_alternative.dart';
typedef HandleEventCallback = void Function(PointerEvent event);
class TestGestureFlutterBinding extends BindingBase with GestureBinding {
HandleEventCallback callback;
HandleEventCallback? callback;
@override
void handleEvent(PointerEvent event, HitTestEntry entry) {
if (callback != null)
callback(event);
callback?.call(event);
super.handleEvent(event, entry);
}
......@@ -33,21 +31,17 @@ class TestGestureFlutterBinding extends BindingBase with GestureBinding {
Future<void> test(VoidCallback callback) {
assert(callback != null);
return _binding.lockEvents(() async {
ui.window.onPointerDataPacket(packet);
ui.window.onPointerDataPacket?.call(packet);
callback();
});
}
}
TestGestureFlutterBinding _binding = TestGestureFlutterBinding();
void ensureTestGestureBinding() {
_binding ??= TestGestureFlutterBinding();
assert(GestureBinding.instance != null);
}
late TestGestureFlutterBinding _binding;
void main() {
setUp(ensureTestGestureBinding);
_binding = TestGestureFlutterBinding();
assert(GestureBinding.instance != null);
test('Pointer events are locked during reassemble', () async {
final List<PointerEvent> events = <PointerEvent>[];
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import '../flutter_test_alternative.dart';
......@@ -64,9 +62,9 @@ void main() {
setUp(ensureGestureBinding);
group('Long press', () {
LongPressGestureRecognizer longPress;
bool longPressDown;
bool longPressUp;
late LongPressGestureRecognizer longPress;
late bool longPressDown;
late bool longPressUp;
setUp(() {
longPress = LongPressGestureRecognizer();
......@@ -293,10 +291,10 @@ void main() {
});
group('long press drag', () {
LongPressGestureRecognizer longPressDrag;
bool longPressStart;
bool longPressUp;
Offset longPressDragUpdate;
late LongPressGestureRecognizer longPressDrag;
late bool longPressStart;
late bool longPressUp;
Offset? longPressDragUpdate;
setUp(() {
longPressDrag = LongPressGestureRecognizer();
......@@ -392,7 +390,7 @@ void main() {
final List<String> recognized = <String>[];
LongPressGestureRecognizer longPress;
late LongPressGestureRecognizer longPress;
setUp(() {
longPress = LongPressGestureRecognizer()
......@@ -532,9 +530,9 @@ void main() {
// competition with a tap gesture recognizer listening on a different button.
final List<String> recognized = <String>[];
TapGestureRecognizer tapPrimary;
TapGestureRecognizer tapSecondary;
LongPressGestureRecognizer longPress;
late TapGestureRecognizer tapPrimary;
late TapGestureRecognizer tapSecondary;
late LongPressGestureRecognizer longPress;
setUp(() {
tapPrimary = TapGestureRecognizer()
..onTapDown = (TapDownDetails details) {
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import '../flutter_test_alternative.dart';
......@@ -20,7 +18,7 @@ void main() {
final List<double> w = <double>[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
final LeastSquaresSolver solver = LeastSquaresSolver(x, y, w);
final PolynomialFit fit = solver.solve(1);
final PolynomialFit fit = solver.solve(1)!;
expect(fit.coefficients.length, 2);
expect(approx(fit.coefficients[0], 1.0), isTrue);
......@@ -34,7 +32,7 @@ void main() {
final List<double> w = <double>[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
final LeastSquaresSolver solver = LeastSquaresSolver(x, y, w);
final PolynomialFit fit = solver.solve(1);
final PolynomialFit fit = solver.solve(1)!;
expect(fit.coefficients.length, 2);
expect(approx(fit.coefficients[0], 1.0), isTrue);
......@@ -48,7 +46,7 @@ void main() {
final List<double> w = <double>[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
final LeastSquaresSolver solver = LeastSquaresSolver(x, y, w);
final PolynomialFit fit = solver.solve(2);
final PolynomialFit fit = solver.solve(2)!;
expect(fit.coefficients.length, 3);
expect(approx(fit.coefficients[0], 1.0), isTrue);
......@@ -63,7 +61,7 @@ void main() {
final List<double> w = <double>[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
final LeastSquaresSolver solver = LeastSquaresSolver(x, y, w);
final PolynomialFit fit = solver.solve(2);
final PolynomialFit fit = solver.solve(2)!;
expect(fit.coefficients.length, 3);
expect(approx(fit.coefficients[0], 1.0), isTrue);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
......@@ -136,7 +134,7 @@ void main() {
log.add('per-pointer 3');
});
final FlutterExceptionHandler previousErrorHandler = FlutterError.onError;
final FlutterExceptionHandler? previousErrorHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) {
log.add('error report');
};
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import 'package:vector_math/vector_math_64.dart';
......
......@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart';
class TestGestureRecognizer extends GestureRecognizer {
TestGestureRecognizer({ Object debugOwner }) : super(debugOwner: debugOwner);
TestGestureRecognizer({ Object? debugOwner }) : super(debugOwner: debugOwner);
@override
String get debugDescription => 'debugDescription content';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
import 'package:flutter_test/flutter_test.dart';
......@@ -19,15 +17,15 @@ void main() {
final TapGestureRecognizer tap = TapGestureRecognizer();
bool didStartScale = false;
Offset updatedFocalPoint;
Offset? updatedFocalPoint;
scale.onStart = (ScaleStartDetails details) {
didStartScale = true;
updatedFocalPoint = details.focalPoint;
};
double updatedScale;
double updatedHorizontalScale;
double updatedVerticalScale;
double? updatedScale;
double? updatedHorizontalScale;
double? updatedVerticalScale;
scale.onUpdate = (ScaleUpdateDetails details) {
updatedScale = details.scale;
updatedHorizontalScale = details.horizontalScale;
......@@ -230,7 +228,7 @@ void main() {
didStartScale = true;
};
double updatedScale;
double? updatedScale;
scale.onUpdate = (ScaleUpdateDetails details) {
updatedScale = details.scale;
};
......@@ -258,13 +256,13 @@ void main() {
final ScaleGestureRecognizer scale = ScaleGestureRecognizer(kind: PointerDeviceKind.touch);
bool didStartScale = false;
Offset updatedFocalPoint;
Offset? updatedFocalPoint;
scale.onStart = (ScaleStartDetails details) {
didStartScale = true;
updatedFocalPoint = details.focalPoint;
};
double updatedScale;
double? updatedScale;
scale.onUpdate = (ScaleUpdateDetails details) {
updatedScale = details.scale;
updatedFocalPoint = details.focalPoint;
......@@ -404,13 +402,13 @@ void main() {
final TapGestureRecognizer tap = TapGestureRecognizer();
bool didStartScale = false;
Offset updatedFocalPoint;
Offset? updatedFocalPoint;
scale.onStart = (ScaleStartDetails details) {
didStartScale = true;
updatedFocalPoint = details.focalPoint;
};
double updatedRotation;
double? updatedRotation;
scale.onUpdate = (ScaleUpdateDetails details) {
updatedRotation = details.rotation;
updatedFocalPoint = details.focalPoint;
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart';
......@@ -108,7 +106,7 @@ void main() {
typedef GestureAcceptedCallback = void Function();
class PassiveGestureRecognizer extends OneSequenceGestureRecognizer {
GestureAcceptedCallback onGestureAccepted;
GestureAcceptedCallback? onGestureAccepted;
@override
void addPointer(PointerDownEvent event) {
......@@ -133,7 +131,7 @@ class PassiveGestureRecognizer extends OneSequenceGestureRecognizer {
@override
void acceptGesture(int pointer) {
if (onGestureAccepted != null) {
onGestureAccepted();
onGestureAccepted!();
}
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:math' as math;
import 'package:flutter/material.dart';
......@@ -63,7 +61,7 @@ void main() {
const Offset(100, 0),
);
expect(
updateDetails.fold(0.0, (double offset, DragUpdateDetails details) => offset + details.primaryDelta),
updateDetails.fold(0.0, (double offset, DragUpdateDetails details) => offset + (details.primaryDelta ?? 0)),
100.0,
);
});
......@@ -391,7 +389,7 @@ void main() {
const Offset(0, 100),
);
expect(
updateDetails.fold(0.0, (double offset, DragUpdateDetails details) => offset + details.primaryDelta),
updateDetails.fold(0.0, (double offset, DragUpdateDetails details) => offset + (details.primaryDelta ?? 0)),
100.0,
);
});
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
const List<PointerEvent> velocityEventData = <PointerEvent>[
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart';
import 'velocity_tracker_data.dart';
......@@ -81,7 +79,7 @@ void main() {
test('FreeScrollStartVelocityTracker.getVelocity throws when no points', () {
final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch);
AssertionError exception;
AssertionError? exception;
try {
tracker.getVelocity();
} on AssertionError catch (e) {
......@@ -93,7 +91,7 @@ void main() {
test('FreeScrollStartVelocityTracker.getVelocity throws when the new point precedes the previous point', () {
final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch);
AssertionError exception;
AssertionError? exception;
tracker.addPosition(const Duration(hours: 1), Offset.zero);
try {
......@@ -112,7 +110,7 @@ void main() {
Duration time = Duration.zero;
const Offset positionDelta = Offset(0, -1);
const Duration durationDelta = Duration(seconds: 1);
AssertionError exception;
AssertionError? exception;
for (int i = 0; i < 5; i+=1) {
position += positionDelta;
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
......@@ -22,7 +20,7 @@ void main() {
});
test('Can cancel queued callback', () {
int secondId;
late int secondId;
bool firstCallbackRan = false;
bool secondCallbackRan = false;
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -14,10 +12,10 @@ class TestBinding extends LiveTestWidgetsFlutterBinding {
int framesBegun = 0;
int framesDrawn = 0;
bool handleBeginFrameMicrotaskRun;
late bool handleBeginFrameMicrotaskRun;
@override
void handleBeginFrame(Duration rawTimeStamp) {
void handleBeginFrame(Duration? rawTimeStamp) {
handleBeginFrameMicrotaskRun = false;
framesBegun += 1;
Future<void>.microtask(() { handleBeginFrameMicrotaskRun = true; });
......@@ -35,7 +33,7 @@ class TestBinding extends LiveTestWidgetsFlutterBinding {
}
void main() {
TestBinding binding;
late TestBinding binding;
setUp(() {
binding = TestBinding();
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/scheduler.dart';
import '../flutter_test_alternative.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'dart:ui' show window;
......@@ -30,13 +28,13 @@ class TestSchedulerBinding extends BindingBase with SchedulerBinding, ServicesBi
class TestStrategy {
int allowedPriority = 10000;
bool shouldRunTaskWithPriority({ int priority, SchedulerBinding scheduler }) {
bool shouldRunTaskWithPriority({ required int priority, required SchedulerBinding scheduler }) {
return priority >= allowedPriority;
}
}
void main() {
TestSchedulerBinding scheduler;
late TestSchedulerBinding scheduler;
setUpAll(() {
scheduler = TestSchedulerBinding();
......@@ -122,7 +120,7 @@ void main() {
createTimer: (Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()) {
// Don't actually run the tasks, just record that it was scheduled.
timerQueueTasks.add(f);
return null;
return DummyTimer();
},
),
);
......@@ -134,7 +132,7 @@ void main() {
});
test('Flutter.Frame event fired', () async {
window.onReportTimings(<FrameTiming>[FrameTiming(
window.onReportTimings!(<FrameTiming>[FrameTiming(
vsyncStart: 5000,
buildStart: 10000,
buildFinish: 15000,
......@@ -155,20 +153,20 @@ void main() {
});
test('TimingsCallback exceptions are caught', () {
FlutterErrorDetails errorCaught;
FlutterErrorDetails? errorCaught;
FlutterError.onError = (FlutterErrorDetails details) {
errorCaught = details;
};
SchedulerBinding.instance.addTimingsCallback((List<FrameTiming> timings) {
SchedulerBinding.instance!.addTimingsCallback((List<FrameTiming> timings) {
throw Exception('Test');
});
window.onReportTimings(<FrameTiming>[]);
expect(errorCaught.exceptionAsString(), equals('Exception: Test'));
window.onReportTimings!(<FrameTiming>[]);
expect(errorCaught!.exceptionAsString(), equals('Exception: Test'));
});
test('currentSystemFrameTimeStamp is the raw timestamp', () {
Duration lastTimeStamp;
Duration lastSystemTimeStamp;
late Duration lastTimeStamp;
late Duration lastSystemTimeStamp;
void frameCallback(Duration timeStamp) {
expect(timeStamp, scheduler.currentFrameTimeStamp);
......@@ -198,3 +196,14 @@ void main() {
expect(lastSystemTimeStamp, const Duration(seconds: 8));
});
}
class DummyTimer implements Timer {
@override
void cancel() {}
@override
bool get isActive => false;
@override
int get tick => 0;
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/scheduler.dart';
@Deprecated('scheduler_tester is not compatible with dart:async') // ignore: flutter_deprecation_syntax (see analyze.dart)
......@@ -12,6 +10,6 @@ class Future { } // so that people can't import us and dart:async
void tick(Duration duration) {
// We don't bother running microtasks between these two calls
// because we don't use Futures in these tests and so don't care.
SchedulerBinding.instance.handleBeginFrame(duration);
SchedulerBinding.instance.handleDrawFrame();
SchedulerBinding.instance!.handleBeginFrame(duration);
SchedulerBinding.instance!.handleDrawFrame();
}
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
......@@ -27,14 +25,14 @@ void main() {
expect(ticker.isActive, isTrue);
expect(tickCount, equals(0));
FlutterError error;
FlutterError? error;
try {
ticker.start();
} on FlutterError catch (e) {
error = e;
}
expect(error, isNotNull);
expect(error.diagnostics.length, 3);
expect(error!.diagnostics.length, 3);
expect(error.diagnostics.last, isA<DiagnosticsProperty<Ticker>>());
expect(
error.toStringDeep(),
......@@ -93,7 +91,7 @@ void main() {
});
testWidgets('Ticker control test', (WidgetTester tester) async {
Ticker ticker;
late Ticker ticker;
void testFunction() {
ticker = Ticker((Duration _) { });
......@@ -107,7 +105,7 @@ void main() {
testWidgets('Ticker can be sped up with time dilation', (WidgetTester tester) async {
timeDilation = 0.5; // Move twice as fast.
Duration lastDuration;
late Duration lastDuration;
void handleTick(Duration duration) {
lastDuration = duration;
}
......@@ -123,7 +121,7 @@ void main() {
testWidgets('Ticker can be slowed down with time dilation', (WidgetTester tester) async {
timeDilation = 2.0; // Move half as fast.
Duration lastDuration;
late Duration lastDuration;
void handleTick(Duration duration) {
lastDuration = duration;
}
......@@ -150,8 +148,8 @@ void main() {
expect(ticker.isActive, isTrue);
expect(tickCount, equals(0));
final ByteData message = const StringCodec().encodeMessage('AppLifecycleState.paused');
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
final ByteData? message = const StringCodec().encodeMessage('AppLifecycleState.paused');
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
expect(ticker.isTicking, isFalse);
expect(ticker.isActive, isTrue);
......@@ -159,8 +157,8 @@ void main() {
});
testWidgets('Ticker can be created before application unpauses', (WidgetTester tester) async {
final ByteData pausedMessage = const StringCodec().encodeMessage('AppLifecycleState.paused');
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', pausedMessage, (_) { });
final ByteData? pausedMessage = const StringCodec().encodeMessage('AppLifecycleState.paused');
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', pausedMessage, (_) { });
int tickCount = 0;
void handleTick(Duration duration) {
......@@ -178,8 +176,8 @@ void main() {
expect(tickCount, equals(0));
expect(ticker.isTicking, isFalse);
final ByteData resumedMessage = const StringCodec().encodeMessage('AppLifecycleState.resumed');
await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', resumedMessage, (_) { });
final ByteData? resumedMessage = const StringCodec().encodeMessage('AppLifecycleState.resumed');
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', resumedMessage, (_) { });
await tester.pump(const Duration(milliseconds: 10));
......
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