json_store
एक फ्लटर स्टोरेज समाधान जो ब्राउज़र के localStorage के करीब है (लेकिन अत्यधिक शक्तिशाली)
एक ऐसा Flutter स्टोरेज समाधान जो ब्राउज़र के localStorage के करीब है
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
A Storage solution somewhat similar to a browser's localStorage in the sence that it is a key value pair storage. The value should be a dart reprisentation of a JSON Object (aka a Map<String, dynamic>)
getItem is done on a key which ttl has expired, that key will be deleted and a null value will be returnedIn your flutter project add the dependency:
dependencies:
...
json_store:
...
For help getting started with Flutter, view the online documentation.
See example folder for full sample app
Note:
JsonStoreis a singleton and instantiating with factory constructorJsonStore()will only ever have one instance
import 'package:json_store/json_store.dart';
class CounterModel {
int value;
CounterModel(this.value);
CounterModel.fromJson(Map<String, dynamic> json) : this.value = json['value'];
Map<String, dynamic> toJson() => {'value': value};
}
...
JsonStore jsonStore = JsonStore();
CounterModel counter;
loadFromStorage() async {
Map<String, dynamic> json = await jsonStore.getItem('counter');
counter = json != null ? CounterModel.fromJson(json) : CounterModel(0);
}
incrementCounter() async {
counter.value++;
await jsonStore.setItem('counter', counter.toJson());
}
...
When adding a lot of data at a time (Like a long list of messages), use the batch feature as it will improve performance significantly
class Message {
final int id;
final String title;
final String body;
Message([this.id, this.title, this.body]);
Message.fromJson(Map<String, dynamic> json)
: this.id = json['id'],
this.title = json['title'],
this.body = json['body'];
Map<String, dynamic> toJson() => {
'id': id,
'title': title,
'body': body,
};
}
saveBigList() {
Batch batch = await jsonStore.startBatch();
await Future.forEach(_messages, (message) async {
await jsonStore.setItem(
'messages-${message.id}',
message.toJson(),
batch: batch,
);
});
jsonStore.commitBatch(batch);
}
loadBigList() {
List<Map<String, dynamic>> json = await jsonStore.getListLike('messages-%');
messages = json != null
? json.map((messageJson) => Message.fromJson(messageJson)).toList()
: [];
}
In [project]/android/app/build.gradle set minSdkVersion to >= 18.
android {
...
defaultConfig {
...
minSdkVersion 18
...
}
}
Thanks to contributors
निर्भरता सूची 6 आइटम
{"sdk":"flutter"}^5.0.3^10.3.1^2.1.3^2.3.3+1{"sdk":"flutter"}उपयोग के अनुसार छाँटें, गतिविधि की तुलना करें और अपनाने से पहले मूल प्रोजेक्ट की आवश्यकताएँ जाँचें।
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗