flutter_foreground_task
flutter_foreground_task copied to clipboard
saveData and getData don't work
i'm following the example and the saveData and getData don't work . can i get help ㅠㅠ
Confirm it's not working +++
For me it is working the first time. But then i do a stopForegroundService() and a restartForegroundService() and it does not work anymore after that.
For me it is working the first time. But then i do a stopForegroundService() and a restartForegroundService() and it does not work anymore after that.
I use this way to walk around the problem:
- call stopService() first.
- delay a little while.(I don't like this way, but it is needed.)
- saveData and startService(not restart service).
if (await FlutterForegroundTask.isRunningService) {
await FlutterForegroundTask.stopService();
await Future.delayed(Duration(milliseconds: 100));
}
..........
await FlutterForegroundTask.saveData(
key: 'json', value: json.encode(data.toJson()));
bool reqResult = await FlutterForegroundTask.startService(
notificationTitle: '${data.name}',
notificationText: '${formatSeconds(data.value)}',
callback: startCallback,
);
For me it is working the first time. But then i do a stopForegroundService() and a restartForegroundService() and it does not work anymore after that.
I use this way to walk around the problem:
1. call stopService() first. 2. delay a little while.(I don't like this way, but it is needed.) 3. saveData and startService(not restart service).if (await FlutterForegroundTask.isRunningService) { await FlutterForegroundTask.stopService(); await Future.delayed(Duration(milliseconds: 100)); } .......... await FlutterForegroundTask.saveData( key: 'json', value: json.encode(data.toJson())); bool reqResult = await FlutterForegroundTask.startService( notificationTitle: '${data.name}', notificationText: '${formatSeconds(data.value)}', callback: startCallback, );
Thanks for the tips ! :)