A Flutter architecture proposal
- Prefer class instances over static classes
- Depend on abstractions, not concretions
- Use
get_it
to locate dependencies - Define a public static variable named
get
in its own top-level file, e.gfinal get = GetIt.instance;
, for import by other files - Prefer using
get
as a callable, e.g.get<MyBloc>()
instead ofget.get<MyBloc>()
- Register a dependency within the scope appropriate to its lifetime and unregistered afterward
- Prefer lazy registration
- Use the name suffix
Bloc
- Inputs are methods
- Outputs are streams
- Stream implementations are
rxdart
subjects - Implement
Disposable
to clean up resources - Use a
StatefulWidget
to register and unregister close to usage in theWidget
tree
- Use the name suffix
Dto
- In a folder named
dtos
- Must be immutable
- Do not contain logic
- If serializable, fields are nullable
- Stateful use the name suffix
Manager
- Stateless use the name suffix
Service
- HTTP clients use the name suffix
Client