You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank you for this great service locator library. I'm using it in my all 3 projects.
Assuming I have 2 screen A and B. I register a BaseBloc as Factory, thus each time enter these screens, I will get a new instance of BaseBloc.
Screen A has 2 child screens A1 and A2. Instead of passing BaseBloc to A1 and A2, I would like to get use GetIt to get it in A1 and A2 instead. However, since BaseBloc was registered as Factory, in A1 when I have BaseBloc, its data was reset to new instance (not have any data which from A screen).
I wonder if we have any existing solutions for this case? If not, I'm thinking about a new param for GetIt.I<BaseBloc>(returnInstanceIfExisting: true) - which will return existing instance of BaseBloc instead of creating the new one.
How do you think about my idea?
More info:
get_it: ^4.0.0
Flutter version 1.12.13+hotfix.5 at C:\DevTools\flutter
Framework revision 27321ebbad (4 months ago), 2019-12-10 18:15:01 -0800
Engine revision 2994f7e1e6
Dart version 2.7.0
The text was updated successfully, but these errors were encountered:
trietbui85
changed the title
Add a param to force get the singleton or factory.
How to get the existing instance in case object is registered as Factory?
Mar 27, 2020
I wonder if we have any existing solutions for this case? If not, I'm thinking about a new param for GetIt.I(returnInstanceIfExisting: true) - which will return existing instance of BaseBloc instead of creating the new one.
is not possible because I don't keep track of factory created objects. How would I know when it is no longer needed?
I think what you would need were scoped singletons but that's something that's not supported yet.
First of all, thank you for this great service locator library. I'm using it in my all 3 projects.
Assuming I have 2 screen A and B. I register a
BaseBloc
as Factory, thus each time enter these screens, I will get a new instance ofBaseBloc
.Screen A has 2 child screens A1 and A2. Instead of passing
BaseBloc
to A1 and A2, I would like to get use GetIt to get it in A1 and A2 instead. However, sinceBaseBloc
was registered as Factory, in A1 when I haveBaseBloc
, its data was reset to new instance (not have any data which from A screen).I wonder if we have any existing solutions for this case? If not, I'm thinking about a new param for
GetIt.I<BaseBloc>(returnInstanceIfExisting: true)
- which will return existing instance ofBaseBloc
instead of creating the new one.How do you think about my idea?
More info:
The text was updated successfully, but these errors were encountered: