Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/get_instance/src/extension_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ extension Inst on GetInterface {
if (_singl.containsKey(key)) {
final newDep = _singl[key];
if (newDep == null || !newDep.isDirty) {
return;
if (isSingleton == true) {
return;
} else {
delete<S>(tag: name, key: key);
dep = newDep as _InstanceBuilderFactory<S>;
dep.isDeleteByNextCreate = true;
}
} else {
dep = newDep as _InstanceBuilderFactory<S>;
}
Expand Down Expand Up @@ -366,6 +372,14 @@ extension Inst on GetInterface {

if (dep == null) return false;

if (dep.isDeleteByNextCreate) {
// fix:https://github.com/jonataslaw/getx/issues/2944
// Prevent the normal lifecycle from being unable to be destroyed
dep.isDeleteByNextCreate = false;
return false;
}


final _InstanceBuilderFactory builder;
if (dep.isDirty) {
builder = dep.lateRemove ?? dep;
Expand Down Expand Up @@ -508,6 +522,10 @@ class _InstanceBuilderFactory<S> {
/// For reusing [dependency] instead of [builderFunc]
bool? isSingleton;

// fix: https://github.com/jonataslaw/getx/issues/2944
// the identifier of the previous instance forcibly deleted when created
bool isDeleteByNextCreate = false;

/// When fenix mode is available, when a new instance is need
/// Instance manager will recreate a new instance of S
bool fenix;
Expand Down