Skip to content

Commit

Permalink
added backward compability (Flutter 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjundevlucid committed May 14, 2022
1 parent b5ef10a commit 6eb294b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/get_core/src/typedefs.dart
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
typedef ValueUpdater<T> = T Function();

T? ambiguate<T>(T? value) => value;
5 changes: 4 additions & 1 deletion lib/get_instance/src/lifecycle.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';

import '../../get.dart';

/// The [GetLifeCycle]
///
/// ```dart
Expand All @@ -16,7 +18,8 @@ mixin GetLifeCycleMixin {
@protected
@mustCallSuper
void onInit() {
SchedulerBinding.instance?.addPostFrameCallback((_) => onReady());
ambiguate(SchedulerBinding.instance)
?.addPostFrameCallback((_) => onReady());
}

/// Called 1 frame after onInit(). It is the perfect place to enter
Expand Down
4 changes: 2 additions & 2 deletions lib/get_navigation/src/extension_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ extension ExtensionSnackbar on GetInterface {
if (instantInit) {
controller.show();
} else {
SchedulerBinding.instance!.addPostFrameCallback((_) {
ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) {
controller.show();
});
}
Expand Down Expand Up @@ -469,7 +469,7 @@ extension ExtensionSnackbar on GetInterface {
controller.show();
} else {
//routing.isSnackbar = true;
SchedulerBinding.instance!.addPostFrameCallback((_) {
ambiguate(SchedulerBinding.instance)!.addPostFrameCallback((_) {
controller.show();
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/get_navigation/src/router_report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RouterReportManager<T> {

void reportRouteDispose(T disposed) {
if (Get.smartManagement != SmartManagement.onlyBuilder) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
ambiguate(WidgetsBinding.instance)!.addPostFrameCallback((_) {
_removeDependencyByRoute(disposed);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/get_navigation/src/snackbar/snackbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ You need to either use message[String], or messageText[Widget] or define a userI
}

void _configureLeftBarFuture() {
SchedulerBinding.instance!.addPostFrameCallback(
ambiguate(SchedulerBinding.instance)!.addPostFrameCallback(
(_) {
final keyContext = _backgroundBoxKey.currentContext;
if (keyContext != null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/get_state_manager/src/simple/get_controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ mixin FullLifeCycleMixin on FullLifeCycleController {
@override
void onInit() {
super.onInit();
WidgetsBinding.instance!.addObserver(this);
ambiguate(WidgetsBinding.instance)!.addObserver(this);
}

@mustCallSuper
@override
void onClose() {
WidgetsBinding.instance!.removeObserver(this);
ambiguate(WidgetsBinding.instance)!.removeObserver(this);
super.onClose();
}

Expand Down
8 changes: 5 additions & 3 deletions lib/get_state_manager/src/simple/simple_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';

import '../../../get_core/src/typedefs.dart';
import 'list_notifier.dart';

typedef ValueBuilderUpdateCallback<T> = void Function(T snapshot);
Expand Down Expand Up @@ -102,13 +103,14 @@ mixin ObserverComponent on ComponentElement {

Future<bool> _safeRebuild() async {
if (dirty) return false;
if (SchedulerBinding.instance == null) {
if (ambiguate(SchedulerBinding.instance) == null) {
markNeedsBuild();
} else {
// refresh was called during the building
if (SchedulerBinding.instance!.schedulerPhase != SchedulerPhase.idle) {
if (ambiguate(SchedulerBinding.instance)!.schedulerPhase
!= SchedulerPhase.idle) {
// Await for the end of build
await SchedulerBinding.instance!.endOfFrame;
await ambiguate(SchedulerBinding.instance)!.endOfFrame;
if (dirty) return false;
}

Expand Down

0 comments on commit 6eb294b

Please sign in to comment.