Phase B+1: Bootstrap-Splash + Logout im Drawer

- AuthBootstrapping als neuer Initial-State im AuthBloc. Beim Cold-Start
  bleibt die App im Splash, bis restoreSession entweder Authenticated
  oder Unauthenticated emittiert — kein sichtbarer LoginPage-Flash mehr
  für Nutzer mit gespeicherter Session.
- LoginEnforcer rendert für AuthBootstrapping ein eigenes Splash-Widget
  mit Logo + Spinner, für Unauthenticated weiterhin die LoginPage.
- AuthBloc._handleRestore emittiert Unauthenticated explizit, wenn
  restoreSession false liefert oder wirft — sonst bliebe der Bootstrap-
  State hängen.
- HomeAppDrawer zeigt jetzt displayName + Personalnummer aus dem
  Authenticated-State im Header und bekommt einen Abmelden-Eintrag
  unten (rot, Confirm-Dialog), der LogoutRequested feuert. Der
  Provider löscht den Refresh-Token aus der Secure Storage und der
  LoginEnforcer routet automatisch zurück auf die LoginPage.
This commit is contained in:
Dennis Nemec
2026-05-15 11:21:57 +02:00
parent cb22fff407
commit f074d53f3d
4 changed files with 116 additions and 12 deletions

View File

@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_event.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
import 'package:hl_lieferservice/feature/car_selection/bloc/bloc.dart';
import 'package:hl_lieferservice/feature/car_selection/bloc/events.dart';
import 'package:hl_lieferservice/feature/car_selection/bloc/state.dart';
@ -22,10 +25,46 @@ class HomeAppDrawer extends StatelessWidget {
);
}
Future<void> _confirmLogout(BuildContext context) async {
final authBloc = context.read<AuthBloc>();
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) => AlertDialog(
title: const Text("Abmelden"),
content: const Text(
"Möchten Sie sich wirklich abmelden? "
"Beim nächsten Start ist eine erneute Anmeldung erforderlich.",
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text("Abbrechen"),
),
FilledButton(
style: FilledButton.styleFrom(backgroundColor: Colors.red),
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text("Abmelden"),
),
],
),
);
if (confirmed != true) return;
authBloc.add(const LogoutRequested());
// Drawer schließen, falls noch sichtbar — der State-Wechsel auf
// Unauthenticated leitet danach von selbst auf die LoginPage.
if (context.mounted && Scaffold.maybeOf(context)?.isDrawerOpen == true) {
Navigator.of(context).pop();
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final carState = context.watch<CarSelectBloc>().state;
final authState = context.watch<AuthBloc>().state;
final authenticated = authState is Authenticated ? authState : null;
return Drawer(
child: SafeArea(
@ -40,14 +79,26 @@ class HomeAppDrawer extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
"Holzleitner",
authenticated?.displayName ?? "Holzleitner",
style: TextStyle(
color: theme.colorScheme.onSecondary,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
if (authenticated != null) ...[
const SizedBox(height: 2),
Text(
"Personalnummer ${authenticated.personalnummer}",
style: TextStyle(
color: theme.colorScheme.onSecondary.withValues(
alpha: 0.85,
),
fontSize: 12,
),
),
],
const SizedBox(height: 8),
if (carState is CarSelectComplete)
Row(
children: [
@ -100,8 +151,16 @@ class HomeAppDrawer extends StatelessWidget {
),
const Spacer(),
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.logout, color: Colors.red),
title: const Text(
"Abmelden",
style: TextStyle(color: Colors.red),
),
onTap: () => _confirmLogout(context),
),
const Padding(
padding: EdgeInsets.all(12),
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Text(
"Lieferservice-App",
style: TextStyle(fontSize: 11, color: Colors.grey),