flutter_data
2.0.0, released 2 years ago by flutterdata.dev
A Flutter/Dart library for reactive, offline‑first data models with built‑in Riverpod integration.
What it does
Flutter Data lets you define data models that automatically sync with local SQLite storage and remote REST endpoints. It generates adapters and providers so you can watch, query, and mutate data reactively via Riverpod.
AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need offline‑first persistence with reactive UI updates
- You want a unified API for local SQLite and remote REST without writing boilerplate
- You are already using Riverpod for state management
Skip it when
- You prefer a pure NoSQL or key‑value store without relational features
- You need Web support only (Flutter Web is still TBD)
- You want a minimal package without code generation
Strengths
- Automatic code‑gen of adapters and providers
- Strong offline‑first support with SQLite3
- Seamless Riverpod integration and reactive watchers
Weaknesses
- Requires build_runner and code generation step
- Flutter Web not fully supported yet
- Complex API may be overkill for simple key‑value storage
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 17
Add flutter_data and build_runner to pubspec, run `flutter pub run build_runner build`, configure a LocalStorage provider via Riverpod overrides, optionally generate adapter map with `main.data.dart`.
```dart
import 'package:flutter_data/flutter_data.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@JsonSerializable()
@DataAdapter([])
class User extends DataModel<User> {
@override final int? id;
final String name;
User({this.id, required this.name});
}
void main() async {
// Initialize Flutter Data with default SQLite storage
await initializeFlutterData(adapterProvidersMap: mainDataAdapterProviders);
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends ConsumerWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.users.watchOne(1);
if (state.isLoading) return const CircularProgressIndicator();
final user = state.model;
return Text(user.name);
}
}
```Alternatives
Packages that do the same job and could replace flutter_data.
- flutter_riverpod
Same as Riverpod but with Flutter‑specific extensions
93Compare - bloc
Offers predictable state management without built‑in persistence; can be combined with separate storage solutions
92Compare
Works with
Packages commonly used together with flutter_data: ones it builds on, ones built on it, and its own family.
- analyzerflutter_data depends on itPerforms static analysis of Dart code for tool integration and embedding.
- globflutter_data depends on itA file and directory globbing library that supports Bash-style path matching and listing.
- pubspec_parseflutter_data depends on itParse pubspec.yaml files with a type‑safe API and detailed error reporting.
- json_annotationflutter_data depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- buildflutter_data depends on itPackage for authoring build_runner compatible code generators.
- equatableflutter_data depends on itProvides value‑based equality for Dart objects without manual == and hashCode.
- source_genflutter_data depends on itSource code generation builders and utilities for the Dart build system.
- source_helperflutter_data depends on itUtilities to help with Dart source code generation and string literal formatting.