Jonny Borges
Committed by GitHub

Add files via upload

## [2.5.10]
- Removed remnants of previousArgs on routeObserver.
This feature had been deprecated in previous updates, and was removed in version 2.5.8. Some remaining references on the routeObserver were causing exceptions in version 2.5.9, and were removed completely in version 2.5.10.
## [2.5.9]
- Fix Get.find with named instance
## [2.5.8]
- Added docs
... ...
... ... @@ -8,8 +8,8 @@ export 'src/snackbar/snack_route.dart';
export 'src/state/get_state.dart';
export 'src/rx/rx_interface.dart';
export 'src/rx/rx_impl.dart';
export 'src/rx/rx_event.dart';
export 'src/rx/rx_getbuilder.dart';
export 'src/rx/rx_listview_builder.dart';
export 'src/root/root_widget.dart';
export 'src/routes/default_route.dart';
export 'src/routes/get_route.dart';
... ...
... ... @@ -144,11 +144,6 @@ class Get {
_get.global(id).currentState.pop(result);
}
// /// Experimental API to back from overlay
// static void backE({dynamic result}) {
// Navigator.pop(overlayContext);
// }
/// It will close as many screens as you define. Times must be> 0;
static void close(int times, [int id]) {
if ((times == null) || (times < 1)) {
... ... @@ -228,14 +223,13 @@ class Get {
/// Api from showGeneralDialog with no context
static Future<T> generalDialog<T>({
@required RoutePageBuilder pageBuilder,
bool barrierDismissible,
String barrierLabel,
Color barrierColor,
Duration transitionDuration,
bool barrierDismissible = true,
Color barrierColor = const Color(0x80000000),
Duration transitionDuration = const Duration(milliseconds: 200),
RouteTransitionsBuilder transitionBuilder,
bool useRootNavigator = true,
RouteSettings routeSettings,
// RouteSettings routeSettings
}) {
return showGeneralDialog(
pageBuilder: pageBuilder,
... ... @@ -555,6 +549,7 @@ class Get {
if (instantInit) {
getBar.show();
} else {
Get()._routing.isSnackbar = true;
SchedulerBinding.instance.addPostFrameCallback((_) {
getBar.show();
});
... ... @@ -570,24 +565,24 @@ class Get {
bool defaultGlobalState,
Transition defaultTransition}) {
if (enableLog != null) {
_get._enableLog = enableLog;
Get()._enableLog = enableLog;
}
if (defaultPopGesture != null) {
_get._defaultPopGesture = defaultPopGesture;
Get()._defaultPopGesture = defaultPopGesture;
}
if (defaultOpaqueRoute != null) {
_get._defaultOpaqueRoute = defaultOpaqueRoute;
Get()._defaultOpaqueRoute = defaultOpaqueRoute;
}
if (defaultTransition != null) {
_get._defaultTransition = defaultTransition;
Get()._defaultTransition = defaultTransition;
}
if (defaultDurationTransition != null) {
_get._defaultDurationTransition = defaultDurationTransition;
Get()._defaultDurationTransition = defaultDurationTransition;
}
if (defaultGlobalState != null) {
_get._defaultGlobalState = defaultGlobalState;
Get()._defaultGlobalState = defaultGlobalState;
}
}
... ... @@ -756,6 +751,8 @@ class Get {
static bool isRegistred<S>({String name}) =>
Get()._singl.containsKey(_getKey(S, name));
static bool isPrepared<S>() => Get()._factory.containsKey(S);
/// give access to Routing API from GetObserver
static Routing get routing => Get()._routing;
... ... @@ -790,8 +787,8 @@ class Get {
static set obs(RxInterface observer) => Get()._obs = observer;
/// give arguments from previous route
static get previousArguments => Get()._routing.previousArgs;
// /// give arguments from previous route
// static get previousArguments => Get()._routing.previousArgs;
/// give name from current route
static get currentRoute => Get()._routing.current;
... ...
... ... @@ -199,8 +199,9 @@ class GetMaterialApp extends StatelessWidget {
home: home,
routes: routes ?? const <String, WidgetBuilder>{},
initialRoute: initialRoute,
onGenerateRoute:
(namedRoutes == null ? onGenerateRoute : namedRoutesGenerate),
onGenerateRoute: (namedRoutes == null || onUnknownRoute != null
? onGenerateRoute
: namedRoutesGenerate),
onGenerateInitialRoutes: onGenerateInitialRoutes,
onUnknownRoute: onUnknownRoute,
navigatorObservers: (navigatorObservers == null
... ...
... ... @@ -12,11 +12,12 @@ class GetRoute {
final Alignment alignment;
final bool maintainState;
final bool opaque;
final Widget customTransition;
final Duration transitionDuration;
final bool fullscreenDialog;
final RouteSettings settings;
GetRoute({
const GetRoute({
@required this.page,
this.title,
this.settings,
... ... @@ -28,6 +29,7 @@ class GetRoute {
this.transitionDuration = const Duration(milliseconds: 400),
this.popGesture,
this.transition,
this.customTransition,
this.fullscreenDialog = false,
}) : assert(page != null),
assert(maintainState != null),
... ...
... ... @@ -3,21 +3,19 @@ import 'package:flutter/widgets.dart';
import '../../get_main.dart';
class Routing {
final current;
final previous;
final args;
final previousArgs;
final removed;
final Route<dynamic> route;
final bool isBack;
final bool isSnackbar;
final bool isBottomSheet;
final bool isDialog;
String current;
String previous;
Object args;
String removed;
Route<dynamic> route;
bool isBack;
bool isSnackbar;
bool isBottomSheet;
bool isDialog;
Routing({
this.current,
this.previous,
this.args,
this.previousArgs,
this.removed,
this.route,
this.isBack,
... ... @@ -37,6 +35,11 @@ class GetObserver extends NavigatorObserver {
bool isSnackbar;
bool isBottomSheet;
bool isDialog;
String current;
String previous;
Object args;
// String previousArgs;
String removed;
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
... ... @@ -53,6 +56,10 @@ class GetObserver extends NavigatorObserver {
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,
... ... @@ -61,7 +68,7 @@ class GetObserver extends NavigatorObserver {
current: '${route?.settings?.name}',
previous: '${previousRoute?.settings?.name}',
args: route?.settings?.arguments,
previousArgs: previousRoute?.settings?.arguments,
// previousArgs: previousRoute?.settings?.arguments,
isSnackbar: isSnackbar,
isDialog: isDialog,
isBottomSheet: isBottomSheet,
... ... @@ -92,6 +99,10 @@ class GetObserver extends NavigatorObserver {
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,
... ... @@ -100,7 +111,7 @@ class GetObserver extends NavigatorObserver {
current: '${previousRoute?.settings?.name}',
previous: '${route?.settings?.name}',
args: previousRoute?.settings?.arguments,
previousArgs: route?.settings?.arguments,
// previousArgs: route?.settings?.arguments,
isSnackbar: false, //'${route?.settings?.name}' == 'snackbar',
isDialog: false, //'${route?.settings?.name}' == 'dialog',
isBottomSheet: false, //'${route?.settings?.name}' == 'bottomsheet',
... ... @@ -123,16 +134,17 @@ class GetObserver extends NavigatorObserver {
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,
isSnackbar: false,
isBottomSheet: false,
isDialog: false,
previousArgs: null);
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);
... ... @@ -144,17 +156,19 @@ class GetObserver extends NavigatorObserver {
void didRemove(Route route, Route previousRoute) {
super.didRemove(route, previousRoute);
if (Get.isLogEnable) print("[REMOVING ROUTE] ${route?.settings?.name}");
final routeSend = Routing(
isBack: false,
route: previousRoute,
current: '${previousRoute?.settings?.name}',
removed: '${route?.settings?.name}',
isSnackbar: isSnackbar,
isBottomSheet: isBottomSheet,
isDialog: isDialog,
args: previousRoute?.settings?.arguments,
previousArgs: route?.settings?.arguments);
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);
... ...
... ... @@ -9,5 +9,6 @@ enum Transition {
size,
rightToLeftWithFade,
leftToRightWithFade,
cupertino
cupertino,
custom
}
... ...
// import '../../get.dart';
// class Reaction extends Rx {
// dynamic Function() listener;
// void Function(dynamic) callback;
// Reaction(this.listener, this.callback) : super() {
// subject.stream.listen((_) {
// callback(_);
// });
// var previousObserver = Get.obs;
// Get.obs = this;
// listener();
// Get.obs = previousObserver;
// }
// void dispose() {
// close();
// }
// }
// class When extends Rx {
// dynamic Function() listener;
// void Function(dynamic) callback;
// When(this.listener, this.callback) : super() {
// subject.stream.listen((_) {
// callback(_);
// dispose();
// });
// var previousObserver = Get.obs;
// Get.obs = this;
// listener();
// Get.obs = previousObserver;
// }
// void dispose() {
// close();
// }
// }
... ...
... ... @@ -7,21 +7,22 @@ import 'rx_interface.dart';
class GetX<T extends RxController> extends StatefulWidget {
final Widget Function(T) builder;
final bool global;
final Stream Function(T) stream;
final StreamController Function(T) streamController;
// final Stream Function(T) stream;
// final StreamController Function(T) streamController;
final bool autoRemove;
final void Function(State state) initState, dispose, didChangeDependencies;
final T init;
GetX(
{this.builder,
this.global = true,
this.autoRemove = true,
this.initState,
this.stream,
this.dispose,
this.didChangeDependencies,
this.init,
this.streamController});
const GetX({
this.builder,
this.global = true,
this.autoRemove = true,
this.initState,
// this.stream,
this.dispose,
this.didChangeDependencies,
this.init,
// this.streamController
});
_GetXState<T> createState() => _GetXState<T>();
}
... ... @@ -29,6 +30,7 @@ class _GetXState<T extends RxController> extends State<GetX<T>> {
RxInterface _observer;
StreamSubscription _listenSubscription;
T controller;
bool isCreator = false;
_GetXState() {
_observer = ListX();
... ... @@ -37,21 +39,30 @@ class _GetXState<T extends RxController> extends State<GetX<T>> {
@override
void initState() {
if (widget.global) {
if (Get.isRegistred<T>()) {
if (Get.isPrepared<T>()) {
isCreator = true;
controller = Get.find<T>();
} else if (Get.isRegistred<T>() && !Get.isPrepared<T>()) {
controller = Get.find<T>();
isCreator = false;
} else {
controller = widget.init;
isCreator = true;
Get.put<T>(controller);
}
} else {
controller = widget.init;
isCreator = true;
}
if (widget.initState != null) widget.initState(this);
try {
controller?.onInit();
} catch (e) {
if (Get.isLogEnable) print("Failure on call onInit");
if (isCreator) {
try {
controller?.onInit();
} catch (e) {
if (Get.isLogEnable) print("Failure on call onInit");
}
}
_listenSubscription = _observer.subject.stream.listen((data) {
setState(() {});
});
... ... @@ -62,15 +73,20 @@ class _GetXState<T extends RxController> extends State<GetX<T>> {
void dispose() {
if (widget.dispose != null) widget.dispose(this);
if (widget.init != null) {
if (isCreator) {
if (widget.autoRemove && Get.isRegistred<T>()) {
controller.onClose();
Get.delete<T>();
}
} else {
controller.onClose();
}
controller.onClose();
// controller.onClose();
_observer.close();
_listenSubscription?.cancel();
controller = null;
isCreator = null;
super.dispose();
}
... ...
... ... @@ -253,8 +253,6 @@ class ListX<E> extends DelegatingList<E> implements List<E>, RxInterface<E> {
return this;
}
// int get length => (value as List).length;
set value(E val) {
assign(val);
}
... ...
... ... @@ -4,11 +4,12 @@ import '../get_main.dart';
class RealState {
final State state;
final String id;
RealState({this.state, this.id});
final bool isCreator;
const RealState({this.state, this.id, this.isCreator = false});
}
class GetController extends State {
Map<int, List<RealState>> _allStates = {};
List<RealState> _allStates = [];
/// Update GetBuilder with update(this)
void update(GetController controller,
... ... @@ -16,15 +17,15 @@ class GetController extends State {
if (controller == null || !condition) return;
if (ids == null) {
var all = _allStates[controller.hashCode];
all.forEach((rs) {
// _allStates[controller.hashCode];
_allStates.forEach((rs) {
if (rs.state != null && rs.state.mounted) rs.state.setState(() {});
});
} else {
ids.forEach(
(s) {
var all = _allStates[controller.hashCode];
all.forEach((rs) {
// var all = _allStates[controller.hashCode];
_allStates.forEach((rs) {
if (rs.state != null && rs.state.mounted && rs.id == s)
rs.state.setState(() {});
});
... ... @@ -49,7 +50,7 @@ class GetBuilder<T extends GetController> extends StatefulWidget {
final void Function(State state) initState, dispose, didChangeDependencies;
final void Function(GetBuilder oldWidget, State state) didUpdateWidget;
final T init;
GetBuilder({
const GetBuilder({
Key key,
this.init,
this.global = true,
... ... @@ -68,39 +69,46 @@ class GetBuilder<T extends GetController> extends StatefulWidget {
class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> {
T controller;
RealState real;
bool isCreator = false;
@override
void initState() {
super.initState();
if (widget.global) {
if (Get.isRegistred<T>()) {
if (Get.isPrepared<T>()) {
isCreator = true;
controller = Get.find<T>();
real = RealState(state: this, id: widget.id, isCreator: isCreator);
controller._allStates.add(real);
} else if (Get.isRegistred<T>() && !Get.isPrepared<T>()) {
controller = Get.find<T>();
if (controller._allStates[controller.hashCode] == null) {
controller._allStates[controller.hashCode] = [];
}
controller._allStates[controller.hashCode]
.add(RealState(state: this, id: widget.id));
isCreator = false;
real = RealState(state: this, id: widget.id, isCreator: isCreator);
controller._allStates.add(real);
} else {
controller = widget.init;
if (controller._allStates[controller.hashCode] == null) {
controller._allStates[controller.hashCode] = [];
}
controller._allStates[controller.hashCode]
.add(RealState(state: this, id: widget.id));
isCreator = true;
real = RealState(state: this, id: widget.id, isCreator: isCreator);
controller._allStates.add(real);
Get.put<T>(controller);
}
} else {
controller = widget.init;
if (controller._allStates[controller.hashCode] == null) {
controller._allStates[controller.hashCode] = [];
}
controller._allStates[controller.hashCode]
.add(RealState(state: this, id: widget.id));
isCreator = true;
real = RealState(state: this, id: widget.id, isCreator: isCreator);
controller._allStates.add(real);
}
if (widget.initState != null) widget.initState(this);
try {
controller?.onInit();
} catch (e) {
if (Get.isLogEnable) print("Controller is not attach");
if (isCreator) {
try {
controller?.onInit();
} catch (e) {
if (Get.isLogEnable) print("Controller is not attach");
}
}
}
... ... @@ -108,29 +116,23 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> {
void dispose() async {
super.dispose();
if (widget.init != null) {
var b = controller;
if (b._allStates[controller.hashCode].hashCode == this.hashCode) {
b._allStates.remove(controller.hashCode);
}
} else {
var b = controller;
if (b._allStates[controller.hashCode].hashCode == this.hashCode) {
b._allStates.remove(controller.hashCode);
}
}
if (widget.dispose != null) widget.dispose(this);
if (widget.init != null) {
if (isCreator) {
if (widget.autoRemove && Get.isRegistred<T>()) {
controller.onClose();
controller._allStates.remove(real);
Get.delete<T>();
}
} else {
// controller._allStates[controller].remove(this);
controller._allStates[controller.hashCode]
.remove(RealState(state: this, id: widget.id));
controller._allStates.remove(real);
}
/// force GC remove this
controller = null;
real = null;
isCreator = null;
}
@override
... ... @@ -151,5 +153,3 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> {
return widget.builder(controller);
}
}
... ...
name: get
description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version: 2.5.9
version: 2.5.10
homepage: https://github.com/jonataslaw/get
environment:
... ...