Flutter Data는 Ember Data와 ActiveRecord를 영감으로 하여 Flutter 애플리케이션에서 지속적인 데이터 모델을 관리하는 간편한 접근 방식을 제공합니다. 로컬 및 원격 데이터 소스에 대한 통합된 API를 통해 CRUD 작업, 상태 관리, 장치 간 데이터 동기화를 단순화합니다. 이 패키지는 Flutter 생태계와 원활하게 통합되며, 타입 안전한 모델, 자동 직렬화, 내장 캐시를 지원합니다. 개발자는 뼈대 코드 없이도 쉽게 데이터 모델과 관계를 정의하고 효율적인 데이터 처리를 가능하게 합니다.
사용 사례
오프라인 우선 데이터 워크플로 관리
로컬 저장소와 API 간의 데이터 동기화
확장 가능한 CRUD 애플리케이션 빌드
복잡한 데이터 관계 처리
반응형 데이터 업데이트 구현
주요 기능
자동 모델 직렬화
SQLite를 사용한 내장 지속성
반응형 상태 관리
REST 및 GraphQL API 지원
타입 안전한 데이터 모델 및 쿼리
적합한 대상
오프라인 데이터 접근이 필요한 앱
REST 또는 GraphQL 백엔드를 사용하는 프로젝트
보일러플레이트를 줄이려는 개발자
MVC 유사 데이터 아키텍처를 채택한 팀
복잡한 데이터 관계를 가진 애플리케이션
고려 사항
신규 사용자를 위한 학습 곡선
성숙한 대안에 비해 문서화가 제한적
사용자 지정 엔드포인트를 위해 추가 설정이 필요할 수 있습니다
데이터 요구 사항이 매우 적은 간단한 앱에는 적합하지 않음
json_serializable 등의 외부 종속성에 의존합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Flutter Data
Persistent reactive models in Flutter with zero boilerplate
Flutter Data is a local-first data framework with a customizable REST client and powerful model relationships, built on Riverpod.
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.