This commit is contained in:
2026-03-20 16:28:26 +03:00
parent 0625e79e73
commit 250bd94812
5 changed files with 117 additions and 38 deletions
+4 -3
View File
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import '../../core/constants.dart'; import '../../core/constants.dart';
import '../../shared/utils/currency_utils.dart';
import '../settings/provider.dart'; import '../settings/provider.dart';
import 'provider.dart'; import 'provider.dart';
@@ -257,7 +258,7 @@ class _PieChartCard extends StatelessWidget {
), ),
), ),
Text( Text(
'$currency${total.toStringAsFixed(2)}', formatAmount(currency, total),
style: Theme.of(context).textTheme.titleMedium?.copyWith( style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface, color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
@@ -311,7 +312,7 @@ class _BarChartCard extends StatelessWidget {
touchTooltipData: BarTouchTooltipData( touchTooltipData: BarTouchTooltipData(
getTooltipItem: (group, groupIndex, rod, rodIndex) { getTooltipItem: (group, groupIndex, rod, rodIndex) {
return BarTooltipItem( return BarTooltipItem(
'$currency${rod.toY.toStringAsFixed(2)}', formatAmount(currency, rod.toY),
TextStyle( TextStyle(
color: Theme.of(context).colorScheme.onPrimary, color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@@ -458,7 +459,7 @@ class _CategoryRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Text( Text(
'$currency${amount.toStringAsFixed(2)}', formatAmount(currency, amount),
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: AppColors.expense, color: AppColors.expense,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
+89 -24
View File
@@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import '../../core/constants.dart'; import '../../core/constants.dart';
import '../../shared/models/transaction.dart'; import '../../shared/models/transaction.dart';
import '../../shared/utils/currency_utils.dart';
import '../settings/provider.dart'; import '../settings/provider.dart';
import 'provider.dart'; import 'provider.dart';
@@ -307,13 +308,13 @@ class _BudgetProgress extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'Spent: ${currencyInfo.symbol}${spent.toStringAsFixed(2)}', 'Spent: ${formatAmount(currencyInfo.symbol, spent)}',
style: Theme.of(context).textTheme.bodySmall?.copyWith( style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6), color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
), ),
), ),
Text( Text(
'Limit: ${currencyInfo.symbol}${budget.toStringAsFixed(2)}', 'Limit: ${formatAmount(currencyInfo.symbol, budget)}',
style: Theme.of(context).textTheme.bodySmall?.copyWith( style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6), color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
), ),
@@ -349,7 +350,7 @@ class _BudgetWarning extends StatelessWidget {
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: Text( child: Text(
'Budget exceeded by ${currencyInfo.symbol}${over.toStringAsFixed(2)}', 'Budget exceeded by ${formatAmount(currencyInfo.symbol, over)}',
style: Theme.of(context).textTheme.bodySmall?.copyWith( style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: AppColors.expense, color: AppColors.expense,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@@ -362,13 +363,22 @@ class _BudgetWarning extends StatelessWidget {
} }
} }
class _BalanceCard extends StatelessWidget { class _BalanceCard extends ConsumerWidget {
final double balance; final double balance;
final CurrencyInfo currencyInfo; final CurrencyInfo currencyInfo;
const _BalanceCard({required this.balance, required this.currencyInfo}); const _BalanceCard({required this.balance, required this.currencyInfo});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final rates = ref.read(exchangeRateServiceProvider);
final allCurrencies = [
('USD', '\$'),
('EUR', ''),
('BYN', 'Br'),
('RUB', ''),
];
final others = allCurrencies.where((c) => c.$1 != currencyInfo.code).toList();
return Container( return Container(
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
@@ -390,34 +400,89 @@ class _BalanceCard extends StatelessWidget {
), ),
], ],
), ),
child: LayoutBuilder(
builder: (context, constraints) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// LEFT: main balance — takes as much space as needed, right side shrinks first
Flexible(
flex: 3,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Text(
'Total Balance', 'TOTAL BALANCE',
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary.withOpacity(0.7), fontSize: 11,
), letterSpacing: 1.2,
), color: Theme.of(context).colorScheme.onPrimary.withOpacity(0.6),
const SizedBox(height: 8),
Text(
'${currencyInfo.symbol}${balance.toStringAsFixed(2)}',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.w700,
letterSpacing: -0.5,
), ),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( // FittedBox shrinks text to fit available width
'Converted to ${currencyInfo.symbol}${currencyInfo.code}', FittedBox(
style: Theme.of(context).textTheme.bodySmall?.copyWith( fit: BoxFit.scaleDown,
color: Theme.of(context).colorScheme.onPrimary.withOpacity(0.6), alignment: Alignment.centerLeft,
fontSize: 11, child: Text(
formatAmount(currencyInfo.symbol, balance),
style: TextStyle(
fontSize: 36, // max font size
fontWeight: FontWeight.w700,
color: Theme.of(context).colorScheme.onPrimary,
),
maxLines: 1,
), ),
), ),
], ],
), ),
),
// RIGHT side: use Flexible (not Expanded) so it can shrink
// When balance is long, this column gets squeezed first
Flexible(
flex: 2,
child: Row(
children: [
const SizedBox(width: 12),
Container(
width: 1,
height: 60,
color: Theme.of(context).colorScheme.onPrimary.withOpacity(0.15),
),
const SizedBox(width: 12),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: others.map((c) {
final converted = rates.convert(balance, currencyInfo.code, c.$1);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(
formatAmount(c.$2, converted),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onPrimary.withOpacity(0.7),
),
maxLines: 1,
),
),
);
}).toList(),
),
),
],
),
),
],
);
},
),
); );
} }
} }
@@ -480,7 +545,7 @@ class _SummaryCard extends StatelessWidget {
Text(label, style: Theme.of(context).textTheme.bodySmall?.copyWith(color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6))), Text(label, style: Theme.of(context).textTheme.bodySmall?.copyWith(color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6))),
const SizedBox(height: 2), const SizedBox(height: 2),
Text( Text(
'${currencyInfo.symbol}${amount.toStringAsFixed(2)}', formatAmount(currencyInfo.symbol, amount),
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: color, color: color,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@@ -562,7 +627,7 @@ class _TransactionTile extends StatelessWidget {
), ),
), ),
Text( Text(
'${isIncome ? '+' : '-'}${transaction.currency}${transaction.amount.toStringAsFixed(2)}', '${isIncome ? '+' : '-'}${formatAmount(transaction.currency, transaction.amount)}',
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: color, color: color,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
+2 -1
View File
@@ -5,6 +5,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../shared/services/exchange_rate_service.dart'; import '../../shared/services/exchange_rate_service.dart';
import '../../shared/utils/currency_utils.dart';
import '../dashboard/provider.dart'; import '../dashboard/provider.dart';
final budgetProvider = StateNotifierProvider<BudgetNotifier, double?>((ref) { final budgetProvider = StateNotifierProvider<BudgetNotifier, double?>((ref) {
@@ -124,7 +125,7 @@ class ExportService {
final date = DateFormat('yyyy-MM-dd').format(tx.date); final date = DateFormat('yyyy-MM-dd').format(tx.date);
final type = tx.type.name; final type = tx.type.name;
final category = tx.category; final category = tx.category;
final amount = '${tx.currency}${tx.amount.toStringAsFixed(2)}'; final amount = formatAmount(tx.currency, tx.amount);
final note = tx.note?.replaceAll(',', ';') ?? ''; final note = tx.note?.replaceAll(',', ';') ?? '';
buffer.writeln('$date,$type,$category,$amount,${tx.currencyCode},$note'); buffer.writeln('$date,$type,$category,$amount,${tx.currencyCode},$note');
} }
+5 -2
View File
@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import '../../core/constants.dart'; import '../../core/constants.dart';
import '../../shared/utils/currency_utils.dart';
import 'provider.dart'; import 'provider.dart';
class SettingsScreen extends ConsumerStatefulWidget { class SettingsScreen extends ConsumerStatefulWidget {
@@ -196,7 +197,9 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
FilteringTextInputFormatter.allow(RegExp(r'^\d+\.?\d{0,2}')), FilteringTextInputFormatter.allow(RegExp(r'^\d+\.?\d{0,2}')),
], ],
decoration: InputDecoration( decoration: InputDecoration(
prefixText: '${currencyInfo.symbol} ', prefixText: currencyInfo.symbol == 'Br' || currencyInfo.symbol == ''
? '${currencyInfo.symbol} '
: currencyInfo.symbol,
hintText: '0.00', hintText: '0.00',
helperText: 'Leave empty to remove budget limit', helperText: 'Leave empty to remove budget limit',
), ),
@@ -232,7 +235,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
children: [ children: [
Text( Text(
budget != null budget != null
? _currencyFmt.format(budget) ? formatAmount(currencyInfo.symbol, budget)
: 'Not set', : 'Not set',
style: Theme.of(context).textTheme.headlineSmall?.copyWith( style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: budget != null ? AppColors.accent : Theme.of(context).colorScheme.onSurface.withOpacity(0.6), color: budget != null ? AppColors.accent : Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
+9
View File
@@ -0,0 +1,9 @@
String formatAmount(String symbol, double amount) {
// Symbols that need a space after them (prefix symbols like Br, ₽ etc.)
const spaceAfter = {'Br', ''};
final formatted = amount.toStringAsFixed(2);
if (spaceAfter.contains(symbol)) {
return '$symbol $formatted';
}
return '$symbol$formatted';
}