Skip to content

Commit

Permalink
Merge pull request #715 from Flutterando/fix/714
Browse files Browse the repository at this point in the history
fix: Parse params in RouteOutlet
  • Loading branch information
Bwolfs2 committed May 13, 2022
2 parents e0583d5 + 8993253 commit c513de7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
2 changes: 2 additions & 0 deletions flutter_modular/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [5.0.2] - 2022-04-22
- Fix: Parse params in RouteOutlet
## [5.0.1] - 2022-04-22
- Fix: Inject.get should return instance.

Expand Down
14 changes: 10 additions & 4 deletions flutter_modular/lib/flutter_modular.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import 'src/presenter/navigation/modular_router_delegate.dart';
import 'src/presenter/navigation/router_outlet_delegate.dart';

export 'package:flutter_modular_annotations/flutter_modular_annotations.dart';
export 'package:modular_core/modular_core.dart' show ModularRoute, Disposable, ReassembleMixin;
export 'package:modular_core/modular_core.dart'
show ModularRoute, Disposable, ReassembleMixin;

export 'src/presenter/guards/route_guard.dart';
export 'src/presenter/models/bind.dart';
Expand Down Expand Up @@ -53,7 +54,10 @@ void cleanGlobals() {

extension InjectorExtends on Injector {
/// get arguments
ModularArguments get args => injector.get<GetArguments>().call().getOrElse((l) => ModularArguments.empty());
ModularArguments get args => injector
.get<GetArguments>()
.call()
.getOrElse((l) => ModularArguments.empty());
}

/// It acts as a Nested Browser that will be populated by the children of this route.
Expand Down Expand Up @@ -86,9 +90,11 @@ class RouterOutletState extends State<RouterOutlet> {
void didChangeDependencies() {
super.didChangeDependencies();
final modal = (ModalRoute.of(context)?.settings as ModularPage);
delegate ??= RouterOutletDelegate(modal.route.uri.toString(), injector.get<ModularRouterDelegate>(), navigatorKey);
delegate ??= RouterOutletDelegate(modal.route.uri.toString(),
injector.get<ModularRouterDelegate>(), navigatorKey);
final router = Router.of(context);
_backButtonDispatcher = router.backButtonDispatcher!.createChildBackButtonDispatcher();
_backButtonDispatcher =
router.backButtonDispatcher!.createChildBackButtonDispatcher();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class ModularRouteInformationParser
{dynamic arguments, void Function(dynamic)? popCallback}) async {
var route = await selectRoute(path, arguments: arguments);

final modularArgs =
getArguments().getOrElse((l) => ModularArguments.empty());

if (popCallback != null) {
route = route.copyWith(popCallback: popCallback);
}
Expand All @@ -78,6 +81,8 @@ class ModularRouteInformationParser
book.routes.insert(0, child);
}

setArguments(modularArgs);

for (var booksRoute in book.routes) {
reportPush(booksRoute);
}
Expand Down
15 changes: 10 additions & 5 deletions flutter_modular/lib/src/presenter/widgets/widget_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ abstract class WidgetModule extends StatelessWidget implements BindContextImpl {
final List<Module> imports = const [];

@override
List<BindEntry> get instanciatedSingletons => _fakeModule.instanciatedSingletons;
List<BindEntry> get instanciatedSingletons =>
_fakeModule.instanciatedSingletons;

@override
void instantiateSingletonBinds(List<BindEntry<Object>> singletons, Injector injector) {
void instantiateSingletonBinds(
List<BindEntry<Object>> singletons, Injector injector) {
_fakeModule.instantiateSingletonBinds(singletons, injector);
}

Expand All @@ -66,7 +68,8 @@ abstract class WidgetModule extends StatelessWidget implements BindContextImpl {
}

@override
void changeBinds(List<BindContract<Object>> newBinds) => _fakeModule.changeBinds(newBinds);
void changeBinds(List<BindContract<Object>> newBinds) =>
_fakeModule.changeBinds(newBinds);

@override
// ignore: invalid_use_of_visible_for_testing_member
Expand All @@ -84,13 +87,15 @@ class ModularProvider<T extends BindContext> extends StatefulWidget {
final BindContext module;
final Widget child;

const ModularProvider({Key? key, required this.module, required this.child}) : super(key: key);
const ModularProvider({Key? key, required this.module, required this.child})
: super(key: key);

@override
_ModularProviderState createState() => _ModularProviderState<T>();
}

class _ModularProviderState<T extends BindContext> extends State<ModularProvider> {
class _ModularProviderState<T extends BindContext>
extends State<ModularProvider> {
@override
void initState() {
super.initState();
Expand Down
2 changes: 1 addition & 1 deletion flutter_modular/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_modular
description: Smart project structure with dependency injection and route management
version: 5.0.1
version: 5.0.2
homepage: https://github.com/Flutterando/modular

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ void main() {

group('getBind', () {
test('should get bind', () {
when(() => injector.getBind<String>()).thenReturn(BindEntry(bind: Bind<String>((i) => ''), value: 'test'));
expect(service.getBind<String>().map((r) => r.value).getOrElse((left) => ''), 'test');
when(() => injector.getBind<String>())
.thenReturn(BindEntry(bind: Bind<String>((i) => ''), value: 'test'));
expect(
service.getBind<String>().map((r) => r.value).getOrElse((left) => ''),
'test');
});
test('should throw error not found bind', () {
when(() => injector.getBind<String>()).thenThrow(BindNotFound('String'));
expect(service.getBind<String>().fold(id, id), isA<BindNotFoundException>());
expect(
service.getBind<String>().fold(id, id), isA<BindNotFoundException>());
});
});

Expand All @@ -33,7 +37,8 @@ void main() {
group('releaseScopedBinds', () {
test('should return true', () {
when(() => injector.removeScopedBinds());
expect(service.releaseScopedBinds().getOrElse((left) => throw left), unit);
expect(
service.releaseScopedBinds().getOrElse((left) => throw left), unit);
});
});
}

0 comments on commit c513de7

Please sign in to comment.