Skip to content

Commit a04ddc1

Browse files
authored
Flutter 3.0.0 migration backward compatibility fix (#31)
1 parent e1a62d5 commit a04ddc1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

example/lib/indicators/warp_indicator.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
55
import 'package:flutter/rendering.dart';
66
import 'package:flutter/scheduler.dart';
77

8+
/// This allows a value of type T or T?
9+
/// to be treated as a value of type T?.
10+
///
11+
/// We use this so that APIs that have become
12+
/// non-nullable can still be used with `!` and `?`
13+
/// to support older versions of the API as well.
14+
T? _ambiguate<T>(T? value) => value;
15+
816
enum WarpAnimationState {
917
stopped,
1018
playing,
@@ -163,7 +171,7 @@ class _WarpIndicatorState extends State<WarpIndicator>
163171
child: Builder(builder: (context) {
164172
if (shakeController.value == 1.0 &&
165173
_state == WarpAnimationState.playing) {
166-
SchedulerBinding.instance
174+
_ambiguate(SchedulerBinding.instance)!
167175
.addPostFrameCallback((_) => _resetShakeAnimation());
168176
}
169177
return Transform.rotate(
@@ -303,6 +311,7 @@ class Sky extends CustomPainter {
303311

304312
@override
305313
bool shouldRepaint(Sky oldDelegate) => true;
314+
306315
@override
307316
bool shouldRebuildSemantics(Sky oldDelegate) => false;
308317
}

lib/src/custom_refresh_indicator.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
part of custom_refresh_indicator;
22

3+
/// This allows a value of type T or T?
4+
/// to be treated as a value of type T?.
5+
///
6+
/// We use this so that APIs that have become
7+
/// non-nullable can still be used with `!` and `?`
8+
/// to support older versions of the API as well.
9+
T? _ambiguate<T>(T? value) => value;
10+
311
typedef IndicatorBuilder = Widget Function(
412
BuildContext context,
513
Widget child,
@@ -206,7 +214,7 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
206214

207215
if (_canStart) setIndicatorState(IndicatorState.dragging);
208216

209-
WidgetsBinding.instance.addPostFrameCallback((_) {
217+
_ambiguate(WidgetsBinding.instance)!.addPostFrameCallback((_) {
210218
controller.setAxisDirection(notification.metrics.axisDirection);
211219
});
212220

0 commit comments

Comments
 (0)