feat: consolidate backend and docker-compose setup
This commit is contained in:
commit
ff3753a745
306 files changed
+35450
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import '../../models/document_model.dart';
|
||||
|
||||
class LocalStorage {
|
||||
static const String documentBoxName = 'documents_box';
|
||||
|
||||
Future<void> init() async {
|
||||
await Hive.initFlutter();
|
||||
|
||||
// Note: In a real flutter run with build_runner, you would register adapters here
|
||||
// Hive.registerAdapter(DocumentModelAdapter());
|
||||
// Hive.registerAdapter(DocumentItemAdapter());
|
||||
|
||||
await Hive.openBox<Map>(documentBoxName); // Using Map directly for scaffold without build_runner generated files
|
||||
}
|
||||
|
||||
Box get documentBox => Hive.box<Map>(documentBoxName);
|
||||
|
||||
Future<void> saveDocument(DocumentModel doc) async {
|
||||
final box = documentBox;
|
||||
await box.put(doc.id, {
|
||||
'id': doc.id,
|
||||
'nama_driver': doc.namaDriver,
|
||||
'nama_penerima': doc.namaPenerima,
|
||||
'created_at': doc.createdAt.toIso8601String(),
|
||||
'latitude': doc.latitude,
|
||||
'longitude': doc.longitude,
|
||||
'header': {
|
||||
'tanggal': doc.tanggal,
|
||||
'no_po': doc.noPo,
|
||||
'no_so': doc.noSo,
|
||||
'no_do': doc.noDo,
|
||||
},
|
||||
'shipment': {
|
||||
'kepada_yth': doc.kepadaYth,
|
||||
'order_untuk': doc.orderUntuk,
|
||||
'alamat': doc.alamat,
|
||||
'plat_truk': doc.platTruk,
|
||||
},
|
||||
'items': doc.items.map((e) => {
|
||||
'nomor_sku': e.nomorSku,
|
||||
'nama_barang': e.namaBarang,
|
||||
'banyak': e.banyak,
|
||||
'jumlah': e.jumlah,
|
||||
}).toList(),
|
||||
});
|
||||
}
|
||||
|
||||
List<DocumentModel> getAllDocuments() {
|
||||
final box = documentBox;
|
||||
final List<DocumentModel> docs = [];
|
||||
for (var key in box.keys) {
|
||||
final data = box.get(key);
|
||||
if (data != null) {
|
||||
docs.add(DocumentModel.fromJson(Map<String, dynamic>.from(data)));
|
||||
}
|
||||
}
|
||||
// Sort descending by creation date
|
||||
docs.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
return docs;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user