您好,我需要在Foreground Service数据包中使用path_provider 前景服务具有隔离功能,因此我需要在隔离功能内使用path_provider,但是当我使用它时,会出现异常
MissingPluginException(未找到方法的实现 通道上的getApplicationDocumentsDirectory plugins.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");
}
答案 0 :(得分:0)
再次运行 flutter clean
和 flutter run
。这应该可以解决问题。
答案 1 :(得分:0)
我也遇到了与您现在面临的 path_provider 包相同的问题,我执行了以下步骤来修复它:
问题已解决。