Skip to content

Commit 48c3a8d

Browse files
authored
Merge pull request #734 from MarcoAFC/master
fix: widget module disposing
2 parents c513de7 + 4982c98 commit 48c3a8d

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

flutter_modular/lib/src/domain/services/module_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '../../shared/either.dart';
66
abstract class ModuleService {
77
Either<ModularError, Unit> start(RouteContext module);
88
Either<ModularError, Unit> bind(BindContext module);
9-
Either<ModularError, Unit> unbind<T extends BindContext>();
9+
Either<ModularError, Unit> unbind<T extends BindContext>({Type? type});
1010
Either<ModularError, Unit> finish();
1111
Future<Either<ModularError, bool>> isModuleReady<M extends Module>();
1212
}

flutter_modular/lib/src/domain/usecases/unbind_module.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import '../../shared/either.dart';
33
import '../services/module_service.dart';
44

55
abstract class UnbindModule {
6-
Either<ModularError, Unit> call<T extends BindContext>();
6+
Either<ModularError, Unit> call<T extends BindContext>({Type? type});
77
}
88

99
class UnbindModuleImpl implements UnbindModule {
@@ -12,7 +12,7 @@ class UnbindModuleImpl implements UnbindModule {
1212
UnbindModuleImpl(this.moduleService);
1313

1414
@override
15-
Either<ModularError, Unit> call<T extends BindContext>() {
16-
return moduleService.unbind<T>();
15+
Either<ModularError, Unit> call<T extends BindContext>({Type? type}) {
16+
return moduleService.unbind<T>(type: type);
1717
}
1818
}

flutter_modular/lib/src/infra/services/module_service_impl.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class ModuleServiceImpl extends ModuleService {
3232
}
3333

3434
@override
35-
Either<ModularError, Unit> unbind<T extends BindContext>() {
36-
tracker.injector.removeBindContext<T>();
35+
Either<ModularError, Unit> unbind<T extends BindContext>({Type? type}) {
36+
tracker.injector.removeBindContext<T>(type: type);
3737
return right(unit);
3838
}
3939
}

flutter_modular/lib/src/presenter/widgets/widget_module.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ class _ModularProviderState<T extends BindContext>
110110
@override
111111
void dispose() {
112112
super.dispose();
113-
injector.get<UnbindModule>().call<T>();
113+
injector.get<UnbindModule>().call<T>(type: widget.module.runtimeType);
114114
}
115115
}

flutter_modular/pubspec.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ dependencies:
1313
flutter:
1414
sdk: flutter
1515

16+
dependency_overrides:
17+
modular_core:
18+
path: ../modular_core
19+
modular_interfaces:
20+
path: ../modular_interfaces
21+
1622
dev_dependencies:
1723
flutter_lints: ^1.0.4
1824
mocktail: ^0.1.4

modular_core/lib/src/di/injector.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ class InjectorImpl<T> extends Injector<T> {
134134

135135
@override
136136
@mustCallSuper
137-
void removeBindContext<B extends BindContext>() {
138-
final module = _allBindContexts.remove(_getType<B>());
137+
void removeBindContext<B extends BindContext>({Type? type}) {
138+
final module = _allBindContexts.remove(type ?? _getType<B>());
139139
if (module != null) {
140140
module.dispose();
141141
debugPrint("-- ${module.runtimeType} DISPOSED");

modular_interfaces/lib/src/di/injector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class Injector<T> {
3030
void destroy();
3131

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

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

0 commit comments

Comments
 (0)