-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Description
Use case
According to this document: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate
We could have a function that takes up to five seconds during the applicationWillTerminate callback. I agree that doing complicated things there should be wrong but I think having the ability to do something is reasonable.
For exmaple, one might want to schedule a notification when a app is closed during a critical process (I believe the teala app will send a notification on close if the app is used as key).
In flutter, there is notification_when_app_is_killed which can achieve this. However, I think its implementation is not ideal, it basically implemented eveything in swift: Overriding the applicationWillTerminate callback and send a notification when it is called. It is weird becuae it is not generic, also we have nice binding of notification in dart but writing swift seems defeat the point of using flutter. I think ideally, applicationWillTerminate should trigger a dart async function and wait for it. Then we could send notification or do other things in that function.
I found this issue: #96779, I think the idea there kinda work but does not really.
It is possible to use FlutterMethodChannel to call a dart function when applicationWillTerminate is called. However, I can't block the applicationWillTerminate and wait for that dart invocation to be finished. If my understanding is correct, doing so will block the main thread and FlutterMethodChannel requires main thread?
Proposal
I naively think, WidgetBindingObserver should support this, applicationWillTerminate should trigger a change in the life cycle and applicationWillTerminate should be blocked until all WidgetBindingObserver callbacks are finished.