-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Single model over multiple pages #5
Comments
Don't use the same model for two views, you're not using the architecture correctly then. Each view has it's own model. Use a service to share your information. Create an information service that's a singleton and keep your list of coins in there. In the AddCoin page call your function addCoin on your information service from the model. In your HomeModel get the coins from the information service. The service manages all your shared information the models should just use services to produce state. |
Thank you. |
Made an Is that the correct approach? |
No there's no base info service. A service is just a plain class that performs logic. There's nothing to share between the services. Yes, That's the approach you'd want to use. Models talk to service/repo and that's it. Any data shown is requested from the service/repo and displayed in the UI. |
How to use the same model in multiple pages
I am making a cryptocurrency app and following your provider guide 010 using get it
For the main page, I made a
HomeModel
class with a list ofCoin
instances and used it indashboard
page by usingBaseView<HomeModel>
.Now, for adding another item to list in HomeModel I move on to another page
add_coin
where also I useBaseView<HomeModel>
.But here if I register it using
locator.registerLazySingleton(()=>HomeModel());
it gives errorHomeModel was used after being disposed.
And if I register it using factory it does not change the value in initial page
You can see the code here:
https://github.com/Ayush789/crypto_provider
The text was updated successfully, but these errors were encountered: