This commit is contained in:
2026-03-24 17:10:50 +03:00
parent e0fa55c6f5
commit 29270edea9
3 changed files with 50 additions and 47 deletions
@@ -172,14 +172,14 @@ class AccountRepository {
)); ));
} }
Future<void> add(model.Account account) async { Future<int> add(model.Account account) async {
await _db.into(_db.accounts).insert( return await _db.into(_db.accounts).insert(
AccountsCompanion.insert( AccountsCompanion.insert(
id: Value(account.id),
name: account.name, name: account.name,
isMain: Value(account.isMain), isMain: Value(account.isMain),
currency: Value(account.currency),
sortOrder: Value(account.sortOrder), sortOrder: Value(account.sortOrder),
currency: Value(account.currency),
createdAt: Value(account.createdAt),
), ),
); );
} }
+10 -5
View File
@@ -162,7 +162,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
if (isAddingAccount) { if (isAddingAccount) {
// Create new account // Create new account
final newAccount = Account( final newAccount = Account(
id: DateTime.now().millisecondsSinceEpoch, id: DateTime.now().millisecondsSinceEpoch, // temporary
name: tempAccountName.trim(), name: tempAccountName.trim(),
isMain: false, isMain: false,
sortOrder: 99, sortOrder: 99,
@@ -170,14 +170,19 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
createdAt: DateTime.now(), createdAt: DateTime.now(),
); );
// Insert into database
await ref.read(accountRepositoryProvider).add(newAccount); await ref.read(accountRepositoryProvider).add(newAccount);
// FIX: Fetch the actual ID assigned by the database to save colors correctly // SECURE FIX: Fetch the actual ID assigned by SQLite, avoiding add() return issues
final accounts = await ref.read(accountRepositoryProvider).getAll(); final allAccounts = await ref.read(accountRepositoryProvider).getAll();
final actualNewAccount = accounts.lastWhere((a) => a.name == tempAccountName.trim()); 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(actualNewAccount.id).notifier) .read(accountCardColorsProvider(actualAccount.id).notifier)
.save(tempPrimary, tempSecondary, tempGradientType); .save(tempPrimary, tempSecondary, tempGradientType);
} else if (editingAccount != null) { } else if (editingAccount != null) {
// Existing edit logic // Existing edit logic
@@ -263,10 +263,9 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
), ),
// Top Right Buttons (Delete & Close) // Top Right Buttons (Delete & Close)
Positioned( Positioned(
top: mq.padding.top + 8, top: cardTop - 20, // Center buttons exactly on the top edge of the card
right: 20, right: 20,
child: SafeArea( child: Row( // REMOVED SafeArea to fix the vertical offset
child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
if (!dash.isAddingAccount && (ref.watch(accountsProvider).valueOrNull?.length ?? 0) > 1) ...[ if (!dash.isAddingAccount && (ref.watch(accountsProvider).valueOrNull?.length ?? 0) > 1) ...[
@@ -321,7 +320,6 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
], ],
), ),
), ),
),
// Custom Dialog Overlay // Custom Dialog Overlay
if (_showDeleteDialog) if (_showDeleteDialog)
Positioned.fill( Positioned.fill(