mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user