Handle Jetpack Glance widget state in a clean way

202 Views Asked by At

Jetpack Glance is getting ready for stable release, I researched a lot about the best way to handle the state of widgets in a clean way in applications using Clean architecture, Hilt, MVVM, MVI and etc. What are your suggestions for this? One way that I saw a lot is to have key-value pairs in preferences and read them in the Widget itself, but in this way if the widget is a little bit complex it would be messy, Also in android documentation it is using the repository as Singletone which in our application it is usually not the case and we are using Hilt for creating that. Let's imagine a scenario:

We have a screen that shows the weather data with a lot of information, We are using Hilt for DI and also we have Usecase, Repo, and DataSource for fetching data, Now we want to have a widget for that and it should be updated with last weather data.

GetWeatherUseCase -> WeatherRepository -> WeatherNetworkDataSource

All of these classes are provided by Hilt and use Flow and common patterns for managing data.

How we should architect a nice and clean pattern for widgets? I think it would be an interesting topic to discuss.

0

There are 0 best solutions below