How to get same instance of an object using a parameter such as ID, with getIt/injectable in flutter?

151 Views Asked by At

I am new to using getIt as dependancy injection, I used to use Riverpod. in riverpod we have family providers, where I can use an ID parameter to get the same instance of an object. Now, in my current app, I'm working on a bookmarking feature using a cubit , and I want to ensure that when I bookmark a post from any page, the update is reflected throughout the app wherever that specific post is displayed. I've created a cubit for bookmarking, and I'm trying to figure out how to obtain the same instance of the cubit based on the post ID using getIt. Currently, when I call GetIt.instance<BookmarkCubit>(param1: post.id) , it creates a new instance, and I'm unsure how to achieve the desired behavior of obtaining the same cubit instance across different pages. Any guidance on achieving this with getIt would be greatly appreciated!

1

There are 1 best solutions below

1
On BEST ANSWER

unlike in riverpod you don't need different instances of cubit. cubit has streams under the hood. here more info. moreover, approach to use get_it for cubit/bloc creation is not recommended.