import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../model/account_data.dart'; import '../../../../state/app/modules/account/bloc/account_bloc.dart'; import '../../../../state/app/modules/account/bloc/account_state.dart'; import '../../../../widget/centered_leading.dart'; import '../../../../widget/confirm_dialog.dart'; class AccountSection extends StatelessWidget { const AccountSection({super.key}); @override Widget build(BuildContext context) => ListTile( leading: const CenteredLeading(Icon(Icons.logout_outlined)), title: const Text('Konto abmelden'), subtitle: Text('Angemeldet als ${AccountData().getUsername()}'), onTap: () => _showLogoutDialog(context), ); Future _showLogoutDialog(BuildContext context) async { // Sequential logout flow: dialog wipes secure storage, dialog closes // (single Navigator.pop), then we flip the AccountBloc state. The bloc // listener in main.dart pops the Settings route and runs the in-memory // wipe. Triggering setStatus from inside removeData (the previous // approach) raced AsyncDialogAction's pop(true) against popUntil(isFirst) // and could leave the navigator in an inconsistent state. final confirmed = await showDialog( context: context, builder: (dialogContext) => ConfirmDialog( title: 'Abmelden?', content: 'Möchtest du dich wirklich abmelden?', confirmButton: 'Abmelden', onConfirmAsync: AccountData().removeData, ), ); if (confirmed != true || !context.mounted) return; context.read().setStatus(AccountStatus.loggedOut); } }