fixes before build 3

This commit is contained in:
gitea
2026-08-31 17:35:46 +02:00
parent b0708101b0
commit edbfade477
7 changed files with 330 additions and 32 deletions
+43 -7
View File
@@ -1148,6 +1148,7 @@ class ProductRepository extends ChangeNotifier {
double? price,
int? quantity,
double? unitPrice,
bool clearQuantity = false,
}) async {
final db = await _database;
final rows = await db.query(
@@ -1161,8 +1162,13 @@ class ProductRepository extends ChangeNotifier {
final values = <String, Object?>{};
if (name != null) values['name'] = name.trim();
if (price != null) values['price'] = price;
if (quantity != null) values['quantity'] = quantity;
if (unitPrice != null) values['unit_price'] = unitPrice;
if (clearQuantity) {
values['quantity'] = null;
values['unit_price'] = null;
} else {
if (quantity != null) values['quantity'] = quantity;
if (unitPrice != null) values['unit_price'] = unitPrice;
}
if (values.isEmpty) return;
await db.update('shop_items', values, where: 'id = ?', whereArgs: [id]);
await _recalculateShopTotal(shopId);
@@ -1540,15 +1546,45 @@ class ProductRepository extends ChangeNotifier {
}
Future<void> clearImageFolders() async {
final dir = await getApplicationDocumentsDirectory();
for (final name in ['receipts', 'products']) {
final folder = Directory(p.join(dir.path, name));
if (await folder.exists()) {
await folder.delete(recursive: true);
try {
final dir = await getApplicationDocumentsDirectory();
for (final name in ['receipts', 'products', 'bonus_cards']) {
final folder = Directory(p.join(dir.path, name));
if (await folder.exists()) {
await folder.delete(recursive: true);
}
}
} catch (_) {
// Platform folders are unavailable in some unit tests.
}
}
/// Deletes all app data and restores default supermarkets.
Future<void> wipeAllData() async {
final db = await _database;
await db.transaction((txn) async {
await txn.delete('shopping_list_items');
await txn.delete('shopping_lists');
await txn.delete('shop_tags');
await txn.delete('shop_items');
await txn.delete('shops');
await txn.delete('products');
await txn.delete('supermarkets');
await txn.delete('app_settings');
await _resetSequence(txn, 'supermarkets');
await _resetSequence(txn, 'products');
await _resetSequence(txn, 'shops');
await _resetSequence(txn, 'shop_items');
await _resetSequence(txn, 'shop_tags');
await _resetSequence(txn, 'shopping_lists');
await _resetSequence(txn, 'shopping_list_items');
await _seedSupermarkets(txn);
});
await clearImageFolders();
notifyListeners();
}
Future<void> replaceAllData({
required List<Map<String, Object?>> supermarkets,
required List<Map<String, Object?>> products,