fix: code-review findings — error handling, null safety, persist settings, auth header
This commit is contained in:
@@ -43,7 +43,10 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
Future<void> _verbindeCloud() async {
|
||||
final user = AuthService().benutzer;
|
||||
if (user.isNotEmpty) {
|
||||
await widget.cloud.login(user);
|
||||
final ok = await widget.cloud.login(user);
|
||||
if (!ok && mounted) {
|
||||
setState(() => _setzeStatus('Cloud-Login fehlgeschlagen', ok: false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +94,7 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
Future<void> _upload() async {
|
||||
setState(() => _ladt = true);
|
||||
_setzeStatus('Suche lokale Songs...');
|
||||
try {
|
||||
final dir = Directory('${(await getApplicationDocumentsDirectory()).path}/music');
|
||||
if (!await dir.exists()) {
|
||||
setState(() { _ladt = false; _setzeStatus('Keine lokalen Songs', ok: false); });
|
||||
@@ -110,11 +114,16 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
_setzeStatus('$count Songs hochgeladen', ok: count > 0);
|
||||
MeloLogger().aktion('cloud_upload', {'count': count});
|
||||
}
|
||||
} catch (e) {
|
||||
MeloLogger().fehler('cloud_upload_path', e);
|
||||
if (mounted) setState(() { _ladt = false; _setzeStatus('Fehler beim Upload', ok: false); });
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _download() async {
|
||||
setState(() => _ladt = true);
|
||||
setState(() { _ladt = true; });
|
||||
_setzeStatus('Vergleiche mit Server...');
|
||||
try {
|
||||
final dir = Directory('${(await getApplicationDocumentsDirectory()).path}/music');
|
||||
if (!await dir.exists()) await dir.create(recursive: true);
|
||||
final localFiles = dir.listSync().whereType<File>()
|
||||
@@ -122,7 +131,7 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
final serverSongs = await widget.cloud.listSongs();
|
||||
int downloaded = 0;
|
||||
for (final song in serverSongs) {
|
||||
final title = song['title'].toString();
|
||||
final title = (song['title'] ?? 'unknown').toString();
|
||||
if (localFiles.contains(title)) continue;
|
||||
_setzeStatus('Download: $title...');
|
||||
final sid = song['id'].toString();
|
||||
@@ -135,6 +144,10 @@ class _CloudScreenState extends State<CloudScreen> {
|
||||
_setzeStatus('$downloaded Songs heruntergeladen', ok: true);
|
||||
MeloLogger().aktion('cloud_download', {'count': downloaded});
|
||||
}
|
||||
} catch (e) {
|
||||
MeloLogger().fehler('cloud_download_path', e);
|
||||
if (mounted) setState(() { _ladt = false; _setzeStatus('Fehler beim Download', ok: false); });
|
||||
}
|
||||
}
|
||||
|
||||
void _setzeStatus(String msg, {bool ok = false}) {
|
||||
|
||||
Reference in New Issue
Block a user