add alot
This commit is contained in:
@@ -231,7 +231,6 @@ class DriftBarTabService implements BarTabService {
|
||||
final items = await _getItemsForTab(tabId);
|
||||
|
||||
if (items.isEmpty) {
|
||||
// Nothing to settle, leave the tab as-is.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -263,9 +262,6 @@ class DriftBarTabService implements BarTabService {
|
||||
..where((item) => item.tabId.equals(tabId));
|
||||
|
||||
await deleteQuery.go();
|
||||
|
||||
// Note: tab status/customerName untouched on purpose — the tab
|
||||
// stays open so it keeps showing in the open tabs list.
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,9 @@ import 'dart:math';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
/// Stores and verifies a PIN. The raw PIN is never persisted — only a
|
||||
/// salted SHA-256 hash of it, kept in secure storage (Keychain on iOS,
|
||||
/// EncryptedSharedPreferences/Keystore on Android).
|
||||
class PinLockService {
|
||||
PinLockService({FlutterSecureStorage? storage})
|
||||
: _storage = storage ?? const FlutterSecureStorage();
|
||||
: _storage = storage ?? const FlutterSecureStorage();
|
||||
|
||||
static const _saltKey = 'pin_salt';
|
||||
static const _hashKey = 'pin_hash';
|
||||
@@ -53,4 +50,4 @@ class PinLockService {
|
||||
final bytes = utf8.encode('$salt:$pin');
|
||||
return sha256.convert(bytes).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ abstract class ProductService {
|
||||
Future<void> updateProduct(Product product);
|
||||
|
||||
Future<void> deleteProduct(String id);
|
||||
|
||||
Future<void> decreaseStock(String productId, int amount);
|
||||
Future<void> increaseStock(String productId, int amount);
|
||||
}
|
||||
|
||||
class DriftProductService implements ProductService {
|
||||
@@ -118,4 +121,39 @@ class DriftProductService implements ProductService {
|
||||
|
||||
await query.go();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> decreaseStock(String productId, int amount) async {
|
||||
final product = await getProductById(productId);
|
||||
|
||||
if (product == null) {
|
||||
throw Exception('Product not found');
|
||||
}
|
||||
|
||||
if (product.stockQuantity < amount) {
|
||||
throw Exception('Not enough stock');
|
||||
}
|
||||
|
||||
await updateProduct(
|
||||
product.copyWith(
|
||||
stockQuantity: product.stockQuantity - amount,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> increaseStock(String productId, int amount) async {
|
||||
final product = await getProductById(productId);
|
||||
|
||||
if (product == null) {
|
||||
throw Exception('Product not found');
|
||||
}
|
||||
|
||||
await updateProduct(
|
||||
product.copyWith(
|
||||
stockQuantity: product.stockQuantity + amount,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
import '../database/app_database.dart';
|
||||
import '../models/settings.dart';
|
||||
|
||||
abstract class SettingsService {
|
||||
Future<AppSettings> getSettings();
|
||||
|
||||
Future<void> saveSettings(AppSettings settings);
|
||||
}
|
||||
|
||||
class DriftSettingsService implements SettingsService {
|
||||
final AppDatabase database;
|
||||
static const _settingsId = 'app_settings';
|
||||
|
||||
DriftSettingsService({required this.database});
|
||||
|
||||
AppSettings _mapRowToSettings(AppSettingsRow row) {
|
||||
return AppSettings(
|
||||
pinRequired: row.pinRequired,
|
||||
themeMode: AppThemeMode.values.firstWhere(
|
||||
(mode) => mode.name == row.themeMode,
|
||||
orElse: () => AppThemeMode.system,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<AppSettings> getSettings() async {
|
||||
final query = database.select(database.appSettingsTable)
|
||||
..where((s) => s.id.equals(_settingsId));
|
||||
|
||||
final row = await query.getSingleOrNull();
|
||||
|
||||
if (row == null) return AppSettings.defaults;
|
||||
|
||||
return _mapRowToSettings(row);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveSettings(AppSettings settings) async {
|
||||
await database.into(database.appSettingsTable).insertOnConflictUpdate(
|
||||
AppSettingsTableCompanion.insert(
|
||||
id: _settingsId,
|
||||
pinRequired: Value(settings.pinRequired),
|
||||
themeMode: Value(settings.themeMode.name),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user