0.4.1

Cookbook

See subsections for FAQs on specific topics.

Is Flutter Data a state management solution?

Flutter Data can be understood as a very specific “stream controller” (essentially taking input from save/delete and incoming streams) and exposing it as a stream/notifier. As such, it can manage global state through repositories and business models, coupled with a dependency injection solution.

Managing local state with Flutter Data (e.g. active tab state) would not make much sense. Use setState or a ValueNotifier instead.

Accessing Repositorys from BLoCs or view-model layers is definitely possible and encouraged. It’s also encouraged to start using Flutter Data directly from the widget layer before it’s absolutely necessary to add more complex setups.

How do I get hold of Repositories with Provider?

Remember to use context.read<Repository<T>>() (or Provider.of<Repository<T>>(listen: false)) as repositories don’t change.

For access from BLoCs or other non-widget layers, you can pass the context.read locator around (or use a global, your call).

Offline support

Use or extend the provided offline adapter.

Errors generating code

If you have trouble with the outputs, try:

flutter packages pub run build_runner build --delete-conflicting-outputs

VSCode users!

If after generating code you still see errors in your files, try reopening the project. This is not a Flutter Data issue.

Local storage for long term persistence

tl;dr don’t save anything critical (with Flutter Data) just yet