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
+62 -26
View File
@@ -18,12 +18,12 @@ const _uuid = Uuid();
// Provider to get the account for new transactions // Provider to get the account for new transactions
final transactionAccountProvider = Provider<({int id, String name})>((ref) { final transactionAccountProvider = Provider<({int id, String name})>((ref) {
final activeAccount = ref.watch(activeAccountProvider); final activeAccount = ref.watch(activeAccountProvider);
if (activeAccount != null) { if (activeAccount != null) {
// User is on a specific account page // User is on a specific account page
return (id: activeAccount.id, name: activeAccount.name); return (id: activeAccount.id, name: activeAccount.name);
} }
// User is on Total Balance page, use Main account // User is on Total Balance page, use Main account
// This will be resolved in the widget // This will be resolved in the widget
return (id: 0, name: ''); // Placeholder, will be replaced return (id: 0, name: ''); // Placeholder, will be replaced
@@ -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;
} }
@@ -181,7 +193,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
currencyCode: state.overrideCurrencyCode, currencyCode: state.overrideCurrencyCode,
accountId: accountId, accountId: accountId,
); );
print('Transaction object created: ID=${tx.id}, AccId=${tx.accountId}'); print('Transaction object created: ID=${tx.id}, AccId=${tx.accountId}');
print('Calling provider to save...'); print('Calling provider to save...');
@@ -190,8 +202,10 @@ 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}');
throw Exception(res.errorOrNull); throw Exception(res.errorOrNull);
@@ -210,7 +224,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
print('Error: $e'); print('Error: $e');
print('Stack trace:'); print('Stack trace:');
print(stack); print(stack);
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
@@ -281,7 +295,7 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
final categories = ref.watch(availableCategoriesProvider(widget.initial)); final categories = ref.watch(availableCategoriesProvider(widget.initial));
final overrideCurrency = state.overrideCurrency; final overrideCurrency = state.overrideCurrency;
final isDark = Theme.of(context).brightness == Brightness.dark; final isDark = Theme.of(context).brightness == Brightness.dark;
// Get active account or fallback to main // Get active account or fallback to main
final activeAccount = ref.watch(activeAccountProvider); final activeAccount = ref.watch(activeAccountProvider);
final accountsAsync = ref.watch(accountsProvider); final accountsAsync = ref.watch(accountsProvider);
@@ -343,9 +357,13 @@ 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,
padding: const EdgeInsets.symmetric(horizontal: 14), padding: const EdgeInsets.symmetric(horizontal: 14),
@@ -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