Jonny Borges
Committed by GitHub
## [3.4.0]
- Added '[everAll]' Worker: Listen a List of '.obx'
- Added Workers dispose
- Fix transition.noTransition
- Fix TextField and VideoPlayController dispose before transition animation
## [3.3.0]
- Fix extensions (@stefandevo)
- Added CPF to utils options (@kauemurakami)
... ...
... ... @@ -41,7 +41,7 @@ extension MDQ on BuildContext {
dividedBy;
}
/// TODO: make docs about that
/// Divide the height proportionally by the given value
double ratio({
double dividedBy = 1,
double reducedByW = 0.0,
... ...
... ... @@ -870,13 +870,13 @@ class GetImpl implements GetService {
RouteSettings get routeSettings => settings;
Routing _routing = Routing();
final _routing = Routing();
Map<String, String> parameters = {};
void setRouting(Routing rt) {
_routing = rt;
}
// void setRouting(Routing rt) {
// _routing = rt;
// }
void setSettings(RouteSettings settings) {
settings = settings;
... ...
... ... @@ -129,7 +129,7 @@ class GetInstance {
if (i is DisposableInterface) {
i.onStart();
if (GetConfig.isLogEnable) print('[GET] $key has been initialized');
if (GetConfig.isLogEnable) print('[GETX] $key has been initialized');
}
}
... ... @@ -162,7 +162,7 @@ class GetInstance {
throw " $S not found. You need call put<$S>($S()) before";
if (GetConfig.isLogEnable)
print('[GET] $S instance was created at that time');
print('[GETX] $S instance was created at that time');
S _value = put<S>(GetConfig._factory[key].builder() as S);
if (!isDependencyInit<S>() &&
... ... @@ -192,13 +192,13 @@ class GetInstance {
if (i is DisposableInterface) {
i.onClose();
if (GetConfig.isLogEnable) print('[GET] onClose of $key called');
if (GetConfig.isLogEnable) print('[GETX] onClose of $key called');
}
if (builder != null) builder.dependency = null;
if (GetConfig._singl.containsKey(key)) {
print('error on remove $key');
} else {
if (GetConfig.isLogEnable) print('[GET] $key removed from memory');
if (GetConfig.isLogEnable) print('[GETX] $key removed from memory');
}
}
... ... @@ -230,21 +230,21 @@ class GetInstance {
FcBuilder builder = GetConfig._singl[newKey] as FcBuilder;
if (builder.permanent) {
print(
'[GET] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.');
'[GETX] [$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.');
return false;
}
final i = builder.dependency;
if (i is DisposableInterface) {
await i.onClose();
if (GetConfig.isLogEnable) print('[GET] onClose of $newKey called');
if (GetConfig.isLogEnable) print('[GETX] onClose of $newKey called');
}
GetConfig._singl.removeWhere((oldkey, value) => (oldkey == newKey));
if (GetConfig._singl.containsKey(newKey)) {
print('[GET] error on remove object $newKey');
print('[GETX] error on remove object $newKey');
} else {
if (GetConfig.isLogEnable) print('[GET] $newKey deleted from memory');
if (GetConfig.isLogEnable) print('[GETX] $newKey deleted from memory');
}
// GetConfig.routesKey?.remove(key);
return true;
... ...
... ... @@ -180,6 +180,8 @@ class GetMaterialApp extends StatelessWidget {
onDispose?.call();
},
initState: (i) {
print(
'[GETX] INITIALIZED: If you need help, join our community support channels: https://tinyurl.com/y3cp88l3');
if (locale != null) {
Get.locale = locale;
}
... ... @@ -221,8 +223,8 @@ class GetMaterialApp extends StatelessWidget {
: initialRoutesGenerate,
onUnknownRoute: onUnknownRoute,
navigatorObservers: (navigatorObservers == null
? <NavigatorObserver>[GetObserver(routingCallback)]
: <NavigatorObserver>[GetObserver(routingCallback)]
? <NavigatorObserver>[GetObserver(routingCallback, Get.routing)]
: <NavigatorObserver>[GetObserver(routingCallback, Get.routing)]
..addAll(navigatorObservers)),
builder: builder,
title: title ?? '',
... ...
... ... @@ -3,6 +3,7 @@ import 'dart:ui' show lerpDouble;
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:get/src/get_main.dart';
import 'package:get/src/instance/get_instance.dart';
import 'package:get/utils.dart';
... ... @@ -129,6 +130,14 @@ class GetPageRoute<T> extends PageRoute<T> {
bool get popGestureInProgress => isPopGestureInProgress(this);
@override
void dispose() {
if (GetConfig.smartManagement != SmartManagement.onlyBuilder) {
GetInstance().removeDependencyByRoute("${settings.name}");
}
super.dispose();
}
@override
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
if (fullscreenDialog && transition == null) {
... ... @@ -197,6 +206,14 @@ class GetPageRoute<T> extends PageRoute<T> {
child: child)
: child);
case Transition.noTransition:
return popGesture ?? Get.defaultPopGesture
? _CupertinoBackGestureDetector<T>(
enabledCallback: () => _isPopGestureEnabled<T>(this),
onStartPopGesture: () => _startPopGesture<T>(this),
child: child)
: child;
case Transition.rightToLeft:
return SlideRightTransition().buildTransitions(
context,
... ...
import 'package:flutter/widgets.dart';
import 'package:get/src/instance/get_instance.dart';
import 'package:get/src/root/smart_management.dart';
import '../../get_main.dart';
class Routing {
String current;
... ... @@ -14,22 +12,28 @@ class Routing {
bool isBottomSheet;
bool isDialog;
Routing({
this.current,
this.previous,
this.current = '',
this.previous = '',
this.args,
this.removed,
this.removed = '',
this.route,
this.isBack,
this.isSnackbar,
this.isBottomSheet,
this.isDialog,
});
void update(void fn(Routing value)) {
fn(this);
GetConfig.currentRoute = this.current;
}
}
class GetObserver extends NavigatorObserver {
final Function(Routing) routing;
GetObserver([this.routing]);
GetObserver([this.routing, this._routeSend]);
final Routing _routeSend;
Route<dynamic> route;
bool isBack;
... ... @@ -46,43 +50,30 @@ class GetObserver extends NavigatorObserver {
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
if ('${route?.settings?.name}' == 'snackbar') {
if (GetConfig.isLogEnable)
print("[OPEN SNACKBAR] ${route?.settings?.name}");
print("[GETX] OPEN SNACKBAR ${route?.settings?.name}");
} else if ('${route?.settings?.name}' == 'bottomsheet') {
if (GetConfig.isLogEnable)
print("[OPEN BOTTOMSHEET] ${route?.settings?.name}");
print("[GETX] OPEN BOTTOMSHEET ${route?.settings?.name}");
} else if ('${route?.settings?.name}' == 'dialog') {
if (GetConfig.isLogEnable)
print("[OPEN DIALOG] ${route?.settings?.name}");
print("[GETX] OPEN DIALOG ${route?.settings?.name}");
} else {
if (GetConfig.isLogEnable)
print("[GOING TO ROUTE] ${route?.settings?.name}");
print("[GETX] GOING TO ROUTE ${route?.settings?.name}");
}
isSnackbar = '${route?.settings?.name}' == 'snackbar';
isDialog = '${route?.settings?.name}' == 'dialog';
isBottomSheet = '${route?.settings?.name}' == 'bottomsheet';
current = '${route?.settings?.name}';
previous = '${previousRoute?.settings?.name}';
args = route?.settings?.arguments;
// previousArgs = previousRoute?.settings?.arguments;
final routeSend = Routing(
removed: null,
isBack: false,
route: route,
current: '${route?.settings?.name}',
previous: '${previousRoute?.settings?.name}',
args: route?.settings?.arguments,
// previousArgs: previousRoute?.settings?.arguments,
isSnackbar: isSnackbar,
isDialog: isDialog,
isBottomSheet: isBottomSheet,
);
if (routing != null) {
routing(routeSend);
}
GetConfig.currentRoute = current;
Get.setRouting(routeSend);
_routeSend.update((value) {
if (route is PageRoute) value.current = '${route?.settings?.name}';
value.args = route?.settings?.arguments;
value.route = route;
value.isBack = false;
value.removed = '';
value.previous = '${previousRoute?.settings?.name}';
value.isSnackbar = '${route?.settings?.name}' == 'snackbar';
value.isBottomSheet = '${route?.settings?.name}' == 'bottomsheet';
value.isDialog = '${route?.settings?.name}' == 'dialog';
});
if (routing != null) routing(_routeSend);
}
@override
... ... @@ -91,112 +82,67 @@ class GetObserver extends NavigatorObserver {
if ('${route?.settings?.name}' == 'snackbar') {
if (GetConfig.isLogEnable)
print("[CLOSE SNACKBAR] ${route?.settings?.name}");
print("[GETX] CLOSE SNACKBAR ${route?.settings?.name}");
} else if ('${route?.settings?.name}' == 'bottomsheet') {
if (GetConfig.isLogEnable)
print("[CLOSE BOTTOMSHEET] ${route?.settings?.name}");
print("[GETX] CLOSE BOTTOMSHEET ${route?.settings?.name}");
} else if ('${route?.settings?.name}' == 'dialog') {
if (GetConfig.isLogEnable)
print("[CLOSE DIALOG] ${route?.settings?.name}");
print("[GETX] CLOSE DIALOG ${route?.settings?.name}");
} else {
if (GetConfig.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}");
}
if (GetConfig.smartManagement != SmartManagement.onlyBuilder) {
GetInstance().removeDependencyByRoute("${route?.settings?.name}");
if (GetConfig.isLogEnable)
print("[GETX] BACK ROUTE ${route?.settings?.name}");
}
isSnackbar = false;
isDialog = false;
isBottomSheet = false;
current = '${previousRoute?.settings?.name}';
previous = '${route?.settings?.name}';
args = previousRoute?.settings?.arguments;
// previousArgs = route?.settings?.arguments;
final routeSend = Routing(
removed: null,
isBack: true,
route: previousRoute,
current: '${previousRoute?.settings?.name}',
previous: '${route?.settings?.name}',
args: previousRoute?.settings?.arguments,
// previousArgs: route?.settings?.arguments,
isSnackbar: false, //'${route?.settings?.name}' == 'snackbar',
isDialog: false, //'${route?.settings?.name}' == 'dialog',
isBottomSheet: false, //'${route?.settings?.name}' == 'bottomsheet',
);
if (routing != null) {
routing(routeSend);
}
GetConfig.currentRoute = current;
Get.setRouting(routeSend);
_routeSend.update((value) {
if (previousRoute is PageRoute)
value.current = '${previousRoute?.settings?.name}';
value.args = route?.settings?.arguments;
value.route = previousRoute;
value.isBack = true;
value.removed = '';
value.previous = '${route?.settings?.name}';
value.isSnackbar = false;
value.isBottomSheet = false;
value.isDialog = false;
});
if (routing != null) routing(_routeSend);
}
@override
void didReplace({Route newRoute, Route oldRoute}) {
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
if (GetConfig.isLogEnable)
print("[REPLACE ROUTE] ${oldRoute?.settings?.name}");
if (GetConfig.isLogEnable) print("[NEW ROUTE] ${newRoute?.settings?.name}");
if (GetConfig.smartManagement == SmartManagement.full) {
GetInstance().removeDependencyByRoute("${oldRoute?.settings?.name}");
}
isSnackbar = false;
isDialog = false;
isBottomSheet = false;
final routeSend = Routing(
removed: null, // add '${oldRoute?.settings?.name}' or remain null ???
isBack: false,
route: newRoute,
current: '${newRoute?.settings?.name}',
previous: '${oldRoute?.settings?.name}',
args: newRoute?.settings?.arguments,
// previousArgs: newRoute?.settings?.arguments,
isSnackbar: false,
isBottomSheet: false,
isDialog: false,
);
if (routing != null) {
routing(routeSend);
}
GetConfig.currentRoute = current;
Get.setRouting(routeSend);
print("[GETX] REPLACE ROUTE ${oldRoute?.settings?.name}");
if (GetConfig.isLogEnable)
print("[GETX] NEW ROUTE ${newRoute?.settings?.name}");
_routeSend.update((value) {
if (newRoute is PageRoute) value.current = '${newRoute?.settings?.name}';
value.args = newRoute?.settings?.arguments;
value.route = newRoute;
value.isBack = false;
value.removed = '';
value.previous = '${oldRoute?.settings?.name}';
value.isSnackbar = false;
value.isBottomSheet = false;
value.isDialog = false;
});
if (routing != null) routing(_routeSend);
}
@override
void didRemove(Route route, Route previousRoute) {
super.didRemove(route, previousRoute);
if (GetConfig.isLogEnable)
print("[REMOVING ROUTE] ${route?.settings?.name}");
if (GetConfig.smartManagement == SmartManagement.full) {
GetInstance().removeDependencyByRoute("${route?.settings?.name}");
}
final routeSend = Routing(
isBack: false,
route: previousRoute,
// current: '${previousRoute?.settings?.name}',
current: current,
args: args,
removed: '${route?.settings?.name}',
// args: previousRoute?.settings?.arguments,
isSnackbar: isSnackbar,
isBottomSheet: isBottomSheet,
isDialog: isDialog,
// previousArgs: route?.settings?.arguments,
);
if (routing != null) {
routing(routeSend);
}
GetConfig.currentRoute = current;
Get.setRouting(routeSend);
print("[GETX] REMOVING ROUTE ${route?.settings?.name}");
_routeSend.update((value) {
value.route = previousRoute;
value.isBack = false;
value.removed = '${route?.settings?.name}';
value.previous = '${route?.settings?.name}';
});
if (routing != null) routing(_routeSend);
}
}
... ...
import 'dart:async';
import 'package:get/get.dart';
import 'rx_interface.dart';
import 'utils/debouncer.dart';
void ever(RxInterface listener, Function(dynamic) callback,
Worker ever(RxInterface listener, Function(dynamic) callback,
{bool condition = true}) {
listener.subject.stream.listen((event) {
if (condition) {
callback(event);
}
StreamSubscription sub = listener.subject.stream.listen((event) {
if (condition) callback(event);
});
Future<void> cancel() {
return sub.cancel();
}
return Worker(cancel, '[ever]');
}
void once(RxInterface listener, Function(dynamic) callback,
Worker everAll(List<RxInterface> listener, Function(dynamic) callback,
{bool condition = true}) {
List<StreamSubscription> evers = <StreamSubscription>[];
for (var i in listener) {
StreamSubscription sub = i.subject.stream.listen((event) {
if (condition) callback(event);
});
evers.add(sub);
}
Future<void> cancel() {
for (var i in evers) {
i.cancel();
}
return Future.value(() {});
}
return Worker(cancel, '[everAll]');
}
Worker once(RxInterface listener, Function(dynamic) callback,
{bool condition = true}) {
StreamSubscription sub;
int times = 0;
listener.subject.stream.listen((event) {
sub = listener.subject.stream.listen((event) {
if (!condition) return null;
times++;
if (times < 2) {
callback(event);
} else {
sub.cancel();
}
});
Future<void> cancel() {
return sub.cancel();
}
return Worker(cancel, '[once]');
}
void interval(RxInterface listener, Function(dynamic) callback,
Worker interval(RxInterface listener, Function(dynamic) callback,
{Duration time, bool condition = true}) {
bool debounceActive = false;
listener.subject.stream.listen((event) async {
StreamSubscription sub = listener.subject.stream.listen((event) async {
if (debounceActive || !condition) return null;
debounceActive = true;
await Future.delayed(time ?? Duration(seconds: 1));
debounceActive = false;
callback(event);
});
Future<void> cancel() {
return sub.cancel();
}
return Worker(cancel, '[interval]');
}
void debounce(RxInterface listener, Function(dynamic) callback,
Worker debounce(RxInterface listener, Function(dynamic) callback,
{Duration time}) {
final _debouncer = Debouncer(delay: time ?? Duration(milliseconds: 800));
listener.subject.stream.listen((event) {
StreamSubscription sub = listener.subject.stream.listen((event) {
_debouncer(() {
callback(event);
});
});
Future<void> cancel() {
return sub.cancel();
}
return Worker(cancel, '[debounce]');
}
class Worker {
Worker(this.worker, this.type);
final Future<void> Function() worker;
final String type;
void _message() {
if (GetConfig.isLogEnable) print('[Getx] Worker $type disposed');
}
void dispose() {
worker();
_message();
}
void call() {
worker();
_message();
}
}
... ...
import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:get/src/instance/get_instance.dart';
import 'package:get/src/root/smart_management.dart';
... ... @@ -34,6 +36,7 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> {
RxInterface _observer;
T controller;
bool isCreator = false;
StreamSubscription subs;
@override
void initState() {
... ... @@ -60,10 +63,10 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> {
controller?.onStart();
}
if (widget.initState != null) widget.initState(this);
if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) {
controller?.onStart();
}
_observer.subject.stream.listen((data) => setState(() {}));
// if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) {
// controller?.onStart();
// }
subs = _observer.subject.stream.listen((data) => setState(() {}));
super.initState();
}
... ... @@ -89,7 +92,7 @@ class GetImplXState<T extends DisposableInterface> extends State<GetX<T>> {
GetInstance().delete<T>();
}
}
subs.cancel();
_observer.close();
controller = null;
isCreator = null;
... ...
... ... @@ -66,6 +66,7 @@ class _RxImpl<T> implements RxInterface<T> {
stream.listen(onData, onError: onError, onDone: onDone);
void bindStream(Stream<T> stream) => stream.listen((va) => value = va);
Stream<R> map<R>(R mapper(T data)) => stream.map(mapper);
}
... ...
... ... @@ -65,7 +65,7 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
@override
void initState() {
super.initState();
if (widget.initState != null) widget.initState(this);
if (widget.global) {
final isPrepared = GetInstance().isPrepared<T>(tag: widget.tag);
final isRegistred = GetInstance().isRegistred<T>(tag: widget.tag);
... ... @@ -96,7 +96,7 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> {
controller._updaters.add(real);
controller?.onStart();
}
if (widget.initState != null) widget.initState(this);
if (isCreator && GetConfig.smartManagement == SmartManagement.onlyBuilder) {
controller?.onStart();
}
... ...
name: get
description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version: 3.3.0
version: 3.4.0
homepage: https://github.com/jonataslaw/get
environment:
... ...