Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix: Use getValidAccessToken() in connectivity banner sync button (#851)

Lazy Bone81cf4738620c
diff --git a/mobile/lib/screens/dashboard_screen.dart b/mobile/lib/screens/dashboard_screen.dart
index e62717c402..2ab6c6d687 100644
--- a/mobile/lib/screens/dashboard_screen.dart
+++ b/mobile/lib/screens/dashboard_screen.dart
@@ -5,8 +5,11 @@ import '../providers/auth_provider.dart';
import '../providers/accounts_provider.dart';
import '../providers/transactions_provider.dart';
import '../services/log_service.dart';
+import '../services/preferences_service.dart';
import '../widgets/account_card.dart';
import '../widgets/connectivity_banner.dart';
+import '../widgets/net_worth_card.dart';
+import '../widgets/currency_filter.dart';
import 'transaction_form_screen.dart';
import 'transactions_list_screen.dart';
import 'log_viewer_screen.dart';
@@ -15,21 +18,28 @@ class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
@override
- State<DashboardScreen> createState() => _DashboardScreenState();
+ DashboardScreenState createState() => DashboardScreenState();
}
-class _DashboardScreenState extends State<DashboardScreen> {
+class DashboardScreenState extends State<DashboardScreen> {
final LogService _log = LogService.instance;
- bool _assetsExpanded = true;
- bool _liabilitiesExpanded = true;
bool _showSyncSuccess = false;
int _previousPendingCount = 0;
TransactionsProvider? _transactionsProvider;
+ // Filter state
+ AccountFilter _accountFilter = AccountFilter.all;
+ Set<String> _selectedCurrencies = {};
+
+ // Group by type state
+ bool _groupByType = false;
+ final Set<String> _collapsedGroups = {};
+
@override
void initState() {
super.initState();
_loadAccounts();
+ _loadPreferences();
// Listen for sync completion to show success indicator
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -92,6 +102,19 @@ class _DashboardScreenState extends State<DashboardScreen> {
}
}
+ Future<void> _loadPreferences() async {
+ final groupByType = await PreferencesService.instance.getGroupByType();
+ if (mounted) {
+ setState(() {
+ _groupByType = groupByType;
+ });
+ }
+ }
+
+ void reloadPreferences() {
+ _loadPreferences();
+ }
+
Future<void> _handleRefresh() async {
await _performManualSync();
}
@@ -173,7 +196,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
}
}
- List<String> _formatCurrencyItem(String currency, double amount) {
+ String _formatAmount(String currency, double amount) {
final symbol = _getCurrencySymbol(currency);
final isSmallAmount = amount.abs() < 1 && amount != 0;
final formattedAmount = amount.toStringAsFixed(isSmallAmount ? 4 : 0);
@@ -186,7 +209,40 @@ class _DashboardScreenState extends State<DashboardScreen> {
);
final finalAmount = parts.length > 1 ? '$integerPart.${parts[1]}' : integerPart;
- return [currency, '$symbol$finalAmount'];
+ return '$symbol$finalAmount $currency';
+ }
+
+ Set<String> _getAllCurrencies(AccountsProvider accountsProvider) {
+ final currencies = <String>{};
+ for (var account in accountsProvider.accounts) {
+ currencies.add(account.currency);
+ }
+ return currencies;
+ }
+
+ List<Account> _getFilteredAccounts(AccountsProvider accountsProvider) {
+ var accounts = accountsProvider.accounts.toList();
+
+ // Filter by account type
+ switch (_accountFilter) {
+ case AccountFilter.assets:
+ accounts = accounts.where((a) => a.isAsset).toList();
+ break;
+ case AccountFilter.liabilities:
+ accounts = accounts.where((a) => a.isLiability).toList();
+ break;
+ case AccountFilter.all:
+ // Show all accounts (assets and liabilities)
+ accounts = accounts.where((a) => a.isAsset || a.isLiability).toList();
+ break;
+ }
+
+ // Filter by currency if any selected
+ if (_selectedCurrencies.isNotEmpty) {
+ accounts = accounts.where((a) => _selectedCurrencies.contains(a.currency)).toList();
+ }
+
+ return accounts;
}
String _getCurrencySymbol(String currency) {
@@ -449,124 +505,41 @@ class _DashboardScreenState extends State<DashboardScreen> {
onRefresh: _handleRefresh,
child: CustomScrollView(
slivers: [
- // Welcome header
+ // Net Worth Card with Asset/Liability filter
SliverToBoxAdapter(
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- 'Welcome${authProvider.user != null ? ', ${authProvider.user!.displayName}' : ''}',
- style: Theme.of(context).textTheme.headlineSmall?.copyWith(
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 4),
- Text(
- 'Here\'s your financial overview',
- style: TextStyle(color: colorScheme.onSurfaceVariant),
- ),
- ],
- ),
+ child: NetWorthCard(
+ assetTotalsByCurrency: accountsProvider.assetTotalsByCurrency,
+ liabilityTotalsByCurrency: accountsProvider.liabilityTotalsByCurrency,
+ currentFilter: _accountFilter,
+ onFilterChanged: (filter) {
+ setState(() {
+ _accountFilter = filter;
+ });
+ },
+ formatAmount: _formatAmount,
),
),
- // Summary cards
+ // Currency filter
SliverToBoxAdapter(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- children: [
- if (accountsProvider.assetAccounts.isNotEmpty)
- _SummaryCard(
- title: 'Assets Total',
- totals: accountsProvider.assetTotalsByCurrency,
- color: Colors.green,
- formatCurrencyItem: _formatCurrencyItem,
- ),
- if (accountsProvider.liabilityAccounts.isNotEmpty)
- _SummaryCard(
- title: 'Liabilities Total',
- totals: accountsProvider.liabilityTotalsByCurrency,
- color: Colors.red,
- formatCurrencyItem: _formatCurrencyItem,
- ),
- ],
- ),
+ child: CurrencyFilter(
+ availableCurrencies: _getAllCurrencies(accountsProvider),
+ selectedCurrencies: _selectedCurrencies,
+ onSelectionChanged: (currencies) {
+ setState(() {
+ _selectedCurrencies = currencies;
+ });
+ },
),
),
- // Assets section
- if (accountsProvider.assetAccounts.isNotEmpty) ...[
- SliverToBoxAdapter(
- child: _CollapsibleSectionHeader(
- title: 'Assets',
- count: accountsProvider.assetAccounts.length,
- color: Colors.green,
- isExpanded: _assetsExpanded,
- onToggle: () {
- setState(() {
- _assetsExpanded = !_assetsExpanded;
- });
- },
- ),
- ),
- if (_assetsExpanded)
- SliverPadding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- sliver: SliverList(
- delegate: SliverChildBuilderDelegate(
- (context, index) {
- final account = accountsProvider.assetAccounts[index];
- return AccountCard(
- account: account,
- onTap: () => _handleAccountTap(account),
- onSwipe: () => _handleAccountSwipe(account),
- );
- },
- childCount: accountsProvider.assetAccounts.length,
- ),
- ),
- ),
- ],
-
- // Liabilities section
- if (accountsProvider.liabilityAccounts.isNotEmpty) ...[
- SliverToBoxAdapter(
- child: _CollapsibleSectionHeader(
- title: 'Liabilities',
- count: accountsProvider.liabilityAccounts.length,
- color: Colors.red,
- isExpanded: _liabilitiesExpanded,
- onToggle: () {
- setState(() {
- _liabilitiesExpanded = !_liabilitiesExpanded;
- });
- },
- ),
- ),
- if (_liabilitiesExpanded)
- SliverPadding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- sliver: SliverList(
- delegate: SliverChildBuilderDelegate(
- (context, index) {
- final account = accountsProvider.liabilityAccounts[index];
- return AccountCard(
- account: account,
- onTap: () => _handleAccountTap(account),
- onSwipe: () => _handleAccountSwipe(account),
- );
- },
- childCount: accountsProvider.liabilityAccounts.length,
- ),
- ),
- ),
- ],
+ // Spacing
+ const SliverToBoxAdapter(
+ child: SizedBox(height: 8),
+ ),
- // Uncategorized accounts
- ..._buildUncategorizedSection(accountsProvider),
+ // Filtered accounts section
+ ..._buildFilteredAccountsSection(accountsProvider),
// Bottom padding
const SliverToBoxAdapter(
@@ -583,253 +556,221 @@ class _DashboardScreenState extends State<DashboardScreen> {
);
}
- List<Widget> _buildUncategorizedSection(AccountsProvider accountsProvider) {
- final uncategorized = accountsProvider.accounts
- .where((a) => !a.isAsset && !a.isLiability)
- .toList();
+ List<Widget> _buildFilteredAccountsSection(AccountsProvider accountsProvider) {
+ final filteredAccounts = _getFilteredAccounts(accountsProvider);
+
+ if (filteredAccounts.isEmpty) {
+ return [
+ SliverToBoxAdapter(
+ child: Center(
+ child: Padding(
+ padding: const EdgeInsets.all(32),
+ child: Column(
+ children: [
+ Icon(
+ Icons.account_balance_wallet_outlined,
+ size: 48,
+ color: Theme.of(context).colorScheme.onSurfaceVariant,
+ ),
+ const SizedBox(height: 16),
+ Text(
+ 'No accounts match the current filter',
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.onSurfaceVariant,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ];
+ }
+
+ // Sort accounts: by type, then currency, then balance
+ filteredAccounts.sort((a, b) {
+ if (a.isAsset && !b.isAsset) return -1;
+ if (!a.isAsset && b.isAsset) return 1;
+ int typeComparison = a.accountType.compareTo(b.accountType);
+ if (typeComparison != 0) return typeComparison;
+ int currencyComparison = a.currency.compareTo(b.currency);
+ if (currencyComparison != 0) return currencyComparison;
+ return b.balanceAsDouble.compareTo(a.balanceAsDouble);
+ });
- if (uncategorized.isEmpty) {
- return [];
+ if (_groupByType) {
+ return _buildGroupedAccountsList(filteredAccounts);
}
+ return _buildFlatAccountsList(filteredAccounts);
+ }
+
+ List<Widget> _buildFlatAccountsList(List<Account> accounts) {
return [
- SliverToBoxAdapter(
- child: _SimpleSectionHeader(
- title: 'Other Accounts',
- count: uncategorized.length,
- color: Colors.grey,
- ),
- ),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
- final account = uncategorized[index];
+ final account = accounts[index];
return AccountCard(
account: account,
onTap: () => _handleAccountTap(account),
onSwipe: () => _handleAccountSwipe(account),
);
},
- childCount: uncategorized.length,
+ childCount: accounts.length,
),
),
),
];
}
-}
-
-class _SummaryCard extends StatelessWidget {
- final String title;
- final Map<String, double> totals;
- final Color color;
- final List<String> Function(String currency, double amount) formatCurrencyItem;
-
- const _SummaryCard({
- required this.title,
- required this.totals,
- required this.color,
- required this.formatCurrencyItem,
- });
-
- @override
- Widget build(BuildContext context) {
- final entries = totals.entries.toList();
- final rows = <Widget>[];
-
- // Group currencies into pairs (2 per row)
- for (int i = 0; i < entries.length; i += 2) {
- final first = entries[i];
- final firstFormatted = formatCurrencyItem(first.key, first.value);
- if (i + 1 < entries.length) {
- // Two items in this row
- final second = entries[i + 1];
- final secondFormatted = formatCurrencyItem(second.key, second.value);
+ List<Widget> _buildGroupedAccountsList(List<Account> accounts) {
+ // Group accounts by accountType
+ final groups = <String, List<Account>>{};
+ for (final account in accounts) {
+ groups.putIfAbsent(account.accountType, () => []).add(account);
+ }
- rows.add(
- Row(
- children: [
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- firstFormatted[0],
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500,
- ),
- ),
- Text(
- firstFormatted[1],
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- Text(
- ' | ',
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w300,
- color: color.withValues(alpha: 0.5),
- ),
- ),
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- secondFormatted[0],
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500,
- ),
- ),
- Text(
- secondFormatted[1],
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- ),
- ],
+ final slivers = <Widget>[];
+ for (final entry in groups.entries) {
+ final accountType = entry.key;
+ final groupAccounts = entry.value;
+ final isCollapsed = _collapsedGroups.contains(accountType);
+
+ // Use first account to get display name and icon
+ final displayName = groupAccounts.first.displayAccountType;
+
+ slivers.add(
+ SliverToBoxAdapter(
+ child: _CollapsibleTypeHeader(
+ title: displayName,
+ count: groupAccounts.length,
+ accountType: accountType,
+ isCollapsed: isCollapsed,
+ onToggle: () {
+ setState(() {
+ if (isCollapsed) {
+ _collapsedGroups.remove(accountType);
+ } else {
+ _collapsedGroups.add(accountType);
+ }
+ });
+ },
),
- );
- } else {
- // Only one item in this row
- rows.add(
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- firstFormatted[0],
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500,
- ),
- ),
- Text(
- firstFormatted[1],
- style: Theme.of(context).textTheme.bodyMedium?.copyWith(
- fontWeight: FontWeight.w500,
- ),
+ ),
+ );
+
+ if (!isCollapsed) {
+ slivers.add(
+ SliverPadding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ sliver: SliverList(
+ delegate: SliverChildBuilderDelegate(
+ (context, index) {
+ final account = groupAccounts[index];
+ return AccountCard(
+ account: account,
+ onTap: () => _handleAccountTap(account),
+ onSwipe: () => _handleAccountSwipe(account),
+ );
+ },
+ childCount: groupAccounts.length,
),
- ],
+ ),
),
);
}
-
- if (i + 2 < entries.length) {
- rows.add(const SizedBox(height: 4));
- }
}
- return Container(
- margin: const EdgeInsets.only(bottom: 12),
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- color: color.withValues(alpha: 0.1),
- borderRadius: BorderRadius.circular(12),
- border: Border.all(
- color: color.withValues(alpha: 0.3),
- width: 1,
- ),
- ),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- width: 4,
- height: 40,
- decoration: BoxDecoration(
- color: color,
- borderRadius: BorderRadius.circular(2),
- ),
- ),
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: Theme.of(context).textTheme.titleMedium?.copyWith(
- fontWeight: FontWeight.bold,
- color: color,
- ),
- ),
- const SizedBox(height: 8),
- ...rows,
- ],
- ),
- ),
- ],
- ),
- );
+ return slivers;
}
}
-class _CollapsibleSectionHeader extends StatelessWidget {
+class _CollapsibleTypeHeader extends StatelessWidget {
final String title;
final int count;
- final Color color;
- final bool isExpanded;
+ final String accountType;
+ final bool isCollapsed;
final VoidCallback onToggle;
- const _CollapsibleSectionHeader({
+ const _CollapsibleTypeHeader({
required this.title,
required this.count,
- required this.color,
- required this.isExpanded,
+ required this.accountType,
+ required this.isCollapsed,
required this.onToggle,
});
+ IconData _getTypeIcon() {
+ switch (accountType) {
+ case 'depository':
+ return Icons.account_balance;
+ case 'credit_card':
+ return Icons.credit_card;
+ case 'investment':
+ return Icons.trending_up;
+ case 'loan':
+ return Icons.receipt_long;
+ case 'property':
+ return Icons.home;
+ case 'vehicle':
+ return Icons.directions_car;
+ case 'crypto':
+ return Icons.currency_bitcoin;
+ case 'other_asset':
+ return Icons.category;
+ case 'other_liability':
+ return Icons.payment;
+ default:
+ return Icons.account_balance_wallet;
+ }
+ }
+
@override
Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+
return InkWell(
onTap: onToggle,
child: Padding(
- padding: const EdgeInsets.fromLTRB(16, 24, 16, 8),
+ padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
child: Row(
children: [
- Container(
- width: 4,
- height: 24,
- decoration: BoxDecoration(
- color: color,
- borderRadius: BorderRadius.circular(2),
- ),
+ Icon(
+ _getTypeIcon(),
+ size: 18,
+ color: colorScheme.onSurfaceVariant,
),
- const SizedBox(width: 12),
+ const SizedBox(width: 10),
Text(
title,
- style: Theme.of(context).textTheme.titleMedium?.copyWith(
- fontWeight: FontWeight.bold,
- ),
+ style: Theme.of(context).textTheme.titleSmall?.copyWith(
+ fontWeight: FontWeight.w600,
+ ),
),
const SizedBox(width: 8),
Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
+ padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
decoration: BoxDecoration(
- color: color.withValues(alpha: 0.1),
- borderRadius: BorderRadius.circular(12),
+ color: colorScheme.primaryContainer.withValues(alpha: 0.5),
+ borderRadius: BorderRadius.circular(10),
),
child: Text(
count.toString(),
style: TextStyle(
- color: color,
+ color: colorScheme.onPrimaryContainer,
fontWeight: FontWeight.bold,
- fontSize: 12,
+ fontSize: 11,
),
),
),
const Spacer(),
Icon(
- isExpanded ? Icons.expand_less : Icons.expand_more,
- color: color,
+ isCollapsed ? Icons.expand_more : Icons.expand_less,
+ size: 20,
+ color: colorScheme.onSurfaceVariant,
),
],
),
@@ -837,57 +778,3 @@ class _CollapsibleSectionHeader extends StatelessWidget {
);
}
}
-
-class _SimpleSectionHeader extends StatelessWidget {
- final String title;
- final int count;
- final Color color;
-
- const _SimpleSectionHeader({
- required this.title,
- required this.count,
- required this.color,
- });
-
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.fromLTRB(16, 24, 16, 8),
- child: Row(
- children: [
- Container(
- width: 4,
- height: 24,
- decoration: BoxDecoration(
- color: color,
- borderRadius: BorderRadius.circular(2),
- ),
- ),
- const SizedBox(width: 12),
- Text(
- title,
- style: Theme.of(context).textTheme.titleMedium?.copyWith(
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(width: 8),
- Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
- decoration: BoxDecoration(
- color: color.withValues(alpha: 0.1),
- borderRadius: BorderRadius.circular(12),
- ),
- child: Text(
- count.toString(),
- style: TextStyle(
- color: color,
- fontWeight: FontWeight.bold,
- fontSize: 12,
- ),
- ),
- ),
- ],
- ),
- );
- }
-}
diff --git a/mobile/lib/screens/main_navigation_screen.dart b/mobile/lib/screens/main_navigation_screen.dart
index a253bf6145..281524b275 100644
--- a/mobile/lib/screens/main_navigation_screen.dart
+++ b/mobile/lib/screens/main_navigation_screen.dart
@@ -13,13 +13,21 @@ class MainNavigationScreen extends StatefulWidget {
class _MainNavigationScreenState extends State<MainNavigationScreen> {
int _currentIndex = 0;
+ int _previousIndex = 0;
+ final _dashboardKey = GlobalKey<DashboardScreenState>();
- final List<Widget> _screens = [
- const DashboardScreen(),
- const ChatListScreen(),
- const MoreScreen(),
- const SettingsScreen(),
- ];
+ late final List<Widget> _screens;
+
+ @override
+ void initState() {
+ super.initState();
+ _screens = [
+ DashboardScreen(key: _dashboardKey),
+ const ChatListScreen(),
+ const MoreScreen(),
+ const SettingsScreen(),
+ ];
+ }
@override
Widget build(BuildContext context) {
@@ -31,9 +39,14 @@ class _MainNavigationScreenState extends State<MainNavigationScreen> {
bottomNavigationBar: NavigationBar(
selectedIndex: _currentIndex,
onDestinationSelected: (index) {
+ _previousIndex = _currentIndex;
setState(() {
_currentIndex = index;
});
+ // Reload preferences when switching back to dashboard from settings
+ if (index == 0 && _previousIndex == 3) {
+ _dashboardKey.currentState?.reloadPreferences();
+ }
},
destinations: const [
NavigationDestination(
diff --git a/mobile/lib/screens/settings_screen.dart b/mobile/lib/screens/settings_screen.dart
index 0f5518c8c9..38a996ac89 100644
--- a/mobile/lib/screens/settings_screen.dart
+++ b/mobile/lib/screens/settings_screen.dart
@@ -3,10 +3,33 @@ import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import '../services/offline_storage_service.dart';
import '../services/log_service.dart';
+import '../services/preferences_service.dart';
-class SettingsScreen extends StatelessWidget {
+class SettingsScreen extends StatefulWidget {
const SettingsScreen({super.key});
+ @override
+ State<SettingsScreen> createState() => _SettingsScreenState();
+}
+
+class _SettingsScreenState extends State<SettingsScreen> {
+ bool _groupByType = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _loadPreferences();
+ }
+
+ Future<void> _loadPreferences() async {
+ final value = await PreferencesService.instance.getGroupByType();
+ if (mounted) {
+ setState(() {
+ _groupByType = value;
+ });
+ }
+ }
+
Future<void> _handleClearLocalData(BuildContext context) async {
final confirmed = await showDialog<bool>(
context: context,
@@ -165,6 +188,34 @@ class SettingsScreen extends StatelessWidget {
const Divider(),
+ // Display Settings Section
+ const Padding(
+ padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
+ child: Text(
+ 'Display',
+ style: TextStyle(
+ fontSize: 14,
+ fontWeight: FontWeight.bold,
+ color: Colors.grey,
+ ),
+ ),
+ ),
+
+ SwitchListTile(
+ secondary: const Icon(Icons.view_list),
+ title: const Text('Group by Account Type'),
+ subtitle: const Text('Group accounts by type (Crypto, Bank, etc.)'),
+ value: _groupByType,
+ onChanged: (value) async {
+ await PreferencesService.instance.setGroupByType(value);
+ setState(() {
+ _groupByType = value;
+ });
+ },
+ ),
+
+ const Divider(),
+
// Data Management Section
const Padding(
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
diff --git a/mobile/lib/services/preferences_service.dart b/mobile/lib/services/preferences_service.dart
new file mode 100644
index 0000000000..15558385e7
--- /dev/null
+++ b/mobile/lib/services/preferences_service.dart
@@ -0,0 +1,30 @@
+import 'package:shared_preferences/shared_preferences.dart';
+
+class PreferencesService {
+ static const _groupByTypeKey = 'dashboard_group_by_type';
+
+ static PreferencesService? _instance;
+ SharedPreferences? _prefs;
+
+ PreferencesService._();
+
+ static PreferencesService get instance {
+ _instance ??= PreferencesService._();
+ return _instance!;
+ }
+
+ Future<SharedPreferences> get _preferences async {
+ _prefs ??= await SharedPreferences.getInstance();
+ return _prefs!;
+ }
+
+ Future<bool> getGroupByType() async {
+ final prefs = await _preferences;
+ return prefs.getBool(_groupByTypeKey) ?? false;
+ }
+
+ Future<void> setGroupByType(bool value) async {
+ final prefs = await _preferences;
+ await prefs.setBool(_groupByTypeKey, value);
+ }
+}
diff --git a/mobile/lib/widgets/connectivity_banner.dart b/mobile/lib/widgets/connectivity_banner.dart
index ece413fd88..eb8fb01f1c 100644
--- a/mobile/lib/widgets/connectivity_banner.dart
+++ b/mobile/lib/widgets/connectivity_banner.dart
@@ -23,13 +23,14 @@ class _ConnectivityBannerState extends State<ConnectivityBanner> {
backgroundColor: Colors.orange,
),
);
+ if (mounted) {
+ setState(() {
+ _isSyncing = false;
+ });
+ }
return;
}
- setState(() {
- _isSyncing = true;
- });
-
try {
await transactionsProvider.syncTransactions(accessToken: accessToken);
@@ -101,11 +102,37 @@ class _ConnectivityBannerState extends State<ConnectivityBanner> {
return TextButton(
onPressed: _isSyncing
? null
- : () => _handleSync(
+ : () async {
+ setState(() {
+ _isSyncing = true;
+ });
+
+ String? accessToken;
+ try {
+ accessToken = await authProvider.getValidAccessToken();
+ } catch (e) {
+ if (!context.mounted) return;
+ ScaffoldMessenger.of(context).showSnackBar(
+ const SnackBar(
+ content: Text('Unable to authenticate. Please try again.'),
+ backgroundColor: Colors.red,
+ ),
+ );
+ if (mounted) {
+ setState(() {
+ _isSyncing = false;
+ });
+ }
+ return;
+ }
+
+ if (!context.mounted) return;
+ await _handleSync(
context,
- authProvider.tokens?.accessToken,
+ accessToken,
transactionsProvider,
- ),
+ );
+ },
style: TextButton.styleFrom(
foregroundColor: Colors.blue.shade900,
),
diff --git a/mobile/lib/widgets/currency_filter.dart b/mobile/lib/widgets/currency_filter.dart
new file mode 100644
index 0000000000..ad2e86b47d
--- /dev/null
+++ b/mobile/lib/widgets/currency_filter.dart
@@ -0,0 +1,134 @@
+import 'package:flutter/material.dart';
+
+class CurrencyFilter extends StatelessWidget {
+ final Set<String> availableCurrencies;
+ final Set<String> selectedCurrencies;
+ final ValueChanged<Set<String>> onSelectionChanged;
+
+ const CurrencyFilter({
+ super.key,
+ required this.availableCurrencies,
+ required this.selectedCurrencies,
+ required this.onSelectionChanged,
+ });
+
+ String _getCurrencySymbol(String currency) {
+ switch (currency.toUpperCase()) {
+ case 'USD':
+ return '\$';
+ case 'TWD':
+ return 'NT\$';
+ case 'BTC':
+ return '₿';
+ case 'ETH':
+ return 'Ξ';
+ case 'EUR':
+ return '€';
+ case 'GBP':
+ return '£';
+ case 'JPY':
+ return '¥';
+ case 'CNY':
+ return '¥';
+ default:
+ return '';
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ if (availableCurrencies.length <= 1) {
+ return const SizedBox.shrink();
+ }
+
+ final sortedCurrencies = availableCurrencies.toList()..sort();
+ final colorScheme = Theme.of(context).colorScheme;
+ final isAllSelected = selectedCurrencies.isEmpty ||
+ selectedCurrencies.length == availableCurrencies.length;
+
+ return Container(
+ height: 44,
+ margin: const EdgeInsets.symmetric(horizontal: 16),
+ child: ListView(
+ scrollDirection: Axis.horizontal,
+ children: [
+ // "All" chip
+ Padding(
+ padding: const EdgeInsets.only(right: 8),
+ child: FilterChip(
+ label: const Text('All'),
+ selected: isAllSelected,
+ onSelected: (_) {
+ onSelectionChanged({});
+ },
+ backgroundColor: colorScheme.surfaceContainerHighest,
+ selectedColor: colorScheme.primaryContainer,
+ checkmarkColor: colorScheme.onPrimaryContainer,
+ labelStyle: TextStyle(
+ color: isAllSelected
+ ? colorScheme.onPrimaryContainer
+ : colorScheme.onSurfaceVariant,
+ fontWeight: isAllSelected ? FontWeight.bold : FontWeight.normal,
+ ),
+ side: BorderSide(
+ color: isAllSelected
+ ? colorScheme.primary
+ : colorScheme.outline.withValues(alpha: 0.3),
+ ),
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ ),
+ ),
+
+ // Currency chips
+ ...sortedCurrencies.map((currency) {
+ final isSelected =
+ selectedCurrencies.contains(currency) && !isAllSelected;
+ final symbol = _getCurrencySymbol(currency);
+ final displayText = symbol.isNotEmpty ? '$currency ($symbol)' : currency;
+
+ return Padding(
+ padding: const EdgeInsets.only(right: 8),
+ child: FilterChip(
+ label: Text(displayText),
+ selected: isSelected,
+ onSelected: (_) {
+ final newSelection = Set<String>.from(selectedCurrencies);
+ if (isSelected) {
+ newSelection.remove(currency);
+ } else {
+ // If currently showing all, start fresh with just this one
+ if (isAllSelected) {
+ newSelection.clear();
+ }
+ newSelection.add(currency);
+ }
+ // If all currencies selected, treat as "All"
+ if (newSelection.length == availableCurrencies.length) {
+ onSelectionChanged({});
+ } else {
+ onSelectionChanged(newSelection);
+ }
+ },
+ backgroundColor: colorScheme.surfaceContainerHighest,
+ selectedColor: colorScheme.primaryContainer,
+ checkmarkColor: colorScheme.onPrimaryContainer,
+ labelStyle: TextStyle(
+ color: isSelected
+ ? colorScheme.onPrimaryContainer
+ : colorScheme.onSurfaceVariant,
+ fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
+ ),
+ side: BorderSide(
+ color: isSelected
+ ? colorScheme.primary
+ : colorScheme.outline.withValues(alpha: 0.3),
+ ),
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ ),
+ );
+ }),
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/widgets/net_worth_card.dart b/mobile/lib/widgets/net_worth_card.dart
new file mode 100644
index 0000000000..0d1c8ccda9
--- /dev/null
+++ b/mobile/lib/widgets/net_worth_card.dart
@@ -0,0 +1,315 @@
+import 'package:flutter/material.dart';
+
+enum AccountFilter { all, assets, liabilities }
+
+class NetWorthCard extends StatelessWidget {
+ final Map<String, double> assetTotalsByCurrency;
+ final Map<String, double> liabilityTotalsByCurrency;
+ final AccountFilter currentFilter;
+ final ValueChanged<AccountFilter> onFilterChanged;
+ final String Function(String currency, double amount) formatAmount;
+
+ const NetWorthCard({
+ super.key,
+ required this.assetTotalsByCurrency,
+ required this.liabilityTotalsByCurrency,
+ required this.currentFilter,
+ required this.onFilterChanged,
+ required this.formatAmount,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+
+ return Container(
+ margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ decoration: BoxDecoration(
+ color: colorScheme.surfaceContainerHighest.withValues(alpha: 0.5),
+ borderRadius: BorderRadius.circular(16),
+ border: Border.all(
+ color: colorScheme.outline.withValues(alpha: 0.2),
+ ),
+ ),
+ child: Column(
+ children: [
+ // Net Worth Section (Placeholder)
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 14, 16, 12),
+ child: Column(
+ children: [
+ Text(
+ 'Net Worth',
+ style: Theme.of(context).textTheme.labelMedium?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ ),
+ ),
+ const SizedBox(height: 2),
+ Text(
+ '--',
+ style: Theme.of(context).textTheme.headlineSmall?.copyWith(
+ fontWeight: FontWeight.bold,
+ color: colorScheme.onSurface,
+ ),
+ ),
+ ],
+ ),
+ ),
+
+ // Divider
+ Divider(
+ height: 1,
+ color: colorScheme.outline.withValues(alpha: 0.2),
+ ),
+
+ // Assets & Liabilities Row
+ IntrinsicHeight(
+ child: Row(
+ children: [
+ // Assets
+ Expanded(
+ child: _FilterButton(
+ totals: assetTotalsByCurrency,
+ color: Colors.green,
+ isSelected: currentFilter == AccountFilter.assets,
+ onTap: () {
+ if (currentFilter == AccountFilter.assets) {
+ onFilterChanged(AccountFilter.all);
+ } else {
+ onFilterChanged(AccountFilter.assets);
+ }
+ },
+ onLongPress: () => _showCurrencyBreakdown(
+ context,
+ 'Assets',
+ assetTotalsByCurrency,
+ Colors.green,
+ ),
+ formatAmount: formatAmount,
+ ),
+ ),
+
+ // Vertical Divider
+ VerticalDivider(
+ width: 1,
+ color: colorScheme.outline.withValues(alpha: 0.2),
+ ),
+
+ // Liabilities
+ Expanded(
+ child: _FilterButton(
+ totals: liabilityTotalsByCurrency,
+ color: Colors.red,
+ isSelected: currentFilter == AccountFilter.liabilities,
+ onTap: () {
+ if (currentFilter == AccountFilter.liabilities) {
+ onFilterChanged(AccountFilter.all);
+ } else {
+ onFilterChanged(AccountFilter.liabilities);
+ }
+ },
+ onLongPress: () => _showCurrencyBreakdown(
+ context,
+ 'Liabilities',
+ liabilityTotalsByCurrency,
+ Colors.red,
+ ),
+ formatAmount: formatAmount,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ void _showCurrencyBreakdown(
+ BuildContext context,
+ String title,
+ Map<String, double> totals,
+ Color color,
+ ) {
+ final sortedEntries = totals.entries.toList()
+ ..sort((a, b) => b.value.abs().compareTo(a.value.abs()));
+
+ if (sortedEntries.isEmpty) return;
+
+ showModalBottomSheet(
+ context: context,
+ isScrollControlled: true,
+ useSafeArea: true,
+ shape: const RoundedRectangleBorder(
+ borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
+ ),
+ builder: (context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ return Padding(
+ padding: const EdgeInsets.fromLTRB(24, 16, 24, 32),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // Handle bar
+ Container(
+ width: 40,
+ height: 4,
+ decoration: BoxDecoration(
+ color: colorScheme.onSurfaceVariant.withValues(alpha: 0.3),
+ borderRadius: BorderRadius.circular(2),
+ ),
+ ),
+ const SizedBox(height: 20),
+
+ // Title with icon
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ Icon(
+ title == 'Assets' ? Icons.trending_up : Icons.trending_down,
+ color: color,
+ size: 20,
+ ),
+ const SizedBox(width: 8),
+ Text(
+ title,
+ style: Theme.of(context).textTheme.titleLarge?.copyWith(
+ fontWeight: FontWeight.bold,
+ color: color,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 20),
+
+ // Currency list (scrollable when many entries)
+ ConstrainedBox(
+ constraints: BoxConstraints(
+ maxHeight: MediaQuery.sizeOf(context).height * 0.5,
+ ),
+ child: ListView.separated(
+ shrinkWrap: true,
+ itemCount: sortedEntries.length,
+ separatorBuilder: (_, __) => const SizedBox(height: 8),
+ itemBuilder: (context, index) {
+ final entry = sortedEntries[index];
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ entry.key,
+ style: Theme.of(context).textTheme.titleMedium?.copyWith(
+ fontWeight: FontWeight.w500,
+ color: colorScheme.onSurfaceVariant,
+ ),
+ ),
+ Text(
+ formatAmount(entry.key, entry.value),
+ style: Theme.of(context).textTheme.titleMedium?.copyWith(
+ fontWeight: FontWeight.bold,
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ );
+ }
+}
+
+class _FilterButton extends StatelessWidget {
+ final Map<String, double> totals;
+ final Color color;
+ final bool isSelected;
+ final VoidCallback onTap;
+ final VoidCallback onLongPress;
+ final String Function(String currency, double amount) formatAmount;
+
+ const _FilterButton({
+ required this.totals,
+ required this.color,
+ required this.isSelected,
+ required this.onTap,
+ required this.onLongPress,
+ required this.formatAmount,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+
+ final sortedEntries = totals.entries.toList()
+ ..sort((a, b) => b.value.abs().compareTo(a.value.abs()));
+
+ return Container(
+ decoration: BoxDecoration(
+ border: Border(
+ bottom: BorderSide(
+ color: color.withValues(alpha: 0.6),
+ width: 3,
+ ),
+ ),
+ ),
+ child: Material(
+ color: isSelected ? color.withValues(alpha: 0.1) : Colors.transparent,
+ child: GestureDetector(
+ onTap: onTap,
+ onLongPress: sortedEntries.isNotEmpty ? onLongPress : null,
+ behavior: HitTestBehavior.opaque,
+ child: SizedBox(
+ height: 48,
+ child: sortedEntries.isEmpty
+ ? Center(
+ child: Text(
+ '--',
+ style: Theme.of(context).textTheme.titleLarge?.copyWith(
+ fontWeight: FontWeight.bold,
+ color: colorScheme.onSurface,
+ ),
+ ),
+ )
+ : sortedEntries.length == 1
+ ? Center(
+ child: Text(
+ formatAmount(sortedEntries.first.key, sortedEntries.first.value),
+ style: Theme.of(context).textTheme.titleMedium?.copyWith(
+ fontWeight: FontWeight.bold,
+ color: colorScheme.onSurface,
+ ),
+ ),
+ )
+ : NotificationListener<ScrollNotification>(
+ onNotification: (_) => true,
+ child: ListWheelScrollView.useDelegate(
+ itemExtent: 32,
+ diameterRatio: 1.5,
+ perspective: 0.003,
+ physics: const FixedExtentScrollPhysics(),
+ childDelegate: ListWheelChildBuilderDelegate(
+ childCount: sortedEntries.length,
+ builder: (context, index) {
+ final entry = sortedEntries[index];
+ return Center(
+ child: Text(
+ formatAmount(entry.key, entry.value),
+ style: Theme.of(context).textTheme.titleMedium?.copyWith(
+ fontWeight: FontWeight.bold,
+ color: colorScheme.onSurface,
+ ),
+ ),
+ );
+ },
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}