This commit is contained in:
2026-03-24 17:18:22 +03:00
parent 29270edea9
commit f04cb29444
+6 -13
View File
@@ -160,9 +160,9 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
HapticService.medium(); HapticService.medium();
if (isAddingAccount) { if (isAddingAccount) {
// Create new account // Create new account (the id: 0 is a placeholder, SQLite ignores it on insert)
final newAccount = Account( final newAccount = Account(
id: DateTime.now().millisecondsSinceEpoch, // temporary id: 0,
name: tempAccountName.trim(), name: tempAccountName.trim(),
isMain: false, isMain: false,
sortOrder: 99, sortOrder: 99,
@@ -170,19 +170,12 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
createdAt: DateTime.now(), createdAt: DateTime.now(),
); );
// Insert into database // Get the ACTUAL generated ID directly from the database insert
await ref.read(accountRepositoryProvider).add(newAccount); final newId = await ref.read(accountRepositoryProvider).add(newAccount);
// SECURE FIX: Fetch the actual ID assigned by SQLite, avoiding add() return issues // Save colors securely using the exact database ID
final allAccounts = await ref.read(accountRepositoryProvider).getAll();
final actualAccount = allAccounts.lastWhere(
(a) => a.name == tempAccountName.trim() && a.currency == tempAccountCurrency,
orElse: () => allAccounts.last,
);
// Save colors using the guaranteed correct database ID
await ref await ref
.read(accountCardColorsProvider(actualAccount.id).notifier) .read(accountCardColorsProvider(newId).notifier)
.save(tempPrimary, tempSecondary, tempGradientType); .save(tempPrimary, tempSecondary, tempGradientType);
} else if (editingAccount != null) { } else if (editingAccount != null) {
// Existing edit logic // Existing edit logic