Skip to content
pubscout

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.

$ flutter pub add flutter_data
Source repository

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

  • bloc

    Offers predictable state management without built‑in persistence; can be combined with separate storage solutions

Works with

Packages commonly used together with flutter_data: ones it builds on, ones built on it, and its own family.