feat: add gallery feature with database integration and rendering capabilities
Build Android App / build (push) Failing after 2m19s
Build Android App / build (push) Failing after 2m19s
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import "package:hive_flutter/hive_flutter.dart";
|
||||
import "package:quotegen_client/models/gallery_item.dart";
|
||||
|
||||
class GalleryDB {
|
||||
|
||||
static const String _boxName = "gallery";
|
||||
|
||||
static LazyBox<String> get _box => Hive.lazyBox<String>(_boxName);
|
||||
|
||||
|
||||
static Future<void> saveItem(GalleryItem item) async {
|
||||
await _box.put(item.id, item.toJsonString());
|
||||
}
|
||||
|
||||
static Future<void> deleteItem(String id) async {
|
||||
await _box.delete(id);
|
||||
}
|
||||
|
||||
static Future<List<GalleryItem>> getAllItems() async {
|
||||
final keys = _box.keys.toList();
|
||||
final items = <GalleryItem>[];
|
||||
|
||||
for (final key in keys) {
|
||||
final raw = await _box.get(key);
|
||||
if (raw != null) {
|
||||
try {
|
||||
items.add(GalleryItem.fromJsonString(raw));
|
||||
} catch (e) {
|
||||
// skip corrupted entries
|
||||
print("GalleryDB: failed to parse item $key: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
return items;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user