Jonny Borges
Committed by GitHub

Merge pull request #2360 from arjundevlucid/master

Fixed backward compatibility
1 typedef ValueUpdater<T> = T Function(); 1 typedef ValueUpdater<T> = T Function();
  2 +/// This allows a value of type T or T?
  3 +/// to be treated as a value of type T?.
  4 +///
  5 +/// We use this so that APIs that have become
  6 +/// non-nullable can still be used with `!` and `?`
  7 +/// to support older versions of the API as well.
  8 +T? ambiguate<T>(T? value) => value;
1 import 'package:flutter/foundation.dart'; 1 import 'package:flutter/foundation.dart';
2 import 'package:flutter/scheduler.dart'; 2 import 'package:flutter/scheduler.dart';
3 3
  4 +import '../../get.dart';
  5 +
4 /// The [GetLifeCycle] 6 /// The [GetLifeCycle]
5 /// 7 ///
6 /// ```dart 8 /// ```dart
@@ -16,7 +18,8 @@ mixin GetLifeCycleMixin { @@ -16,7 +18,8 @@ mixin GetLifeCycleMixin {
16 @protected 18 @protected
17 @mustCallSuper 19 @mustCallSuper
18 void onInit() { 20 void onInit() {
19 - SchedulerBinding.instance?.addPostFrameCallback((_) => onReady()); 21 + ambiguate(SchedulerBinding.instance)
  22 + ?.addPostFrameCallback((_) => onReady());
20 } 23 }
21 24
22 /// Called 1 frame after onInit(). It is the perfect place to enter 25 /// Called 1 frame after onInit(). It is the perfect place to enter
@@ -358,7 +358,7 @@ extension ExtensionSnackbar on GetInterface { @@ -358,7 +358,7 @@ extension ExtensionSnackbar on GetInterface {
358 if (instantInit) { 358 if (instantInit) {
359 controller.show(); 359 controller.show();
360 } else { 360 } else {
361 - SchedulerBinding.instance!.addPostFrameCallback((_) { 361 + ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) {
362 controller.show(); 362 controller.show();
363 }); 363 });
364 } 364 }
@@ -469,7 +469,7 @@ extension ExtensionSnackbar on GetInterface { @@ -469,7 +469,7 @@ extension ExtensionSnackbar on GetInterface {
469 controller.show(); 469 controller.show();
470 } else { 470 } else {
471 //routing.isSnackbar = true; 471 //routing.isSnackbar = true;
472 - SchedulerBinding.instance!.addPostFrameCallback((_) { 472 + ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) {
473 controller.show(); 473 controller.show();
474 }); 474 });
475 } 475 }
@@ -544,8 +544,10 @@ extension GetNavigationExt on GetInterface { @@ -544,8 +544,10 @@ extension GetNavigationExt on GetInterface {
544 // return page; 544 // return page;
545 // } else if (page is Widget) { 545 // } else if (page is Widget) {
546 // Get.log( 546 // Get.log(
547 -// '''WARNING, consider using: "Get.$method(() => Page())" instead of "Get.$method(Page())".  
548 -// Using a widget function instead of a widget fully guarantees that the widget and its controllers will be removed from memory when they are no longer used. 547 +// '''WARNING, consider using: "Get.$method(() => Page())"
  548 +//instead of "Get.$method(Page())".
  549 +// Using a widget function instead of a widget fully guarantees that the widget
  550 +//and its controllers will be removed from memory when they are no longer used.
549 // '''); 551 // ''');
550 // return () => page; 552 // return () => page;
551 // } else if (page is String) { 553 // } else if (page is String) {
@@ -52,7 +52,7 @@ class RouterReportManager<T> { @@ -52,7 +52,7 @@ class RouterReportManager<T> {
52 52
53 void reportRouteDispose(T disposed) { 53 void reportRouteDispose(T disposed) {
54 if (Get.smartManagement != SmartManagement.onlyBuilder) { 54 if (Get.smartManagement != SmartManagement.onlyBuilder) {
55 - WidgetsBinding.instance!.addPostFrameCallback((_) { 55 + ambiguate(WidgetsBinding.instance)!.addPostFrameCallback((_) {
56 _removeDependencyByRoute(disposed); 56 _removeDependencyByRoute(disposed);
57 }); 57 });
58 } 58 }
@@ -34,6 +34,7 @@ class GetNavigator extends Navigator { @@ -34,6 +34,7 @@ class GetNavigator extends Navigator {
34 settings: settings, 34 settings: settings,
35 ); 35 );
36 } 36 }
  37 + return null;
37 }, 38 },
38 reportsRouteUpdateToEngine: reportsRouteUpdateToEngine, 39 reportsRouteUpdateToEngine: reportsRouteUpdateToEngine,
39 restorationScopeId: restorationScopeId, 40 restorationScopeId: restorationScopeId,
@@ -326,7 +326,8 @@ class GetDelegate extends RouterDelegate<RouteDecoder> @@ -326,7 +326,8 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
326 PreventDuplicateHandlingMode.ReorderRoutes, 326 PreventDuplicateHandlingMode.ReorderRoutes,
327 }) async { 327 }) async {
328 routeName = _cleanRouteName("/${page.runtimeType}"); 328 routeName = _cleanRouteName("/${page.runtimeType}");
329 - // if (preventDuplicateHandlingMode == PreventDuplicateHandlingMode.Recreate) { 329 + // if (preventDuplicateHandlingMode ==
  330 + // PreventDuplicateHandlingMode.Recreate) {
330 // routeName = routeName + page.hashCode.toString(); 331 // routeName = routeName + page.hashCode.toString();
331 // } 332 // }
332 333
@@ -449,7 +449,7 @@ You need to either use message[String], or messageText[Widget] or define a userI @@ -449,7 +449,7 @@ You need to either use message[String], or messageText[Widget] or define a userI
449 } 449 }
450 450
451 void _configureLeftBarFuture() { 451 void _configureLeftBarFuture() {
452 - SchedulerBinding.instance!.addPostFrameCallback( 452 + ambiguate(SchedulerBinding.instance)!.addPostFrameCallback(
453 (_) { 453 (_) {
454 final keyContext = _backgroundBoxKey.currentContext; 454 final keyContext = _backgroundBoxKey.currentContext;
455 if (keyContext != null) { 455 if (keyContext != null) {
@@ -248,18 +248,21 @@ extension RxnBoolExt on Rx<bool?> { @@ -248,18 +248,21 @@ extension RxnBoolExt on Rx<bool?> {
248 248
249 bool? get isFalse { 249 bool? get isFalse {
250 if (value != null) return !isTrue!; 250 if (value != null) return !isTrue!;
  251 + return null;
251 } 252 }
252 253
253 bool? operator &(bool other) { 254 bool? operator &(bool other) {
254 if (value != null) { 255 if (value != null) {
255 return other && value!; 256 return other && value!;
256 } 257 }
  258 + return null;
257 } 259 }
258 260
259 bool? operator |(bool other) { 261 bool? operator |(bool other) {
260 if (value != null) { 262 if (value != null) {
261 return other || value!; 263 return other || value!;
262 } 264 }
  265 + return null;
263 } 266 }
264 267
265 bool? operator ^(bool other) => !other == value; 268 bool? operator ^(bool other) => !other == value;
@@ -269,6 +269,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -269,6 +269,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
269 if (value != null) { 269 if (value != null) {
270 return value! * other; 270 return value! * other;
271 } 271 }
  272 + return null;
272 } 273 }
273 274
274 /// Euclidean modulo operator. 275 /// Euclidean modulo operator.
@@ -288,6 +289,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -288,6 +289,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
288 if (value != null) { 289 if (value != null) {
289 return value! % other; 290 return value! % other;
290 } 291 }
  292 + return null;
291 } 293 }
292 294
293 /// Division operator. 295 /// Division operator.
@@ -295,6 +297,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -295,6 +297,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
295 if (value != null) { 297 if (value != null) {
296 return value! / other; 298 return value! / other;
297 } 299 }
  300 + return null;
298 } 301 }
299 302
300 /// Truncating division operator. 303 /// Truncating division operator.
@@ -308,6 +311,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -308,6 +311,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
308 if (value != null) { 311 if (value != null) {
309 return value! ~/ other; 312 return value! ~/ other;
310 } 313 }
  314 + return null;
311 } 315 }
312 316
313 /// Negate operator. 317 /// Negate operator.
@@ -315,6 +319,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -315,6 +319,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
315 if (value != null) { 319 if (value != null) {
316 return -value!; 320 return -value!;
317 } 321 }
  322 + return null;
318 } 323 }
319 324
320 /// Returns the remainder of the truncating division of `this` by [other]. 325 /// Returns the remainder of the truncating division of `this` by [other].
@@ -330,6 +335,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -330,6 +335,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
330 if (value != null) { 335 if (value != null) {
331 return value! < other; 336 return value! < other;
332 } 337 }
  338 + return null;
333 } 339 }
334 340
335 /// Relational less than or equal operator. 341 /// Relational less than or equal operator.
@@ -337,6 +343,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -337,6 +343,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
337 if (value != null) { 343 if (value != null) {
338 return value! <= other; 344 return value! <= other;
339 } 345 }
  346 + return null;
340 } 347 }
341 348
342 /// Relational greater than operator. 349 /// Relational greater than operator.
@@ -344,6 +351,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -344,6 +351,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
344 if (value != null) { 351 if (value != null) {
345 return value! > other; 352 return value! > other;
346 } 353 }
  354 + return null;
347 } 355 }
348 356
349 /// Relational greater than or equal operator. 357 /// Relational greater than or equal operator.
@@ -351,6 +359,7 @@ extension RxnNumExt<T extends num> on Rx<T?> { @@ -351,6 +359,7 @@ extension RxnNumExt<T extends num> on Rx<T?> {
351 if (value != null) { 359 if (value != null) {
352 return value! >= other; 360 return value! >= other;
353 } 361 }
  362 + return null;
354 } 363 }
355 364
356 /// True if the number is the double Not-a-Number value; otherwise, false. 365 /// True if the number is the double Not-a-Number value; otherwise, false.
@@ -585,6 +594,7 @@ class RxnNum extends Rx<num?> { @@ -585,6 +594,7 @@ class RxnNum extends Rx<num?> {
585 value = value! + other; 594 value = value! + other;
586 return value; 595 return value;
587 } 596 }
  597 + return null;
588 } 598 }
589 599
590 /// Subtraction operator. 600 /// Subtraction operator.
@@ -593,6 +603,7 @@ class RxnNum extends Rx<num?> { @@ -593,6 +603,7 @@ class RxnNum extends Rx<num?> {
593 value = value! - other; 603 value = value! - other;
594 return value; 604 return value;
595 } 605 }
  606 + return null;
596 } 607 }
597 } 608 }
598 609
@@ -711,6 +722,7 @@ extension RxnDoubleExt on Rx<double?> { @@ -711,6 +722,7 @@ extension RxnDoubleExt on Rx<double?> {
711 value = value! + other; 722 value = value! + other;
712 return this; 723 return this;
713 } 724 }
  725 + return null;
714 } 726 }
715 727
716 /// Subtraction operator. 728 /// Subtraction operator.
@@ -719,6 +731,7 @@ extension RxnDoubleExt on Rx<double?> { @@ -719,6 +731,7 @@ extension RxnDoubleExt on Rx<double?> {
719 value = value! + other; 731 value = value! + other;
720 return this; 732 return this;
721 } 733 }
  734 + return null;
722 } 735 }
723 736
724 /// Multiplication operator. 737 /// Multiplication operator.
@@ -726,12 +739,14 @@ extension RxnDoubleExt on Rx<double?> { @@ -726,12 +739,14 @@ extension RxnDoubleExt on Rx<double?> {
726 if (value != null) { 739 if (value != null) {
727 return value! * other; 740 return value! * other;
728 } 741 }
  742 + return null;
729 } 743 }
730 744
731 double? operator %(num other) { 745 double? operator %(num other) {
732 if (value != null) { 746 if (value != null) {
733 return value! % other; 747 return value! % other;
734 } 748 }
  749 + return null;
735 } 750 }
736 751
737 /// Division operator. 752 /// Division operator.
@@ -739,6 +754,7 @@ extension RxnDoubleExt on Rx<double?> { @@ -739,6 +754,7 @@ extension RxnDoubleExt on Rx<double?> {
739 if (value != null) { 754 if (value != null) {
740 return value! / other; 755 return value! / other;
741 } 756 }
  757 + return null;
742 } 758 }
743 759
744 /// Truncating division operator. 760 /// Truncating division operator.
@@ -749,6 +765,7 @@ extension RxnDoubleExt on Rx<double?> { @@ -749,6 +765,7 @@ extension RxnDoubleExt on Rx<double?> {
749 if (value != null) { 765 if (value != null) {
750 return value! ~/ other; 766 return value! ~/ other;
751 } 767 }
  768 + return null;
752 } 769 }
753 770
754 /// Negate operator. */ 771 /// Negate operator. */
@@ -756,6 +773,7 @@ extension RxnDoubleExt on Rx<double?> { @@ -756,6 +773,7 @@ extension RxnDoubleExt on Rx<double?> {
756 if (value != null) { 773 if (value != null) {
757 return -value!; 774 return -value!;
758 } 775 }
  776 + return null;
759 } 777 }
760 778
761 /// Returns the absolute value of this [double]. 779 /// Returns the absolute value of this [double].
@@ -1104,6 +1122,7 @@ extension RxnIntExt on Rx<int?> { @@ -1104,6 +1122,7 @@ extension RxnIntExt on Rx<int?> {
1104 if (value != null) { 1122 if (value != null) {
1105 return value! & other; 1123 return value! & other;
1106 } 1124 }
  1125 + return null;
1107 } 1126 }
1108 1127
1109 /// Bit-wise or operator. 1128 /// Bit-wise or operator.
@@ -1118,6 +1137,7 @@ extension RxnIntExt on Rx<int?> { @@ -1118,6 +1137,7 @@ extension RxnIntExt on Rx<int?> {
1118 if (value != null) { 1137 if (value != null) {
1119 return value! | other; 1138 return value! | other;
1120 } 1139 }
  1140 + return null;
1121 } 1141 }
1122 1142
1123 /// Bit-wise exclusive-or operator. 1143 /// Bit-wise exclusive-or operator.
@@ -1132,6 +1152,7 @@ extension RxnIntExt on Rx<int?> { @@ -1132,6 +1152,7 @@ extension RxnIntExt on Rx<int?> {
1132 if (value != null) { 1152 if (value != null) {
1133 return value! ^ other; 1153 return value! ^ other;
1134 } 1154 }
  1155 + return null;
1135 } 1156 }
1136 1157
1137 /// The bit-wise negate operator. 1158 /// The bit-wise negate operator.
@@ -1144,6 +1165,7 @@ extension RxnIntExt on Rx<int?> { @@ -1144,6 +1165,7 @@ extension RxnIntExt on Rx<int?> {
1144 if (value != null) { 1165 if (value != null) {
1145 return ~value!; 1166 return ~value!;
1146 } 1167 }
  1168 + return null;
1147 } 1169 }
1148 1170
1149 /// Shift the bits of this integer to the left by [shiftAmount]. 1171 /// Shift the bits of this integer to the left by [shiftAmount].
@@ -1160,6 +1182,7 @@ extension RxnIntExt on Rx<int?> { @@ -1160,6 +1182,7 @@ extension RxnIntExt on Rx<int?> {
1160 if (value != null) { 1182 if (value != null) {
1161 return value! << shiftAmount; 1183 return value! << shiftAmount;
1162 } 1184 }
  1185 + return null;
1163 } 1186 }
1164 1187
1165 /// Shift the bits of this integer to the right by [shiftAmount]. 1188 /// Shift the bits of this integer to the right by [shiftAmount].
@@ -1173,6 +1196,7 @@ extension RxnIntExt on Rx<int?> { @@ -1173,6 +1196,7 @@ extension RxnIntExt on Rx<int?> {
1173 if (value != null) { 1196 if (value != null) {
1174 return value! >> shiftAmount; 1197 return value! >> shiftAmount;
1175 } 1198 }
  1199 + return null;
1176 } 1200 }
1177 1201
1178 /// Returns this integer to the power of [exponent] modulo [modulus]. 1202 /// Returns this integer to the power of [exponent] modulo [modulus].
@@ -1290,6 +1314,7 @@ extension RxnIntExt on Rx<int?> { @@ -1290,6 +1314,7 @@ extension RxnIntExt on Rx<int?> {
1290 if (value != null) { 1314 if (value != null) {
1291 return -value!; 1315 return -value!;
1292 } 1316 }
  1317 + return null;
1293 } 1318 }
1294 1319
1295 /// Returns the absolute value of this integer. 1320 /// Returns the absolute value of this integer.
@@ -96,13 +96,13 @@ mixin FullLifeCycleMixin on FullLifeCycleController { @@ -96,13 +96,13 @@ mixin FullLifeCycleMixin on FullLifeCycleController {
96 @override 96 @override
97 void onInit() { 97 void onInit() {
98 super.onInit(); 98 super.onInit();
99 - WidgetsBinding.instance!.addObserver(this); 99 + ambiguate(WidgetsBinding.instance)!.addObserver(this);
100 } 100 }
101 101
102 @mustCallSuper 102 @mustCallSuper
103 @override 103 @override
104 void onClose() { 104 void onClose() {
105 - WidgetsBinding.instance!.removeObserver(this); 105 + ambiguate(WidgetsBinding.instance)!.removeObserver(this);
106 super.onClose(); 106 super.onClose();
107 } 107 }
108 108
@@ -3,6 +3,7 @@ import 'dart:async'; @@ -3,6 +3,7 @@ import 'dart:async';
3 import 'package:flutter/scheduler.dart'; 3 import 'package:flutter/scheduler.dart';
4 import 'package:flutter/widgets.dart'; 4 import 'package:flutter/widgets.dart';
5 5
  6 +import '../../../get_core/src/typedefs.dart';
6 import 'list_notifier.dart'; 7 import 'list_notifier.dart';
7 8
8 typedef ValueBuilderUpdateCallback<T> = void Function(T snapshot); 9 typedef ValueBuilderUpdateCallback<T> = void Function(T snapshot);
@@ -102,13 +103,14 @@ mixin ObserverComponent on ComponentElement { @@ -102,13 +103,14 @@ mixin ObserverComponent on ComponentElement {
102 103
103 Future<bool> _safeRebuild() async { 104 Future<bool> _safeRebuild() async {
104 if (dirty) return false; 105 if (dirty) return false;
105 - if (SchedulerBinding.instance == null) { 106 + if (ambiguate(SchedulerBinding.instance) == null) {
106 markNeedsBuild(); 107 markNeedsBuild();
107 } else { 108 } else {
108 // refresh was called during the building 109 // refresh was called during the building
109 - if (SchedulerBinding.instance!.schedulerPhase != SchedulerPhase.idle) { 110 + if (ambiguate(SchedulerBinding.instance)!.schedulerPhase
  111 + != SchedulerPhase.idle) {
110 // Await for the end of build 112 // Await for the end of build
111 - await SchedulerBinding.instance!.endOfFrame; 113 + await ambiguate(SchedulerBinding.instance)!.endOfFrame;
112 if (dirty) return false; 114 if (dirty) return false;
113 } 115 }
114 116
1 void main() { 1 void main() {
2 - // testWidgets('Back swipe dismiss interrupted by route push', (tester) async { 2 + // testWidgets('Back swipe dismiss interrupted by route push',
  3 + // (tester) async {
3 // // final scaffoldKey = GlobalKey(); 4 // // final scaffoldKey = GlobalKey();
4 5
5 // await tester.pumpWidget( 6 // await tester.pumpWidget(
@@ -59,7 +60,8 @@ void main() { @@ -59,7 +60,8 @@ void main() {
59 // expect(find.text('push'), findsOneWidget); 60 // expect(find.text('push'), findsOneWidget);
60 // expect( 61 // expect(
61 // tester.getTopLeft(find.ancestor( 62 // tester.getTopLeft(find.ancestor(
62 - // of: find.text('push'), matching: find.byType(CupertinoPageScaffold))), 63 + // of: find.text('push'),
  64 + // matching: find.byType(CupertinoPageScaffold))),
63 // Offset.zero, 65 // Offset.zero,
64 // ); 66 // );
65 // expect(find.text('route'), findsNothing); 67 // expect(find.text('route'), findsNothing);