Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Flutter 3 Warnings #320

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions flare_flutter/lib/flare_render_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';

/// This allows a value of type T or T?
/// to be treated as a value of type T?.
///
/// We use this so that APIs that have become
/// non-nullable can still be used with `!` and `?`
/// to support older versions of the API as well.
T? _ambiguate<T>(T? value) => value;

/// A render box for Flare content.
abstract class FlareRenderBox extends RenderBox {
static const double _notPlayingFlag = -1;
Expand Down Expand Up @@ -164,10 +172,12 @@ abstract class FlareRenderBox extends RenderBox {
if (isPlaying) {
// Paint again
if (_frameCallbackID != -1) {
SchedulerBinding.instance?.cancelFrameCallbackWithId(_frameCallbackID);
_ambiguate(SchedulerBinding.instance)
?.cancelFrameCallbackWithId(_frameCallbackID);
}
_frameCallbackID =
SchedulerBinding.instance?.scheduleFrameCallback(_beginFrame) ?? -1;
_frameCallbackID = _ambiguate(SchedulerBinding.instance)
?.scheduleFrameCallback(_beginFrame) ??
-1;
}

final Canvas canvas = context.canvas;
Expand Down Expand Up @@ -269,7 +279,8 @@ abstract class FlareRenderBox extends RenderBox {
} else {
_lastFrameTime = _notPlayingFlag;
if (_frameCallbackID != -1) {
SchedulerBinding.instance?.cancelFrameCallbackWithId(_frameCallbackID);
_ambiguate(SchedulerBinding.instance)
?.cancelFrameCallbackWithId(_frameCallbackID);
}
}
}
Expand Down