Jonny Borges
Committed by GitHub

Merge pull request #2162 from jonataslaw/navigator-rework

fix all binding types
... ... @@ -7,7 +7,7 @@ export 'get_common/get_reset.dart';
export 'get_connect/connect.dart';
export 'get_core/get_core.dart';
export 'get_instance/get_instance.dart';
export 'get_navigation/get_navigation.dart' hide FirstWhereOrNullExt;
export 'get_navigation/get_navigation.dart';
export 'get_rx/get_rx.dart';
export 'get_state_manager/get_state_manager.dart';
export 'get_utils/get_utils.dart';
... ...
... ... @@ -511,7 +511,7 @@ extension GetNavigationExt on GetInterface {
String? routeName,
bool fullscreenDialog = false,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool preventDuplicates = true,
bool? popGesture,
bool showCupertinoParallax = true,
... ... @@ -889,7 +889,7 @@ extension GetNavigationExt on GetInterface {
int? id,
String? routeName,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool fullscreenDialog = false,
bool preventDuplicates = true,
Duration? duration,
... ... @@ -968,7 +968,7 @@ extension GetNavigationExt on GetInterface {
int? id,
String? routeName,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool fullscreenDialog = false,
Transition? transition,
Curve? curve,
... ...
... ... @@ -51,7 +51,7 @@ class GetPageRoute<T> extends PageRoute<T>
this.customTransition,
this.barrierDismissible = false,
this.barrierColor,
this.bindings,
this.bindings = const [],
this.binds,
this.routeName,
this.page,
... ... @@ -73,7 +73,7 @@ class GetPageRoute<T> extends PageRoute<T>
final String? routeName;
//final String reference;
final CustomTransition? customTransition;
final List<BindingsInterface>? bindings;
final List<BindingsInterface> bindings;
final Map<String, String>? parameter;
final List<Bind>? binds;
... ... @@ -113,41 +113,33 @@ class GetPageRoute<T> extends PageRoute<T>
if (_child != null) return _child!;
final middlewareRunner = MiddlewareRunner(middlewares);
final localbinds = [
if (binds != null) ...binds!,
];
final localbindings = [
if (bindings != null) ...bindings!,
];
final localbinds = [if (binds != null) ...binds!];
final bindingsToBind = middlewareRunner
.runOnBindingsStart(bindings != null ? localbindings : localbinds);
/// Retrocompatibility workaround, remove this when Bindings api
/// have been removed
if (bindingsToBind != null &&
bindingsToBind is! List<Bind> &&
bindingsToBind is List<BindingsInterface>) {
for (final binding in bindingsToBind) {
binding.dependencies();
}
}
.runOnBindingsStart(bindings.isNotEmpty ? bindings : localbinds);
final pageToBuild = middlewareRunner.runOnPageBuildStart(page)!;
if (bindingsToBind != null &&
bindingsToBind.isNotEmpty &&
bindingsToBind is List<Bind>) {
if (bindingsToBind != null && bindingsToBind.isNotEmpty) {
if (bindingsToBind is List<BindingsInterface>) {
for (final item in bindingsToBind) {
final dep = item.dependencies();
if (dep is List<Bind>) {
_child = Binds(
child: middlewareRunner.runOnPageBuilt(pageToBuild()),
binds: dep,
);
}
}
} else if (bindingsToBind is List<Bind>) {
_child = Binds(
child: middlewareRunner.runOnPageBuilt(pageToBuild()),
binds: bindingsToBind,
);
} else {
_child = middlewareRunner.runOnPageBuilt(pageToBuild());
}
}
return _child!;
return _child ??= middlewareRunner.runOnPageBuilt(pageToBuild());
}
@override
... ...
... ... @@ -2,7 +2,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import '../../../get.dart';
import 'parse_route.dart';
class GetInformationParser extends RouteInformationParser<RouteDecoder> {
final String initialRoute;
... ...
... ... @@ -15,7 +15,7 @@ mixin IGetNavigation {
String? routeName,
bool fullscreenDialog = false,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool preventDuplicates = true,
bool? popGesture,
bool showCupertinoParallax = true,
... ... @@ -32,7 +32,7 @@ mixin IGetNavigation {
String? routeName,
bool fullscreenDialog = false,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool preventDuplicates = true,
bool? popGesture,
bool showCupertinoParallax = true,
... ... @@ -47,7 +47,7 @@ mixin IGetNavigation {
int? id,
String? routeName,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool fullscreenDialog = false,
Transition? transition,
Curve? curve,
... ...
... ... @@ -20,7 +20,7 @@ class GetPage<T> extends Page<T> {
final bool opaque;
final double Function(BuildContext context)? gestureWidth;
//final BindingsInterface? binding;
final List<BindingsInterface>? bindings;
final List<BindingsInterface> bindings;
final List<Bind> binds;
final CustomTransition? customTransition;
final Duration? transitionDuration;
... ... @@ -75,17 +75,19 @@ class GetPage<T> extends Page<T> {
this.preventDuplicateHandlingMode =
PreventDuplicateHandlingMode.ReorderRoutes,
this.completer,
LocalKey? key,
}) : path = _nameToRegex(name),
assert(name.startsWith('/'),
'It is necessary to start route name [$name] with a slash: /$name'),
super(
key: ValueKey(name),
key: key ?? ValueKey(name),
name: name,
// arguments: Get.arguments,
);
// settings = RouteSettings(name: name, arguments: Get.arguments);
GetPage<T> copy({
LocalKey? key,
String? name,
GetPageBuilder? page,
bool? popGesture,
... ... @@ -114,6 +116,7 @@ class GetPage<T> extends Page<T> {
Completer<T?>? completer,
}) {
return GetPage(
key: key ?? this.key,
participatesInRootNavigator:
participatesInRootNavigator ?? this.participatesInRootNavigator,
preventDuplicates: preventDuplicates ?? this.preventDuplicates,
... ...
... ... @@ -7,6 +7,7 @@ import '../../../get_instance/src/bindings_interface.dart';
import '../../../get_state_manager/src/simple/list_notifier.dart';
import '../../../get_utils/src/platform/platform.dart';
import '../../../route_manager.dart';
import 'parse_route.dart';
/// Enables the user to customize the intended pop behavior
///
... ... @@ -350,7 +351,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
String? routeName,
bool fullscreenDialog = false,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool preventDuplicates = true,
bool? popGesture,
bool showCupertinoParallax = true,
... ... @@ -401,7 +402,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
String? routeName,
bool fullscreenDialog = false,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool preventDuplicates = true,
bool? popGesture,
bool showCupertinoParallax = true,
... ... @@ -435,7 +436,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
int? id,
String? routeName,
dynamic arguments,
List<BindingsInterface>? bindings,
List<BindingsInterface> bindings = const [],
bool fullscreenDialog = false,
Transition? transition,
Curve? curve,
... ... @@ -701,6 +702,7 @@ class GetDelegate extends RouterDelegate<RouteDecoder>
completer: _activePages.isEmpty ? null : Completer(),
arguments: arguments,
parameters: parameters,
key: ValueKey(arguments.name),
);
return decoder;
... ...
... ... @@ -7,7 +7,6 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../../../get.dart';
import 'default_transitions.dart';
const double _kBackGestureWidth = 20.0;
const int _kMaxDroppedSwipePageForwardAnimationTime =
... ...
... ... @@ -11,7 +11,7 @@ export 'get_transition_mixin.dart';
export 'modules.dart';
export 'observers/route_observer.dart';
export 'page_settings.dart';
export 'parse_route.dart';
export 'parse_route.dart' hide FirstWhereOrNullExt;
export 'route_middleware.dart';
export 'route_report.dart';
export 'router_outlet.dart';
... ...
... ... @@ -79,7 +79,8 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object>
}
}
// class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object>
// class _RouterOutletState<TDelegate extends RouterDelegate<T>,
//T extends Object>
// extends State<RouterOutlet<TDelegate, T>> {
// TDelegate get delegate => context.delegate as TDelegate;
// @override
... ...
... ... @@ -64,6 +64,22 @@ mixin StateMixin<T> on ListNotifier {
refresh();
}
@protected
void change(T newState, {GetStatus<T>? status}) {
var _canUpdate = false;
if (status != null) {
_status = status;
_canUpdate = true;
}
if (newState != _value) {
_value = newState;
_canUpdate = true;
}
if (_canUpdate) {
refresh();
}
}
void futurize(Future<T> Function() body(),
{String? errorMessage, bool useEmpty = true}) {
final compute = body();
... ... @@ -89,8 +105,9 @@ class GetListenable<T> extends ListNotifierSingle implements RxInterface<T> {
StreamController<T> get subject {
if (_controller == null) {
_controller = StreamController<T>.broadcast();
addListener(_streamListener);
_controller =
StreamController<T>.broadcast(onCancel: addListener(_streamListener));
_controller?.add(_value);
///TODO: report to controller dispose
}
... ...
... ... @@ -80,7 +80,8 @@ abstract class RxController with GetLifeCycleMixin {}
/// A recommended way to use Getx with Future fetching
abstract class StateController<T> extends GetxController with StateMixin<T> {}
/// A controller with super lifecycles (including native lifecycles) and StateMixins
/// A controller with super lifecycles (including native lifecycles)
/// and StateMixins
abstract class SuperController<T> extends FullLifeCycleController
with FullLifeCycleMixin, StateMixin<T> {}
... ...
... ... @@ -114,7 +114,7 @@ abstract class Bind<T> extends StatelessWidget {
final Widget? child;
static Bind put<S extends GetxController>(S dependency,
static Bind put<S>(S dependency,
{String? tag,
bool permanent = false,
InstanceBuilderCallback<S>? builder}) {
... ... @@ -137,10 +137,8 @@ abstract class Bind<T> extends StatelessWidget {
);
}
static Bind create<S extends GetxController>(
InstanceBuilderCallback<S> builder,
{String? tag,
bool permanent = true}) {
static Bind create<S>(InstanceBuilderCallback<S> builder,
{String? tag, bool permanent = true}) {
Get.create<S>(builder, tag: tag, permanent: permanent);
return _FactoryBind<S>(
tag: tag,
... ... @@ -581,4 +579,4 @@ class BindError<T> extends Error {
/// instance of Bindings to manage the
/// dependencies() (via Get.put()) for the Route you are opening.
// ignore: one_member_abstracts
abstract class Binding extends BindingsInterface<Iterable<Bind>> {}
abstract class Binding extends BindingsInterface<List<Bind>> {}
... ...
... ... @@ -3,7 +3,7 @@ export 'double_extensions.dart';
export 'duration_extensions.dart';
export 'dynamic_extensions.dart';
export 'event_loop_extensions.dart';
export 'internacionalization.dart';
export 'internacionalization.dart' hide FirstWhereExt;
export 'iterable_extensions.dart';
export 'num_extensions.dart';
export 'string_extensions.dart';
... ...
name: get
description: Open screens/snackbars/dialogs without context, manage states and inject dependencies easily with GetX.
version: 5.0.0-beta.15
version: 5.0.0-beta.18
homepage: https://github.com/jonataslaw/getx
environment:
... ...
... ... @@ -85,7 +85,8 @@ Future<int> stream() {
// if (times == v) {
// timer.stop();
// print(
// """$v listeners notified | [GET_STREAM] time: ${timer.elapsedMicroseconds}ms""");
// """$v listeners notified |
// [GET_STREAM] time: ${timer.elapsedMicroseconds}ms""");
// c.complete(timer.elapsedMicroseconds);
// }
// });
... ...
... ... @@ -342,28 +342,28 @@ void main() {
expect(find.byType(SecondScreen), findsNothing);
});
// testWidgets(
// "Get.offNamedUntil leaves previous routes that match provided predicate",
// (tester) async {
// await tester.pumpWidget(WrapperNamed(
// initialRoute: '/first',
// namedRoutes: [
// GetPage(page: () => FirstScreen(), name: '/first'),
// GetPage(page: () => SecondScreen(), name: '/second'),
// GetPage(page: () => ThirdScreen(), name: '/third'),
// ],
// ));
// Get.toNamed('/second');
// await tester.pumpAndSettle();
// Get.offNamedUntil('/third', (route) => route.name == '/first');
// await tester.pumpAndSettle();
// Get.back();
// await tester.pumpAndSettle();
// expect(find.byType(FirstScreen), findsOneWidget);
// });
testWidgets(
"Get.offNamedUntil leaves previous routes that match provided predicate",
(tester) async {
await tester.pumpWidget(WrapperNamed(
initialRoute: '/first',
namedRoutes: [
GetPage(page: () => FirstScreen(), name: '/first'),
GetPage(page: () => SecondScreen(), name: '/second'),
GetPage(page: () => ThirdScreen(), name: '/third'),
],
));
Get.toNamed('/second');
await tester.pumpAndSettle();
Get.offNamedUntil('/third', (route) => route.name == '/first');
await tester.pumpAndSettle();
Get.back();
await tester.pumpAndSettle();
expect(find.byType(FirstScreen), findsOneWidget);
});
testWidgets("Get.back navigates back", (tester) async {
await tester.pumpWidget(
... ...