Skip to content

Commit

Permalink
Merge pull request #1 from tsinis/fix/flutter-3-warnings
Browse files Browse the repository at this point in the history
Fix Flutter 3 Warnings
  • Loading branch information
tsinis authored May 29, 2022
2 parents 3c31464 + 5fd9e5b commit e90219f
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit e90219f

Please sign in to comment.