plus_plugins
plus_plugins copied to clipboard
[Question]: How To Get Context Inside Callback
What is your question?
When using the Flutter AlarmManagerPlus package and any one of its exposed methods, the callback we can pass is either of type Function or Function(int).
assert(callback is Function() || callback is Function(int));
Furthermore, we are instructed to mark our callback functions as static.
Due to all of these restrictions, I am wondering how I can access/get a context in one of the callbacks so that I can (for example) show an alert dialog when the callback is being triggered.
static void _periodicTaskCallback() {
// How to get context here?
}
void _schedulePeriodicAlarm() async {
Duration duration = await _chooseDuration();
await AndroidAlarmManager.periodic(duration, _periodicTaskId, _periodicTaskCallback);
}
Just as a note, I have a basic one class stateful widget and I have tried accessing the state using a GlobalKey or using the OneContext package, but both don't appear to work.
You can see the code here.
Any guidance will be appreciated.