first google play release for internal testing

This commit is contained in:
2026-07-10 17:32:02 +03:00
parent e3c60c4775
commit 861a9abd02
11 changed files with 684 additions and 685 deletions
+71 -43
View File
@@ -1,4 +1,5 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../shared/models/account.dart';
import '../../shared/models/transaction.dart';
import '../dashboard/provider.dart';
import '../settings/provider.dart';
@@ -35,81 +36,88 @@ class _StatsTimeFilterNotifier extends Notifier<StatsTimeFilter> {
});
}
String _statsTargetCurrency(Ref ref) {
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
if (index > 0) {
final accounts = accountsAsync.value ?? [];
if (index <= accounts.length) {
return accounts[index - 1].currency;
}
String _resolveTargetCurrency(
int activeIndex,
List<Account> accounts,
String globalCurrency,
) {
if (activeIndex > 0 && activeIndex <= accounts.length) {
return accounts[activeIndex - 1].currency;
}
return globalCurrency;
}
CurrencyInfo _statsCurrencyInfo(Ref ref) {
final code = _statsTargetCurrency(ref);
return CurrencyInfo(currencyMap[code]?.symbol ?? '\$', code);
}
List<Transaction> _statsScopedTransactions(Ref ref) {
final txs = ref.watch(accountFilteredTransactionsProvider);
final timeFilter = ref.watch(statsTimeFilterProvider);
List<Transaction> _filterScopedTransactions(
List<Transaction> txs,
StatsTimeFilter timeFilter,
) {
var filtered = txs.where((t) => t.category != 'Transfer');
if (timeFilter == StatsTimeFilter.month) {
final now = DateTime.now();
filtered = filtered.where(
(t) => t.date.year == now.year && t.date.month == now.month,
);
}
return filtered.toList();
}
double _convertAmount(Ref ref, Transaction t) {
final exchange = ref.watch(exchangeRateServiceProvider);
return exchange.convert(
t.amount,
t.currencyCode,
_statsTargetCurrency(ref),
);
}
final statsCurrencyProvider = Provider<CurrencyInfo>((ref) {
return _statsCurrencyInfo(ref);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final code = _resolveTargetCurrency(index, accounts, globalCurrency);
return CurrencyInfo(currencyMap[code]?.symbol ?? '\$', code);
});
final statsScopedTransactionsProvider = Provider<List<Transaction>>((ref) {
return _statsScopedTransactions(ref);
});
final statsScopedTransactionsProvider = Provider<List<Transaction>>((ref) {
final txs = ref.watch(accountFilteredTransactionsProvider);
final timeFilter = ref.watch(statsTimeFilterProvider);
return _filterScopedTransactions(txs, timeFilter);
});
final statsIncomeTotalProvider = Provider<double>((ref) {
final exchange = ref.watch(exchangeRateServiceProvider);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
return ref
.watch(statsScopedTransactionsProvider)
.where((t) => t.type == TransactionType.income)
.fold(0.0, (sum, t) => sum + _convertAmount(ref, t));
.fold(0.0, (sum, t) => sum + exchange.convert(t.amount, t.currencyCode, target));
});
final statsExpenseTotalProvider = Provider<double>((ref) {
final exchange = ref.watch(exchangeRateServiceProvider);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
return ref
.watch(statsScopedTransactionsProvider)
.where((t) => t.type == TransactionType.expense)
.fold(0.0, (sum, t) => sum + _convertAmount(ref, t));
.fold(0.0, (sum, t) => sum + exchange.convert(t.amount, t.currencyCode, target));
});
final statsSummaryProvider = Provider<StatsSummary>((ref) {
final statsSummaryProvider = Provider<StatsSummary>((ref) {
final exchange = ref.watch(exchangeRateServiceProvider);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
final transactions = ref.watch(statsScopedTransactionsProvider);
var income = 0.0;
var expense = 0.0;
var incomeCount = 0;
var expenseCount = 0;
for (final transaction in transactions) {
final amount = _convertAmount(ref, transaction);
final amount = exchange.convert(transaction.amount, transaction.currencyCode, target);
if (transaction.type == TransactionType.income) {
income += amount;
incomeCount++;
@@ -128,22 +136,34 @@ final statsExpenseTotalProvider = Provider<double>((ref) {
averageIncome: incomeCount == 0 ? 0 : income / incomeCount,
averageExpense: expenseCount == 0 ? 0 : expense / expenseCount,
);
});
});
final categoryExpenseProvider = Provider<Map<String, double>>((ref) {
final exchange = ref.watch(exchangeRateServiceProvider);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
final map = <String, double>{};
for (final t in ref.watch(statsScopedTransactionsProvider)) {
if (t.type != TransactionType.expense) continue;
map[t.category] = (map[t.category] ?? 0) + _convertAmount(ref, t);
map[t.category] = (map[t.category] ?? 0) + exchange.convert(t.amount, t.currencyCode, target);
}
return map;
});
final categoryIncomeProvider = Provider<Map<String, double>>((ref) {
final exchange = ref.watch(exchangeRateServiceProvider);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
final map = <String, double>{};
for (final t in ref.watch(statsScopedTransactionsProvider)) {
if (t.type != TransactionType.income) continue;
map[t.category] = (map[t.category] ?? 0) + _convertAmount(ref, t);
map[t.category] = (map[t.category] ?? 0) + exchange.convert(t.amount, t.currencyCode, target);
}
return map;
});
@@ -151,7 +171,11 @@ final categoryIncomeProvider = Provider<Map<String, double>>((ref) {
final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
final txs = ref.watch(accountFilteredTransactionsProvider);
final exchange = ref.watch(exchangeRateServiceProvider);
final target = _statsTargetCurrency(ref);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
final now = DateTime.now();
final months = <MonthlyData>[];
@@ -177,7 +201,11 @@ final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
final monthlyIncomeBreakdownProvider = Provider<List<MonthlyData>>((ref) {
final txs = ref.watch(accountFilteredTransactionsProvider);
final exchange = ref.watch(exchangeRateServiceProvider);
final target = _statsTargetCurrency(ref);
final index = ref.watch(activeAccountIndexProvider);
final accountsAsync = ref.watch(accountsProvider);
final globalCurrency = ref.watch(currencyProvider).code;
final accounts = accountsAsync.value ?? [];
final target = _resolveTargetCurrency(index, accounts, globalCurrency);
final now = DateTime.now();
final months = <MonthlyData>[];