Unverified Commit 9e658bc3 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

migrate scheduler to nullsafety (#61570)

parent fdf87edd
......@@ -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
/// The Flutter Scheduler library.
///
/// To use, import `package:flutter/scheduler.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/foundation.dart';
// Any changes to this file should be reflected in the debugAssertAllSchedulerVarsUnset()
......
......@@ -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';
/// A task priority, as passed to [SchedulerBinding.scheduleTask].
......
......@@ -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 'package:flutter/foundation.dart';
......@@ -71,7 +69,7 @@ class Ticker {
}());
}
TickerFuture _future;
TickerFuture? _future;
/// Whether this ticker has been silenced.
///
......@@ -115,9 +113,9 @@ class Ticker {
return false;
if (muted)
return false;
if (SchedulerBinding.instance.framesEnabled)
if (SchedulerBinding.instance!.framesEnabled)
return true;
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle)
if (SchedulerBinding.instance!.schedulerPhase != SchedulerPhase.idle)
return true; // for example, we might be in a warm-up frame or forced frame
return false;
}
......@@ -130,7 +128,7 @@ class Ticker {
/// [isTicking].
bool get isActive => _future != null;
Duration _startTime;
Duration? _startTime;
/// Starts the clock for this [Ticker]. If the ticker is not [muted], then this
/// also starts calling the ticker's callback once per animation frame.
......@@ -163,10 +161,10 @@ class Ticker {
if (shouldScheduleTick) {
scheduleTick();
}
if (SchedulerBinding.instance.schedulerPhase.index > SchedulerPhase.idle.index &&
SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index)
_startTime = SchedulerBinding.instance.currentFrameTimeStamp;
return _future;
if (SchedulerBinding.instance!.schedulerPhase.index > SchedulerPhase.idle.index &&
SchedulerBinding.instance!.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index)
_startTime = SchedulerBinding.instance!.currentFrameTimeStamp;
return _future!;
}
/// Adds a debug representation of a [Ticker] optimized for including in error
......@@ -197,7 +195,7 @@ class Ticker {
// We take the _future into a local variable so that isTicking is false
// when we actually complete the future (isTicking uses _future to
// determine its state).
final TickerFuture localFuture = _future;
final TickerFuture localFuture = _future!;
_future = null;
_startTime = null;
assert(!isActive);
......@@ -213,7 +211,7 @@ class Ticker {
final TickerCallback _onTick;
int _animationId;
int? _animationId;
/// Whether this [Ticker] has already scheduled a frame callback.
@protected
......@@ -237,7 +235,7 @@ class Ticker {
_animationId = null;
_startTime ??= timeStamp;
_onTick(timeStamp - _startTime);
_onTick(timeStamp - _startTime!);
// The onTick callback may have scheduled another tick already, for
// example by calling stop then start again.
......@@ -252,7 +250,7 @@ class Ticker {
void scheduleTick({ bool rescheduling = false }) {
assert(!scheduled);
assert(shouldScheduleTick);
_animationId = SchedulerBinding.instance.scheduleFrameCallback(_tick, rescheduling: rescheduling);
_animationId = SchedulerBinding.instance!.scheduleFrameCallback(_tick, rescheduling: rescheduling);
}
/// Cancels the frame callback that was requested by [scheduleTick], if any.
......@@ -264,7 +262,7 @@ class Ticker {
@protected
void unscheduleTick() {
if (scheduled) {
SchedulerBinding.instance.cancelFrameCallbackWithId(_animationId);
SchedulerBinding.instance!.cancelFrameCallbackWithId(_animationId!);
_animationId = null;
}
assert(!shouldScheduleTick);
......@@ -301,7 +299,7 @@ class Ticker {
@mustCallSuper
void dispose() {
if (_future != null) {
final TickerFuture localFuture = _future;
final TickerFuture localFuture = _future!;
_future = null;
assert(!isActive);
unscheduleTick();
......@@ -319,8 +317,8 @@ class Ticker {
/// An optional label can be provided for debugging purposes.
///
/// This label will appear in the [toString] output in debug builds.
final String debugLabel;
StackTrace _debugCreationStack;
final String? debugLabel;
late StackTrace _debugCreationStack;
@override
String toString({ bool debugIncludeStack = false }) {
......@@ -374,14 +372,14 @@ class TickerFuture implements Future<void> {
}
final Completer<void> _primaryCompleter = Completer<void>();
Completer<void> _secondaryCompleter;
bool _completed; // null means unresolved, true means complete, false means canceled
Completer<void>? _secondaryCompleter;
bool? _completed; // null means unresolved, true means complete, false means canceled
void _complete() {
assert(_completed == null);
_completed = true;
_primaryCompleter.complete(null);
_secondaryCompleter?.complete(null);
_primaryCompleter.complete();
_secondaryCompleter?.complete();
}
void _cancel(Ticker ticker) {
......@@ -415,14 +413,14 @@ class TickerFuture implements Future<void> {
if (_secondaryCompleter == null) {
_secondaryCompleter = Completer<void>();
if (_completed != null) {
if (_completed) {
_secondaryCompleter.complete();
if (_completed!) {
_secondaryCompleter!.complete();
} else {
_secondaryCompleter.completeError(const TickerCanceled());
_secondaryCompleter!.completeError(const TickerCanceled());
}
}
}
return _secondaryCompleter.future;
return _secondaryCompleter!.future;
}
@override
......@@ -431,17 +429,17 @@ class TickerFuture implements Future<void> {
}
@override
Future<void> catchError(Function onError, { bool test(dynamic error) }) {
Future<void> catchError(Function onError, { bool Function(Object)? test }) {
return _primaryCompleter.future.catchError(onError, test: test);
}
@override
Future<R> then<R>(FutureOr<R> onValue(void value), { Function onError }) {
Future<R> then<R>(FutureOr<R> onValue(void value), { Function? onError }) {
return _primaryCompleter.future.then<R>(onValue, onError: onError);
}
@override
Future<void> timeout(Duration timeLimit, { dynamic onTimeout() }) {
Future<void> timeout(Duration timeLimit, { FutureOr<void> Function()? onTimeout }) {
return _primaryCompleter.future.timeout(timeLimit, onTimeout: onTimeout);
}
......@@ -451,7 +449,7 @@ class TickerFuture implements Future<void> {
}
@override
String toString() => '${describeIdentity(this)}(${ _completed == null ? "active" : _completed ? "complete" : "canceled" })';
String toString() => '${describeIdentity(this)}(${ _completed == null ? "active" : _completed! ? "complete" : "canceled" })';
}
/// Exception thrown by [Ticker] objects on the [TickerFuture.orCancel] future
......@@ -464,7 +462,7 @@ class TickerCanceled implements Exception {
///
/// This may be null in the case that the [Future] created for
/// [TickerFuture.orCancel] was created after the ticker was canceled.
final Ticker ticker;
final Ticker? ticker;
@override
String toString() {
......
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