This commit is contained in:
2026-03-25 01:13:28 +03:00
parent ceea63812b
commit 76cffc4960
2 changed files with 569 additions and 328 deletions
+53 -17
View File
@@ -77,10 +77,16 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
_noteController.text = widget.initial!.note ?? ''; _noteController.text = widget.initial!.note ?? '';
} else { } else {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
final activeAccount = ref.read(activeAccountProvider);
final curr = ref.read(currencyProvider); final curr = ref.read(currencyProvider);
// Use active account's currency if available, otherwise use global currency
final currencyCode = activeAccount?.currency ?? curr.code;
final currencySymbol = currencyMap[currencyCode]?.symbol ?? curr.symbol;
ref ref
.read(addTransactionProvider(null).notifier) .read(addTransactionProvider(null).notifier)
.setCurrency(curr.symbol, curr.code); .setCurrency(currencySymbol, currencyCode);
}); });
} }
} }
@@ -155,18 +161,24 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
try { try {
print('--- SUBMIT CLICKED ---'); print('--- SUBMIT CLICKED ---');
print('Amount: $amount, Category: ${state.category}, Type: ${state.type.name}'); print(
'Amount: $amount, Category: ${state.category}, Type: ${state.type.name}',
);
final activeAccount = ref.read(activeAccountProvider); final activeAccount = ref.read(activeAccountProvider);
int accountId; int accountId;
if (activeAccount != null) { if (activeAccount != null) {
print('Using active account ID: ${activeAccount.id}, Name: ${activeAccount.name}'); print(
'Using active account ID: ${activeAccount.id}, Name: ${activeAccount.name}',
);
accountId = activeAccount.id; accountId = activeAccount.id;
} else { } else {
print('No active account. Fetching main account...'); print('No active account. Fetching main account...');
final mainAccount = await ref.read(accountRepositoryProvider).getMain(); final mainAccount = await ref.read(accountRepositoryProvider).getMain();
print('Main account fetched: ID=${mainAccount.id}, Name: ${mainAccount.name}'); print(
'Main account fetched: ID=${mainAccount.id}, Name: ${mainAccount.name}',
);
accountId = mainAccount.id; accountId = mainAccount.id;
} }
@@ -190,7 +202,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
print('Update completed'); print('Update completed');
} else { } else {
final res = await ref.read(transactionsProvider.notifier).add(tx); final res = await ref.read(transactionsProvider.notifier).add(tx);
print('Add completed. Result: ${res.isSuccess ? "SUCCESS" : "FAILURE"}'); print(
'Add completed. Result: ${res.isSuccess ? "SUCCESS" : "FAILURE"}',
);
if (res.isFailure) { if (res.isFailure) {
print('!!! Provider returned failure: ${res.errorOrNull}'); print('!!! Provider returned failure: ${res.errorOrNull}');
@@ -343,8 +357,12 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
Expanded( Expanded(
child: accountsAsync.when( child: accountsAsync.when(
data: (accounts) { data: (accounts) {
final displayAccount = activeAccount ?? final displayAccount =
accounts.firstWhere((a) => a.isMain, orElse: () => accounts.first); activeAccount ??
accounts.firstWhere(
(a) => a.isMain,
orElse: () => accounts.first,
);
return Container( return Container(
height: 56, height: 56,
@@ -369,11 +387,12 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
Flexible( Flexible(
child: Text( child: Text(
displayAccount.name, displayAccount.name,
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium
color: const Color(0xFF7C6DED), ?.copyWith(
fontWeight: FontWeight.w600, color: const Color(0xFF7C6DED),
fontSize: 14, fontWeight: FontWeight.w600,
), fontSize: 14,
),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
@@ -408,14 +427,21 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
border: isDark border: isDark
? null ? null
: Border.all(color: const Color(0xFFDDDDEE), width: 1), : Border.all(
color: const Color(0xFFDDDDEE),
width: 1,
),
), ),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () => ref onTap: () => ref
.read(addTransactionProvider(widget.initial).notifier) .read(
addTransactionProvider(
widget.initial,
).notifier,
)
.setType(TransactionType.income), .setType(TransactionType.income),
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
@@ -430,7 +456,10 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
Icons.arrow_downward_rounded, Icons.arrow_downward_rounded,
color: state.type == TransactionType.income color: state.type == TransactionType.income
? AppColors.income ? AppColors.income
: Theme.of(context).colorScheme.onSurface.withOpacity(0.4), : Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.4),
size: 20, size: 20,
), ),
), ),
@@ -440,7 +469,11 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () => ref onTap: () => ref
.read(addTransactionProvider(widget.initial).notifier) .read(
addTransactionProvider(
widget.initial,
).notifier,
)
.setType(TransactionType.expense), .setType(TransactionType.expense),
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
@@ -455,7 +488,10 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
Icons.arrow_upward_rounded, Icons.arrow_upward_rounded,
color: state.type == TransactionType.expense color: state.type == TransactionType.expense
? AppColors.expense ? AppColors.expense
: Theme.of(context).colorScheme.onSurface.withOpacity(0.4), : Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.4),
size: 20, size: 20,
), ),
), ),
File diff suppressed because it is too large Load Diff