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