Flutter Data は、Ember Data や ActiveRecord を参考に、Flutter アプリケーションにおける永続データモデルの管理を簡素化するアプローチを提供します。ローカルおよびリモートのデータソースに対して一貫した API を提供することで、CRUD 操作、状態管理、デバイス間のデータ同期を容易にします。このパッケージは Flutter のエコシステムとシームレスに統合され、型安全なモデル、自動シリアル化、組み込みキャッシュをサポートしています。開発者はデータモデルと関係性を簡単に定義でき、ボイラープレートコードなしで効率的なデータ処理が可能になります。
In Flutter Data, every model gets its default adapter. These adapters can be extended by mixing in custom adapters.
Annotate a model with @DataAdapter and pass a custom adapter:
@JsonSerializable()
@DataAdapter([MyJSONServerAdapter])
classUserextendsDataModel<User> {
@overridefinalint? id; // ID can be of any typefinalString name;
User({this.id, requiredthis.name});
// `User.fromJson` and `toJson` optional
}
mixinMyJSONServerAdapteronRemoteAdapter<User> {
@overrideStringget baseUrl => "https://my-json-server.typicode.com/flutterdata/demo/";
}
After code-gen, Flutter Data will generate the resulting Adapter<User> which is accessible via Riverpod's ref.users or container.users.
@overrideWidgetbuild(BuildContext context, WidgetRef ref) {
final state = ref.users.watchOne(1);
if (state.isLoading) {
returnCenter(child: constCircularProgressIndicator());
}
final user = state.model;
returnText(user.name);
}
ref.users.watchOne(1) will make a background HTTP request (to https://my-json-server.typicode.com/flutterdata/demo/users/1 in this case), deserialize data and listen for any further local changes to the user.
state is of type DataState which has loading, error and data substates.
In addition to the reactivity, models have ActiveRecord-style extension methods so the above becomes:
Appwrite Offline. A Flutter Data adapter for Appwrite that provides offline support, real-time updates, and seamless integration with Flutter Data's powerful features.
🚨 BREAKING CHANGES IN 2.0
All methods are now directly on Adapter, there is no Repository, RemoteAdapter or LocalAdapter. Any method you are looking for is probably on Adapter, for example, findAll from LocalAdapter is now called findAllLocal
For initialization we no longer call the configure... method on the Riverpod overrides, we just do localStorageProvider.overrideWithValue and pass a LocalStorage instance; the actual initialization is done via initializeFlutterData which needs an adapter map. An adapterProvidersMap is conveniently code-generated and available on main.data.dart
Offline operations are still supported, but retries are not, it is up to clients to implement them
📚 Public API
Initialization
First you need to supply a local storage provider, via Riverpod configuration. A popular option for the base directory is using the path_provider package.