mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
39 lines
818 B
Dart
39 lines
818 B
Dart
import 'package:toolbox/core/persistant_store.dart';
|
|
import 'package:toolbox/data/model/server/server_private_info.dart';
|
|
|
|
class ServerStore extends PersistentStore {
|
|
void put(ServerPrivateInfo info) {
|
|
box.put(info.id, info);
|
|
}
|
|
|
|
List<ServerPrivateInfo> fetch() {
|
|
final ids = box.keys;
|
|
final List<ServerPrivateInfo> ss = [];
|
|
for (final id in ids) {
|
|
final s = box.get(id);
|
|
if (s != null) {
|
|
ss.add(s);
|
|
}
|
|
}
|
|
return ss;
|
|
}
|
|
|
|
void delete(String id) {
|
|
box.delete(id);
|
|
}
|
|
|
|
void deleteAll() {
|
|
box.clear();
|
|
}
|
|
|
|
void update(ServerPrivateInfo old, ServerPrivateInfo newInfo) {
|
|
if (!have(old)) {
|
|
throw Exception('Old spi: $old not found');
|
|
}
|
|
delete(old.id);
|
|
put(newInfo);
|
|
}
|
|
|
|
bool have(ServerPrivateInfo s) => box.get(s.id) != null;
|
|
}
|