simple_json_persistence
간단한 JSON 파일을 기반으로 하는 Flutter 데이터 저장소로, 여러 저장 인스턴스, 스트림 등을 지원합니다.
간단한 JSON 파일을 기반으로 한 Flutter 데이터 저장소.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Flutter data storage based on simple json files. The main advantage to using for example the shared preference plugin is that:
It is still not suitable for large datasets, since all data will be kept in memory and written into the json file at once, but it's a good middle ground between shared preferences and complicated database.
To make use of SimpleJsonPersistence you have to create your
data models to serialize to and from json. I personally prefer to use
built_value with it's
serialization, or json_serializable.
Anyway, it is recommended that persistence models are immutable.
import 'package:simple_json_persistence/simple_json_persistence.dart';
@JsonSerializable(nullable: false)
class MyModel {
MyModel({this.property,});
factory MyModel.fromJson(Map<String, dynamic> json) =>
_$MyModelFromJson(json);
Map<String, dynamic> toJson() => _$MyModelToJson(this);
final String property;
}
void doSomething() async {
final store = SimpleJsonPersistence.forType(
(json) => MyModel.fromJson(json),
name = 'MyModel',
);
await store.save(MyModel(property: 'foo'));
final foo = await store.load();
// since every SimpleJsonPersistence for the same type/name is the same instance
// you can also subscribe to changes.
store.onValueChanged.listen((newValue) {
print('got a new value $newValue');
});
}
See also the example application.
Widget build(BuildContext context) {
final store = SimpleJsonPersistence.forType(
(json) => AppData.fromJson(json),
defaultCreator: () => AppData(counter: 0));
return StreamBuilder<AppData>(
stream: store.onValueChangedAndLoad,
initialData: store.cachedValue,
builder: (context, snapshot) => Text('Counter: ${snapshot.data?.counter ?? 'Loading'}'),
);
}
의존성 목록 13 개
{"sdk":"flutter"}>=1.3.0 <2.0.0>=1.8.0 <2.0.0>=1.0.0 <2.0.0>=0.26.0 <1.0.0>=2.0.0 <3.0.0>=3.0.0 <4.0.0>=1.0.0 <2.0.0>=0.5.1 <2.0.0{"sdk":"flutter"}^4.0.0^1.2.0^1.0.0사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗