This commit is contained in:
2026-03-20 16:40:25 +03:00
parent 250bd94812
commit 1daeb1aa22
7 changed files with 195 additions and 33 deletions
+38
View File
@@ -74,6 +74,44 @@ class AppCategories {
}; };
} }
enum AmountFormat { commasDot, spacesDot, plain }
extension AmountFormatExt on AmountFormat {
String get label {
switch (this) {
case AmountFormat.commasDot: return '1,234,567.89';
case AmountFormat.spacesDot: return '1 234 567.89';
case AmountFormat.plain: return '1234567.89';
}
}
String get example {
switch (this) {
case AmountFormat.commasDot: return 'SYM 1,234.56';
case AmountFormat.spacesDot: return 'SYM 1 234.56';
case AmountFormat.plain: return 'SYM 1234.56';
}
}
String format(double amount) {
switch (this) {
case AmountFormat.commasDot:
// groups of 3 with commas, dot decimal
final parts = amount.toStringAsFixed(2).split('.');
final intPart = parts[0].replaceAllMapped(
RegExp(r'(\d)(?=(\d{3})+$)'), (m) => '${m[1]},');
return '$intPart.${parts[1]}';
case AmountFormat.spacesDot:
final parts = amount.toStringAsFixed(2).split('.');
final intPart = parts[0].replaceAllMapped(
RegExp(r'(\d)(?=(\d{3})+$)'), (m) => '${m[1]} ');
return '$intPart.${parts[1]}';
case AmountFormat.plain:
return amount.toStringAsFixed(2);
}
}
}
class CurrencyOption { class CurrencyOption {
final String symbol; final String symbol;
final String name; final String name;
+13 -9
View File
@@ -5,6 +5,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/utils/currency_utils.dart'; import '../../shared/utils/currency_utils.dart';
import '../../shared/providers/amount_format_provider.dart';
import '../settings/provider.dart'; import '../settings/provider.dart';
import 'provider.dart'; import 'provider.dart';
@@ -180,7 +181,7 @@ class _ToggleButton extends StatelessWidget {
} }
} }
class _PieChartCard extends StatelessWidget { class _PieChartCard extends ConsumerWidget {
final Map<String, double> data; final Map<String, double> data;
final double total; final double total;
final int touchedIndex; final int touchedIndex;
@@ -196,7 +197,8 @@ class _PieChartCard extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
final entries = data.entries.toList(); final entries = data.entries.toList();
return Container( return Container(
@@ -258,7 +260,7 @@ class _PieChartCard extends StatelessWidget {
), ),
), ),
Text( Text(
formatAmount(currency, total), formatAmount(currency, total, fmt),
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,
@@ -275,13 +277,14 @@ class _PieChartCard extends StatelessWidget {
} }
} }
class _BarChartCard extends StatelessWidget { class _BarChartCard extends ConsumerWidget {
final List<MonthlyData> monthlyData; final List<MonthlyData> monthlyData;
final String currency; final String currency;
const _BarChartCard({required this.monthlyData, required this.currency}); const _BarChartCard({required this.monthlyData, required this.currency});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
final maxY = monthlyData.map((e) => e.amount).reduce((a, b) => a > b ? a : b); final maxY = monthlyData.map((e) => e.amount).reduce((a, b) => a > b ? a : b);
final adjustedMaxY = maxY * 1.2; final adjustedMaxY = maxY * 1.2;
@@ -312,7 +315,7 @@ class _BarChartCard extends StatelessWidget {
touchTooltipData: BarTouchTooltipData( touchTooltipData: BarTouchTooltipData(
getTooltipItem: (group, groupIndex, rod, rodIndex) { getTooltipItem: (group, groupIndex, rod, rodIndex) {
return BarTooltipItem( return BarTooltipItem(
formatAmount(currency, rod.toY), formatAmount(currency, rod.toY, fmt),
TextStyle( TextStyle(
color: Theme.of(context).colorScheme.onPrimary, color: Theme.of(context).colorScheme.onPrimary,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@@ -390,7 +393,7 @@ class _BarChartCard extends StatelessWidget {
} }
} }
class _CategoryRow extends StatelessWidget { class _CategoryRow extends ConsumerWidget {
final int rank; final int rank;
final String category; final String category;
final double amount; final double amount;
@@ -405,7 +408,8 @@ class _CategoryRow extends StatelessWidget {
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
final color = AppCategories.colors[category] ?? AppColors.accent; final color = AppCategories.colors[category] ?? AppColors.accent;
final icon = AppCategories.icons[category] ?? Icons.category_rounded; final icon = AppCategories.icons[category] ?? Icons.category_rounded;
final pct = total > 0 ? amount / total : 0.0; final pct = total > 0 ? amount / total : 0.0;
@@ -459,7 +463,7 @@ class _CategoryRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Text( Text(
formatAmount(currency, amount), formatAmount(currency, amount, fmt),
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,
+23 -16
View File
@@ -5,6 +5,7 @@ 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 '../../shared/utils/currency_utils.dart';
import '../../shared/providers/amount_format_provider.dart';
import '../settings/provider.dart'; import '../settings/provider.dart';
import 'provider.dart'; import 'provider.dart';
@@ -245,7 +246,7 @@ class _FilterChip extends StatelessWidget {
} }
} }
class _BudgetProgress extends StatelessWidget { class _BudgetProgress extends ConsumerWidget {
final double spent; final double spent;
final double budget; final double budget;
final CurrencyInfo currencyInfo; final CurrencyInfo currencyInfo;
@@ -257,7 +258,8 @@ class _BudgetProgress extends StatelessWidget {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
final ratio = spent / budget; final ratio = spent / budget;
final color = ratio >= 1.0 final color = ratio >= 1.0
? AppColors.expense ? AppColors.expense
@@ -308,13 +310,13 @@ class _BudgetProgress extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'Spent: ${formatAmount(currencyInfo.symbol, spent)}', 'Spent: ${formatAmount(currencyInfo.symbol, spent, fmt)}',
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: ${formatAmount(currencyInfo.symbol, budget)}', 'Limit: ${formatAmount(currencyInfo.symbol, budget, fmt)}',
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),
), ),
@@ -327,14 +329,15 @@ class _BudgetProgress extends StatelessWidget {
} }
} }
class _BudgetWarning extends StatelessWidget { class _BudgetWarning extends ConsumerWidget {
final double spent; final double spent;
final double budget; final double budget;
final CurrencyInfo currencyInfo; final CurrencyInfo currencyInfo;
const _BudgetWarning({required this.spent, required this.budget, required this.currencyInfo}); const _BudgetWarning({required this.spent, required this.budget, required this.currencyInfo});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
final over = spent - budget; final over = spent - budget;
final isDark = Theme.of(context).brightness == Brightness.dark; final isDark = Theme.of(context).brightness == Brightness.dark;
return Container( return Container(
@@ -350,7 +353,7 @@ class _BudgetWarning extends StatelessWidget {
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: Text( child: Text(
'Budget exceeded by ${formatAmount(currencyInfo.symbol, over)}', 'Budget exceeded by ${formatAmount(currencyInfo.symbol, over, fmt)}',
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,
@@ -371,6 +374,7 @@ class _BalanceCard extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final rates = ref.read(exchangeRateServiceProvider); final rates = ref.read(exchangeRateServiceProvider);
final fmt = ref.watch(amountFormatProvider);
final allCurrencies = [ final allCurrencies = [
('USD', '\$'), ('USD', '\$'),
('EUR', ''), ('EUR', ''),
@@ -381,7 +385,8 @@ class _BalanceCard extends ConsumerWidget {
return Container( return Container(
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.all(24), height: 140,
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
colors: [ colors: [
@@ -426,7 +431,7 @@ class _BalanceCard extends ConsumerWidget {
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
formatAmount(currencyInfo.symbol, balance), formatAmount(currencyInfo.symbol, balance, fmt),
style: TextStyle( style: TextStyle(
fontSize: 36, // max font size fontSize: 36, // max font size
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
@@ -463,7 +468,7 @@ class _BalanceCard extends ConsumerWidget {
fit: BoxFit.scaleDown, fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
formatAmount(c.$2, converted), formatAmount(c.$2, converted, fmt),
style: TextStyle( style: TextStyle(
fontSize: 13, fontSize: 13,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
@@ -505,7 +510,7 @@ class _SummaryRow extends StatelessWidget {
} }
} }
class _SummaryCard extends StatelessWidget { class _SummaryCard extends ConsumerWidget {
final String label; final String label;
final double amount; final double amount;
final Color color; final Color color;
@@ -519,7 +524,8 @@ class _SummaryCard extends StatelessWidget {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
return Container( return Container(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
decoration: BoxDecoration( decoration: BoxDecoration(
@@ -545,7 +551,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(
formatAmount(currencyInfo.symbol, amount), formatAmount(currencyInfo.symbol, amount, fmt),
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: color, color: color,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
@@ -561,7 +567,7 @@ class _SummaryCard extends StatelessWidget {
} }
} }
class _TransactionTile extends StatelessWidget { class _TransactionTile extends ConsumerWidget {
final Transaction transaction; final Transaction transaction;
const _TransactionTile({required this.transaction}); const _TransactionTile({required this.transaction});
@@ -571,7 +577,8 @@ class _TransactionTile extends StatelessWidget {
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final fmt = ref.watch(amountFormatProvider);
final isIncome = transaction.type == TransactionType.income; final isIncome = transaction.type == TransactionType.income;
final color = isIncome ? AppColors.income : AppColors.expense; final color = isIncome ? AppColors.income : AppColors.expense;
final catColor = AppCategories.colors[transaction.category] ?? AppColors.accent; final catColor = AppCategories.colors[transaction.category] ?? AppColors.accent;
@@ -627,7 +634,7 @@ class _TransactionTile extends StatelessWidget {
), ),
), ),
Text( Text(
'${isIncome ? '+' : '-'}${formatAmount(transaction.currency, transaction.amount)}', '${isIncome ? '+' : '-'}${formatAmount(transaction.currency, transaction.amount, fmt)}',
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: color, color: color,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
+4 -1
View File
@@ -4,8 +4,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:path_provider/path_provider.dart'; 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 '../../core/constants.dart';
import '../../shared/services/exchange_rate_service.dart'; import '../../shared/services/exchange_rate_service.dart';
import '../../shared/utils/currency_utils.dart'; import '../../shared/utils/currency_utils.dart';
import '../../shared/providers/amount_format_provider.dart';
import '../dashboard/provider.dart'; import '../dashboard/provider.dart';
final budgetProvider = StateNotifierProvider<BudgetNotifier, double?>((ref) { final budgetProvider = StateNotifierProvider<BudgetNotifier, double?>((ref) {
@@ -115,6 +117,7 @@ class ExportService {
Future<String> exportToCSV() async { Future<String> exportToCSV() async {
final transactions = _ref.read(transactionsProvider); final transactions = _ref.read(transactionsProvider);
final currency = _ref.read(currencyProvider); final currency = _ref.read(currencyProvider);
final fmt = _ref.read(amountFormatProvider);
// CSV header // CSV header
final buffer = StringBuffer(); final buffer = StringBuffer();
@@ -125,7 +128,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 = formatAmount(tx.currency, tx.amount); final amount = formatAmount(tx.currency, tx.amount, fmt);
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');
} }
+86 -1
View File
@@ -5,6 +5,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/utils/currency_utils.dart'; import '../../shared/utils/currency_utils.dart';
import '../../shared/providers/amount_format_provider.dart';
import 'provider.dart'; import 'provider.dart';
class SettingsScreen extends ConsumerStatefulWidget { class SettingsScreen extends ConsumerStatefulWidget {
@@ -55,6 +56,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
final themeMode = ref.watch(themeProvider); final themeMode = ref.watch(themeProvider);
final isDarkMode = themeMode == ThemeMode.dark; final isDarkMode = themeMode == ThemeMode.dark;
final currencyInfo = ref.watch(currencyProvider); final currencyInfo = ref.watch(currencyProvider);
final fmt = ref.watch(amountFormatProvider);
final isDark = Theme.of(context).brightness == Brightness.dark; final isDark = Theme.of(context).brightness == Brightness.dark;
// Update currency format when it changes // Update currency format when it changes
@@ -235,7 +237,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
children: [ children: [
Text( Text(
budget != null budget != null
? formatAmount(currencyInfo.symbol, budget) ? formatAmount(currencyInfo.symbol, budget, fmt)
: '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),
@@ -258,6 +260,89 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
// Amount Format Selector
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(16),
border: isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColors.accent.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.format_list_numbered_rounded,
color: AppColors.accent,
size: 20,
),
),
const SizedBox(width: 12),
Expanded(
child: Text(
'Amount Format',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onSurface,
),
),
),
],
),
const SizedBox(height: 16),
...AmountFormat.values.map((format) {
final isSelected = fmt == format;
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: GestureDetector(
onTap: () => ref.read(amountFormatProvider.notifier).set(format),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: isSelected
? AppColors.accent.withOpacity(0.2)
: Theme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(12),
border: isSelected
? Border.all(color: AppColors.accent, width: 1.5)
: (isDark ? null : Border.all(color: const Color(0xFFDDDDEE), width: 1)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
format.label,
style: TextStyle(
color: isSelected ? AppColors.accent : Theme.of(context).colorScheme.onSurface,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
),
),
Text(
format.example.replaceFirst('SYM', currencyInfo.symbol),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
fontSize: 12,
),
),
],
),
),
),
);
}).toList(),
],
),
),
const SizedBox(height: 16),
// Currency Selector // Currency Selector
Container( Container(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
@@ -0,0 +1,25 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../core/constants.dart';
class AmountFormatNotifier extends StateNotifier<AmountFormat> {
AmountFormatNotifier() : super(AmountFormat.commasDot) {
_load();
}
void _load() async {
final prefs = await SharedPreferences.getInstance();
final index = prefs.getInt('amount_format') ?? 0;
state = AmountFormat.values[index];
}
void set(AmountFormat format) async {
final prefs = await SharedPreferences.getInstance();
state = format;
await prefs.setInt('amount_format', format.index);
}
}
final amountFormatProvider = StateNotifierProvider<AmountFormatNotifier, AmountFormat>(
(ref) => AmountFormatNotifier(),
);
+6 -6
View File
@@ -1,9 +1,9 @@
String formatAmount(String symbol, double amount) { import '../../core/constants.dart';
String formatAmount(String symbol, double amount, AmountFormat fmt) {
// Symbols that need a space after them (prefix symbols like Br, ₽ etc.) // Symbols that need a space after them (prefix symbols like Br, ₽ etc.)
const spaceAfter = {'Br', ''}; const spaceAfter = {'Br', ''};
final formatted = amount.toStringAsFixed(2); final formatted = fmt.format(amount);
if (spaceAfter.contains(symbol)) { final sep = spaceAfter.contains(symbol) ? ' ' : '';
return '$symbol $formatted'; return '$symbol$sep$formatted';
}
return '$symbol$formatted';
} }