Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSingle 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
HomeModelclass with a list ofCoininstances and used it indashboardpage by usingBaseView<HomeModel>.Now, for adding another item to list in HomeModel I move on to another page
add_coinwhere 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