-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Page URL
https://docs.flutter.dev/app-architecture/guide
Page source
https://github.com/flutter/website/blob/main/src/content/app-architecture/guide.md
Describe the problem
I've read these docs many times, but I don't see anywhere that mentions lifecycle app-wide state. There are many cases where you want to use a state shared between multiple ViewModels, that you do not want to be storing in a database or leaving the application. You only want this shared state to be during the app lifecycle.
- ViewModels: Have a 1-1 with View so can't be shared
- Services: Only used for external data.
"They wrap API endpoints and expose asynchronous response objects, such as Future and Stream objects." - Repositories: Don't seem to hold data, just used to transform it from services.
"They're responsible for polling data from services, and transforming that raw data into domain models." - Use-cases: Seems like it could be here, but from reading the docs, it shouldn't hold state and should depend on repositories
"This method of adding use-cases is defined by the following rules: 1. Use-cases depend on repositories"
Lifecycle app-wide state seems to be excluded from this MVVM approach.
Expected fix
We have our own approach that we use, but I am sure the Flutter team who has worked on this framework with other companies can have a better answer.
If it's helpful, here's what we do: https://www.hungrimind.com/articles/the-definitive-guide-to-our-mvvm-architecture-in-flutter