look ahead
This commit is contained in:
@@ -17,23 +17,11 @@ class AccountScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = context.watch<AuthController>();
|
||||
final sync = context.watch<SyncController>();
|
||||
final meta = context.watch<TxMetaController>();
|
||||
final bank = context.watch<BankController>();
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
|
||||
final lastSync = sync.lastSyncedAt;
|
||||
final syncSubtitle = sync.isSyncing
|
||||
? (sync.statusDetail.isEmpty
|
||||
? 'Syncing… ${(sync.syncProgress * 100).round()}%'
|
||||
: '${sync.statusDetail} · ${(sync.syncProgress * 100).round()}%')
|
||||
: sync.lastError != null
|
||||
? 'Last error: ${sync.lastError}'
|
||||
: lastSync == null
|
||||
? 'Not synced yet'
|
||||
: 'Last sync ${_formatTime(lastSync)}';
|
||||
|
||||
final categorized = meta.labeledTransactionCount(bank.transactions);
|
||||
final perTxAnnotations = meta.syncableAnnotationCount;
|
||||
final viaMerchantOnly = meta.merchantOnlyLabeledCount(bank.transactions);
|
||||
@@ -83,41 +71,7 @@ class AccountScreen extends StatelessWidget {
|
||||
subtitle: Text(kPocketBaseUrl),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: sync.isSyncing
|
||||
? SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
value: sync.syncProgress <= 0
|
||||
? null
|
||||
: sync.syncProgress.clamp(0.02, 1.0),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
sync.lastError == null
|
||||
? Icons.sync
|
||||
: Icons.sync_problem_outlined,
|
||||
),
|
||||
title: const Text('Cloud sync'),
|
||||
subtitle: Text(syncSubtitle),
|
||||
trailing: TextButton(
|
||||
onPressed: sync.isSyncing ? null : () => sync.syncNow(),
|
||||
child: const Text('Sync now'),
|
||||
),
|
||||
),
|
||||
if (sync.lastSyncSummary.isNotEmpty) ...[
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.fact_check_outlined),
|
||||
title: const Text('Last sync detail'),
|
||||
subtitle: Text(sync.lastSyncSummary),
|
||||
),
|
||||
],
|
||||
const _CloudSyncTile(),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.phone_android_outlined),
|
||||
@@ -150,6 +104,72 @@ class AccountScreen extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Isolated so sync progress ticks do not rebuild account stats.
|
||||
class _CloudSyncTile extends StatelessWidget {
|
||||
const _CloudSyncTile();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenableBuilder(
|
||||
listenable: context.read<SyncController>(),
|
||||
builder: (context, _) {
|
||||
final sync = context.read<SyncController>();
|
||||
final lastSync = sync.lastSyncedAt;
|
||||
final syncSubtitle = sync.isSyncing
|
||||
? (sync.statusDetail.isEmpty
|
||||
? 'Syncing… ${(sync.syncProgress * 100).round()}%'
|
||||
: '${sync.statusDetail} · ${(sync.syncProgress * 100).round()}%')
|
||||
: sync.lastError != null
|
||||
? 'Last error: ${sync.lastError}'
|
||||
: lastSync == null
|
||||
? 'Not synced yet'
|
||||
: 'Last sync ${_formatTime(lastSync)}';
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: sync.isSyncing
|
||||
? SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
value: sync.syncProgress <= 0
|
||||
? null
|
||||
: sync.syncProgress.clamp(0.02, 1.0),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
sync.lastError == null
|
||||
? Icons.sync
|
||||
: Icons.sync_problem_outlined,
|
||||
),
|
||||
title: const Text('Cloud sync'),
|
||||
subtitle: Text(syncSubtitle),
|
||||
trailing: TextButton(
|
||||
onPressed: sync.isSyncing ? null : () => sync.syncNow(),
|
||||
child: const Text('Sync now'),
|
||||
),
|
||||
),
|
||||
if (sync.lastSyncSummary.isNotEmpty) ...[
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.fact_check_outlined),
|
||||
title: const Text('Last sync detail'),
|
||||
subtitle: Text(sync.lastSyncSummary),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static String _formatTime(DateTime time) {
|
||||
final local = time.toLocal();
|
||||
|
||||
Reference in New Issue
Block a user