This commit is contained in:
2026-03-24 12:10:19 +03:00
parent 6750b996fc
commit 5888e0d196
2 changed files with 56 additions and 6 deletions
+34
View File
@@ -139,6 +139,40 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
.read(accountCardColorsProvider(editingAccount!.id).notifier)
.save(tempPrimary, tempSecondary, tempGradientType);
// Check if currency was changed and convert transactions
if (tempAccountCurrency != editingAccount!.currency) {
final exchangeService = ref.read(exchangeRateServiceProvider);
final txRepo = ref.read(transactionRepositoryProvider);
// Fetch all transactions
final allTxsResult = await txRepo.getAll();
if (allTxsResult.isSuccess) {
final accountTxs = allTxsResult.dataOrNull!
.where((t) => t.accountId == editingAccount!.id)
.toList();
// Convert and update each transaction
for (final tx in accountTxs) {
final convertedAmount = exchangeService.convert(
tx.amount,
editingAccount!.currency, // old currency
tempAccountCurrency, // new currency
);
final updatedTx = tx.copyWith(
amount: convertedAmount,
currency: currencyMap[tempAccountCurrency]?.symbol ?? '\$',
currencyCode: tempAccountCurrency,
);
await txRepo.update(updatedTx);
}
// Refresh transactions provider so the UI updates
ref.read(transactionsProvider.notifier).refresh();
}
}
// Update account name and currency
final updatedAccount = Account(
id: editingAccount!.id,
@@ -45,15 +45,21 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
_originalCurrency = dash.tempAccountCurrency;
_nameController.addListener(() {
final text = _nameController.text;
if (text.length > 17) {
_nameController.text = text.substring(0, 17);
_nameController.selection = TextSelection.fromPosition(
const TextPosition(offset: 17),
);
// Check if empty or exceeds limit
if (text.trim().isEmpty || text.length > 20) {
setState(() => _showLimitError = true);
Future.delayed(const Duration(seconds: 2), () {
if (mounted) setState(() => _showLimitError = false);
});
}
// Truncate if exceeds 20 characters
if (text.length > 20) {
_nameController.text = text.substring(0, 20);
_nameController.selection = TextSelection.fromPosition(
const TextPosition(offset: 20),
);
return; // Skip updating dash to avoid out-of-bounds
}
@@ -858,10 +864,20 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
Expanded(
flex: 2,
child: ElevatedButton(
onPressed: () => dash.closeAccountOverlay(apply: true),
onPressed: _nameController.text.trim().isEmpty
? null
: () => dash.closeAccountOverlay(apply: true),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF7C6DED),
foregroundColor: Colors.white,
disabledBackgroundColor: Theme.of(widget.context)
.colorScheme
.onSurface
.withOpacity(0.12),
disabledForegroundColor: Theme.of(widget.context)
.colorScheme
.onSurface
.withOpacity(0.38),
padding: const EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),