Мне нужно использовать path_provider
внутри ForegroundService
пакета. Кстати, у Foreground Service
есть Isolate
, поэтому мне нужно использовать path_provider
внутри Isolate
. Однако, когда я использую его, у меня возникает следующее исключение:
MissingPluginException (Реализация для метода getApplicationDocumentsDirectory в плагинах канала не найдена. Flutter.io/path_provider)
Мой код:
void maybeStartFGS() async {
///if the app was killed+relaunched, this function will be executed again
///but if the foreground service stayed alive,
///this does not need to be re-done
if (!(await ForegroundService.foregroundServiceIsStarted())) {
await ForegroundService.setServiceIntervalSeconds(5);
//necessity of editMode is dubious (see function comments)
await ForegroundService.notification.startEditMode();
await ForegroundService.notification
.setTitle("Example Title: ${DateTime.now()}");
await ForegroundService.notification
.setText("Example Text: ${DateTime.now()}");
await ForegroundService.notification.finishEditMode();
await ForegroundService.startForegroundService(foregroundServiceFunction);
await ForegroundService.getWakeLock();
}
///this exists solely in the main app/isolate,
///so needs to be redone after every app kill+relaunch
await ForegroundService.setupIsolateCommunication((data) {
debugPrint("main received: $data");
// _beacon.Brodcast();
//_scanningBeacon.initScanBeacon();
});
}
void foregroundServiceFunction() {
debugPrint("The current time is: ${DateTime.now()}");
Future<List> readCounter() async {
try {
final file = await _localFile;
print('file$file');
// Read the file.
List reada = await jsonDecode(file.readAsStringSync());
print('reada$reada');
return reada;
} catch (e) {
print(e.toString());
return null;
}
}
ForegroundService.notification.setText("The time was: ${DateTime.now()}");
if (!ForegroundService.isIsolateCommunicationSetup) {
ForegroundService.setupIsolateCommunication((data) {
debugPrint("bg isolate received: $data");
});
}
ForegroundService.sendToPort("message from bg isolate");
}