From f04cb2944441e5d170a5f8e8f72144ba10ecd62f Mon Sep 17 00:00:00 2001 From: kolo Date: Tue, 24 Mar 2026 17:18:22 +0300 Subject: [PATCH] update --- lib/features/dashboard/screen.dart | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/features/dashboard/screen.dart b/lib/features/dashboard/screen.dart index da72cdc..aaa147b 100644 --- a/lib/features/dashboard/screen.dart +++ b/lib/features/dashboard/screen.dart @@ -160,9 +160,9 @@ class _DashboardScreenState extends ConsumerState { HapticService.medium(); if (isAddingAccount) { - // Create new account + // Create new account (the id: 0 is a placeholder, SQLite ignores it on insert) final newAccount = Account( - id: DateTime.now().millisecondsSinceEpoch, // temporary + id: 0, name: tempAccountName.trim(), isMain: false, sortOrder: 99, @@ -170,19 +170,12 @@ class _DashboardScreenState extends ConsumerState { createdAt: DateTime.now(), ); - // Insert into database - await ref.read(accountRepositoryProvider).add(newAccount); + // Get the ACTUAL generated ID directly from the database insert + final newId = await ref.read(accountRepositoryProvider).add(newAccount); - // SECURE FIX: Fetch the actual ID assigned by SQLite, avoiding add() return issues - 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 + // Save colors securely using the exact database ID await ref - .read(accountCardColorsProvider(actualAccount.id).notifier) + .read(accountCardColorsProvider(newId).notifier) .save(tempPrimary, tempSecondary, tempGradientType); } else if (editingAccount != null) { // Existing edit logic