Feature: Jederzeit von 'nur lokal' auf Cloud wechseln + Abmelden-Fix

- Profil-Dialog: 'Cloud aktivieren' erscheint im Lokal-Modus -> setzt Modus + Login
- Abmelden loescht jetzt wirklich das Token (CloudService.logout)
- _zeigeProfil liest Modus vor dem Dialog
This commit is contained in:
Hermes (Server)
2026-07-31 15:37:00 +02:00
parent f9b6e57606
commit 519bdd4e23
+26 -4
View File
@@ -103,7 +103,10 @@ class _MeloHomeState extends State<MeloHome> {
}
}
void _zeigeProfil() {
Future<void> _zeigeProfil() async {
final p = await SharedPreferences.getInstance();
final modus = p.getString('melo_modus') ?? 'cloud';
if (!mounted) return;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
@@ -119,6 +122,23 @@ class _MeloHomeState extends State<MeloHome> {
_profilZeile(Icons.music_note, 'Lieder auf Gerät', '${_vm.songs.length}'),
_profilZeile(Icons.cloud, 'Cloud-Server', '${_cloud.status().then((s) => s?['total'] ?? 0)}'),
const Divider(color: MeloTheme.dunkel2),
// Später von "nur lokal" auf Cloud wechseln jederzeit möglich
if (modus == 'lokal') ...[
ListTile(
leading: const Icon(Icons.cloud_upload, color: Colors.blueAccent, size: 18),
title: const Text('☁️ Cloud aktivieren',
style: TextStyle(color: Colors.white, fontSize: 13)),
subtitle: const Text('Musik sichern & geräteübergreifend nutzen',
style: TextStyle(color: Colors.grey, fontSize: 11)),
onTap: () async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('melo_modus', 'cloud');
if (ctx.mounted) Navigator.pop(ctx);
_nutzerWechseln();
},
),
const Divider(color: MeloTheme.dunkel2),
],
ListTile(
leading: const Icon(Icons.swap_horiz, color: Colors.grey, size: 18),
title: const Text('Nutzer wechseln', style: TextStyle(color: Colors.white, fontSize: 13)),
@@ -131,10 +151,12 @@ class _MeloHomeState extends State<MeloHome> {
leading: const Icon(Icons.logout, color: Colors.red, size: 18),
title: const Text('Abmelden', style: TextStyle(color: Colors.red, fontSize: 13)),
onTap: () async {
final p = await SharedPreferences.getInstance();
await p.remove('melo_nutzer');
// Token wirklich löschen, sonst wäre man gar nicht abgemeldet
await CloudService().logout();
final prefs = await SharedPreferences.getInstance();
await prefs.remove('melo_nutzer');
if (ctx.mounted) Navigator.pop(ctx);
setState(() => _nutzer = '');
if (mounted) setState(() => _nutzer = '');
},
),
],