feat: add default mock data
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:kooltab2/database/app_database.dart';
|
||||
import 'package:kooltab2/services/bar_tab_service.dart';
|
||||
import 'package:kooltab2/models/payment_method.dart';
|
||||
import 'package:kooltab2/services/default_product_seeder.dart';
|
||||
import 'package:kooltab2/services/pin_lock_service.dart';
|
||||
import 'package:kooltab2/services/product_service.dart';
|
||||
import 'package:kooltab2/services/settings_service.dart';
|
||||
@@ -78,6 +82,67 @@ class DevMenuViewModel extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> seedDefaultProducts() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await DefaultProductSeeder(database: database).seedIfEmpty();
|
||||
final count = await _getProductCount();
|
||||
_lastAction = 'Seeded default products ($count total)';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearAndReseedProducts() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await database.transaction(() async {
|
||||
await database.delete(database.tabItems).go();
|
||||
await database.delete(database.products).go();
|
||||
});
|
||||
await DefaultProductSeeder(database: database).seedIfEmpty();
|
||||
final count = await _getProductCount();
|
||||
_lastAction = 'Cleared and reseeded ($count products)';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> _getProductCount() async {
|
||||
final countExpr = database.products.id.count();
|
||||
final query = database.selectOnly(database.products)
|
||||
..addColumns([countExpr]);
|
||||
final row = await query.getSingle();
|
||||
return row.read(countExpr) ?? 0;
|
||||
}
|
||||
|
||||
Future<void> clearProductImages() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final appDir = await getApplicationSupportDirectory();
|
||||
final imagesDir = Directory('${appDir.path}/product_images');
|
||||
if (await imagesDir.exists()) {
|
||||
await imagesDir.delete(recursive: true);
|
||||
}
|
||||
_lastAction = 'Product images cleared';
|
||||
} catch (e, stack) {
|
||||
debugPrint('DevMenuViewModel: clearProductImages error: $e');
|
||||
Sentry.captureException(e, stackTrace: stack);
|
||||
_lastAction = 'Failed to clear images: $e';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resetAllStock() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user