fix login

This commit is contained in:
davmar
2026-09-10 10:51:45 +02:00
parent 79e4417edb
commit 56cc0fc94c
6 changed files with 269 additions and 182 deletions
+181 -140
View File
@@ -46,119 +46,92 @@ class _SyncAwareAccountMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: context.read<SyncController>(),
builder: (context, _) {
final sync = context.read<SyncController>();
final showRing = sync.showProgressRing;
final progress = sync.syncProgress;
final success = sync.progressSuccess;
final syncActive = sync.isSyncing || showRing;
final ringColor = success
? const Color(0xFF16A34A)
: Theme.of(context).colorScheme.primary;
final colors = Theme.of(context).colorScheme;
return PopupMenuButton<_AccountMenuAction>(
tooltip: sync.isSyncing
? 'Syncing… ${(progress * 100).round()}%'
: auth.displayName,
offset: const Offset(0, 48),
onSelected: (action) async {
switch (action) {
case _AccountMenuAction.account:
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const AccountScreen(),
),
);
case _AccountMenuAction.logout:
await auth.logout();
}
// MenuAnchor (not PopupMenuButton): no modal black barrier, and the menu
// stays anchored under this trailing control instead of jumping left.
return MenuAnchor(
consumeOutsideTap: true,
alignmentOffset: const Offset(0, 4),
style: MenuStyle(
alignment: AlignmentDirectional.bottomEnd,
backgroundColor: WidgetStatePropertyAll(colors.surfaceContainerHigh),
surfaceTintColor: const WidgetStatePropertyAll(Colors.transparent),
elevation: const WidgetStatePropertyAll(6),
shadowColor: const WidgetStatePropertyAll(Colors.black38),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(vertical: 8),
),
),
builder: (context, controller, child) {
return ListenableBuilder(
listenable: context.read<SyncController>(),
builder: (context, _) {
final sync = context.read<SyncController>();
final tooltip = sync.isSyncing
? 'Syncing… ${(sync.syncProgress * 100).round()}%'
: auth.displayName;
return IconButton(
tooltip: tooltip,
onPressed: () {
if (controller.isOpen) {
controller.close();
} else {
controller.open();
}
},
icon: child ?? const SizedBox.shrink(),
);
},
itemBuilder: (context) {
final email = auth.email;
final showSyncRow = syncActive;
return [
if (email != null)
PopupMenuItem<_AccountMenuAction>(
enabled: false,
child: Text(
email,
style: Theme.of(context).textTheme.bodySmall,
),
),
if (showSyncRow)
const PopupMenuItem<_AccountMenuAction>(
enabled: false,
child: _SyncProgressMenuTile(),
),
const PopupMenuItem<_AccountMenuAction>(
value: _AccountMenuAction.account,
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.person_outline),
title: Text('Account'),
),
),
const PopupMenuItem<_AccountMenuAction>(
value: _AccountMenuAction.logout,
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.logout),
title: Text('Sign out'),
),
),
];
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: SizedBox(
width: 32,
height: 32,
child: Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
radius: 16,
backgroundColor:
Theme.of(context).colorScheme.primaryContainer,
child: Text(
auth.initials,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
),
),
),
if (showRing)
SizedBox(
width: 32,
height: 32,
child: CircularProgressIndicator(
value:
progress <= 0 ? null : progress.clamp(0.02, 1.0),
strokeWidth: 2.5,
color: ringColor,
backgroundColor: Theme.of(context)
.colorScheme
.outlineVariant
.withValues(alpha: 0.45),
),
),
],
),
),
),
);
},
menuChildren: [
if (auth.email case final email?)
Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 8),
child: Text(
email,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: colors.onSurfaceVariant,
),
),
),
const _SyncProgressMenuEntry(),
MenuItemButton(
leadingIcon: const Icon(Icons.person_outline),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const AccountScreen(),
),
);
},
child: const Text('Account'),
),
MenuItemButton(
leadingIcon: const Icon(Icons.logout),
onPressed: () async {
await auth.logout();
if (!context.mounted) return;
Navigator.of(context).popUntil((route) => route.isFirst);
},
child: const Text('Sign out'),
),
],
child: _AccountAvatar(auth: auth),
);
}
}
/// Live sync status row inside the account popup (watches [SyncController]).
class _SyncProgressMenuTile extends StatelessWidget {
const _SyncProgressMenuTile();
/// Avatar + optional sync ring; watches sync without rebuilding the menu shell.
class _AccountAvatar extends StatelessWidget {
const _AccountAvatar({required this.auth});
final AuthController auth;
@override
Widget build(BuildContext context) {
@@ -166,50 +139,118 @@ class _SyncProgressMenuTile extends StatelessWidget {
listenable: context.read<SyncController>(),
builder: (context, _) {
final sync = context.read<SyncController>();
final theme = Theme.of(context);
final colors = theme.colorScheme;
final pct = (sync.syncProgress * 100).round().clamp(0, 100);
final detail = sync.statusDetail.trim();
final showRing = sync.showProgressRing;
final progress = sync.syncProgress;
final success = sync.progressSuccess;
final ringColor = success
? const Color(0xFF16A34A)
: Theme.of(context).colorScheme.primary;
if (sync.progressSuccess) {
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.check_circle_outline, color: colors.primary),
title: Text(
'Sync complete',
style: theme.textTheme.bodyMedium?.copyWith(
color: colors.onSurface,
return SizedBox(
width: 32,
height: 32,
child: Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
radius: 14,
backgroundColor:
Theme.of(context).colorScheme.primaryContainer,
child: Text(
auth.initials,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
),
),
),
),
);
}
return ListTile(
contentPadding: EdgeInsets.zero,
leading: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
value: sync.syncProgress <= 0
? null
: sync.syncProgress.clamp(0.02, 1.0),
strokeWidth: 2.5,
),
if (showRing)
SizedBox(
width: 32,
height: 32,
child: CircularProgressIndicator(
value: progress <= 0 ? null : progress.clamp(0.02, 1.0),
strokeWidth: 2.5,
color: ringColor,
backgroundColor: Theme.of(context)
.colorScheme
.outlineVariant
.withValues(alpha: 0.45),
),
),
],
),
title: Text(
detail.isEmpty ? 'Sync in progress ($pct%)' : detail,
style: theme.textTheme.bodyMedium?.copyWith(
color: colors.onSurface,
),
),
subtitle: detail.isEmpty ? null : Text('Sync in progress ($pct%)'),
);
},
);
}
}
enum _AccountMenuAction { account, logout }
/// Sync row shown only while a sync is active / finishing.
class _SyncProgressMenuEntry extends StatelessWidget {
const _SyncProgressMenuEntry();
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: context.read<SyncController>(),
builder: (context, _) {
final sync = context.read<SyncController>();
if (!sync.isSyncing && !sync.showProgressRing) {
return const SizedBox.shrink();
}
final theme = Theme.of(context);
final colors = theme.colorScheme;
final pct = (sync.syncProgress * 100).round().clamp(0, 100);
final detail = sync.statusDetail.trim();
if (sync.progressSuccess) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
Icon(
Icons.check_circle_outline,
color: colors.primary,
size: 20,
),
const SizedBox(width: 12),
Text('Sync complete', style: theme.textTheme.bodyMedium),
],
),
);
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
value: sync.syncProgress <= 0
? null
: sync.syncProgress.clamp(0.02, 1.0),
strokeWidth: 2.5,
),
),
const SizedBox(width: 12),
Expanded(
child: Text(
detail.isEmpty ? 'Sync in progress ($pct%)' : detail,
style: theme.textTheme.bodyMedium,
),
),
],
),
);
},
);
}
}
List<Widget> bankAppBarActions({
required BuildContext context,