Skip to content

Commit

Permalink
Merge pull request #734 from MarcoAFC/master
Browse files Browse the repository at this point in the history
fix: widget module disposing
  • Loading branch information
jacobaraujo7 authored Jun 2, 2022
2 parents c513de7 + 4982c98 commit 48c3a8d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '../../shared/either.dart';
abstract class ModuleService {
Either<ModularError, Unit> start(RouteContext module);
Either<ModularError, Unit> bind(BindContext module);
Either<ModularError, Unit> unbind<T extends BindContext>();
Either<ModularError, Unit> unbind<T extends BindContext>({Type? type});
Either<ModularError, Unit> finish();
Future<Either<ModularError, bool>> isModuleReady<M extends Module>();
}
6 changes: 3 additions & 3 deletions flutter_modular/lib/src/domain/usecases/unbind_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import '../../shared/either.dart';
import '../services/module_service.dart';

abstract class UnbindModule {
Either<ModularError, Unit> call<T extends BindContext>();
Either<ModularError, Unit> call<T extends BindContext>({Type? type});
}

class UnbindModuleImpl implements UnbindModule {
Expand All @@ -12,7 +12,7 @@ class UnbindModuleImpl implements UnbindModule {
UnbindModuleImpl(this.moduleService);

@override
Either<ModularError, Unit> call<T extends BindContext>() {
return moduleService.unbind<T>();
Either<ModularError, Unit> call<T extends BindContext>({Type? type}) {
return moduleService.unbind<T>(type: type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class ModuleServiceImpl extends ModuleService {
}

@override
Either<ModularError, Unit> unbind<T extends BindContext>() {
tracker.injector.removeBindContext<T>();
Either<ModularError, Unit> unbind<T extends BindContext>({Type? type}) {
tracker.injector.removeBindContext<T>(type: type);
return right(unit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ class _ModularProviderState<T extends BindContext>
@override
void dispose() {
super.dispose();
injector.get<UnbindModule>().call<T>();
injector.get<UnbindModule>().call<T>(type: widget.module.runtimeType);
}
}
6 changes: 6 additions & 0 deletions flutter_modular/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ dependencies:
flutter:
sdk: flutter

dependency_overrides:
modular_core:
path: ../modular_core
modular_interfaces:
path: ../modular_interfaces

dev_dependencies:
flutter_lints: ^1.0.4
mocktail: ^0.1.4
Expand Down
4 changes: 2 additions & 2 deletions modular_core/lib/src/di/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class InjectorImpl<T> extends Injector<T> {

@override
@mustCallSuper
void removeBindContext<B extends BindContext>() {
final module = _allBindContexts.remove(_getType<B>());
void removeBindContext<B extends BindContext>({Type? type}) {
final module = _allBindContexts.remove(type ?? _getType<B>());
if (module != null) {
module.dispose();
debugPrint("-- ${module.runtimeType} DISPOSED");
Expand Down
2 changes: 1 addition & 1 deletion modular_interfaces/lib/src/di/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class Injector<T> {
void destroy();

/// remove [BindContext] by [Type]
void removeBindContext<B extends BindContext>();
void removeBindContext<T extends BindContext>({Type? type});

/// checks if all asynchronous binds are ready to be used synchronously of all BindContext of Tree.
Future<bool> isModuleReady<M extends BindContext>();
Expand Down

0 comments on commit 48c3a8d

Please sign in to comment.