v2.41 — Issue #3: Musik-Download im Hintergrund (flutter_background_service)

- flutter_background_service ^5.0.0 hinzugefügt
- AndroidManifest: FOREGROUND_SERVICE_DATA_SYNC Permission
- main.dart: Background Service mit configure() initialisiert
- _onServiceStart(): Service-Callback für Foreground-Garantie
- DownloadService._startBackgroundService(): Foreground Service vor Download
- DownloadService._stopBackgroundService(): Stopp nach Batch/Single
- Integration in _resetStatus, downloadBatch, downloadVonUrl
This commit is contained in:
Dustin
2026-08-02 16:06:04 +02:00
parent b8c206e58f
commit ae11a85872
5 changed files with 94 additions and 1 deletions
+24
View File
@@ -5,6 +5,7 @@ import 'package:audio_service/audio_service.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'database/db_helper.dart';
import 'services/favoriten_service.dart';
import 'services/auth_service.dart';
@@ -47,6 +48,16 @@ void main() async {
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(downloadChannel);
// ── Background Service initialisieren (Issue #3) ──
await FlutterBackgroundService().configure(
iosConfiguration: IosConfiguration(),
androidConfiguration: AndroidConfiguration(
onStart: _onServiceStart,
autoStart: false,
isForegroundMode: true,
),
);
try {
await DbHelper().db;
await FavoritenService().init();
@@ -148,6 +159,19 @@ Future<void> _starteAutoSyncFallsNoetig() async {
}
}
/// Background Service Callback hält App im Vordergrund beim Download (Issue #3)
@pragma('vm:entry-point')
Future<bool> _onServiceStart(ServiceInstance service) async {
WidgetsFlutterBinding.ensureInitialized();
// Service läuft als Foreground-Service und hält den Prozess am Leben.
// Der eigentliche Download läuft im Haupt-Isolate der Service dient nur
// als WakeLock / Foreground-Garantie.
service.on('stopService').listen((_) {
service.stopSelf();
});
return true;
}
class MeloApp extends StatelessWidget {
const MeloApp({super.key});