Skip to content

Need an example of defining an instance which will be rebuild when listening to a Stream of another instance #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dungnv2602 opened this issue Feb 8, 2020 · 6 comments

Comments

@dungnv2602
Copy link

dungnv2602 commented Feb 8, 2020

I have a service which exposes a Stream, what I want is defining an instance which has a subscription listening to that Stream and rebuilds itself when that Stream emits a new value. This case pretty much the same as using ProxyProvider in Provider package. How do I do it in get_it? An example of code will be much appreciated.

@dungnv2602 dungnv2602 changed the title Need an example of using get_it with an instance which will be rebuild when listening to a Stream of another instance Need an example of defining an instance which will be rebuild when listening to a Stream of another instance Feb 8, 2020
@escamoteur
Copy link
Collaborator

What about using a StreamBuilder?

@dungnv2602
Copy link
Author

dungnv2602 commented Feb 14, 2020

What about using a StreamBuilder?

I want to provide it everywhere in the app. If wrapping the entire MaterialApp in StreamBuilder that means it will rebuild the whole app when new value emits.

If using StreamBuilder in where I need it, it will be too much boilerplate code, not as easy as one line if I can use it with get_it.

@escamoteur
Copy link
Collaborator

Get_It does not update anything in the UI! You have to register an Object that either publishes an ChangeNotifier or a Stream as a property to signal the UI that it should update.

Then you you can use this object as data source at any place of your UI and use their either an StreamBuilder or an AnimatedBuilde (if you choose ChangenNotifiers)

I'm not really clear where your problem is.

@dungnv2602
Copy link
Author

dungnv2602 commented Feb 22, 2020

What I want is to register an instance that can automatically update its value based on another registered instance's value (a Stream or ChangeNotifier) changes. Then when I use locator<>(), the value of that instance already be updated. As I said, it's like a ProxyProvider.

@dungnv2602
Copy link
Author

I hope the code will describe my problem properly

        StreamProvider<ImagesConfiguration>(
          create: (context) =>
              Provider.of<TmdbRemoteDataSource>(context, listen: false)
                  .onConfigurationChange,
        ),
        ProxyProvider2<ImagesConfiguration, AssetQualitySettings,
            AssetResolver>(
          update: (_, configuration, qualitySettings, assetRevolver) =>
              AssetResolver(
            configuration,
            qualitySettings,
          ),
        ),

From the code above, you can see that AssetResolver's configuration is updated every time ImagesConfiguration update. I want that in get_it either. I'm having trouble migrating from Provider to get_it

@escamoteur
Copy link
Collaborator

Updates like that are not supported directly from GetIt. Provider has there anotehr philosopie in that it includes some state management whereas get_it is a pure locator. I always recomens to use get_it togeteher with Streams .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants