42 lines
1.4 KiB
Dart
42 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../../../model/account_data.dart';
|
|
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
|
import '../../../../widget/centered_leading.dart';
|
|
import '../../../../widget/confirm_dialog.dart';
|
|
import '../../../../widget/debug/cache_view.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),
|
|
);
|
|
|
|
void _showLogoutDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => ConfirmDialog(
|
|
title: 'Abmelden?',
|
|
content: 'Möchtest du dich wirklich abmelden?',
|
|
confirmButton: 'Abmelden',
|
|
onConfirm: () async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.clear();
|
|
PaintingBinding.instance.imageCache.clear();
|
|
if (!context.mounted) return;
|
|
context.read<SettingsCubit>().reset();
|
|
const CacheView().clear();
|
|
AccountData().removeData(context: context);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|