-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VisibilityDetector not working with AppLifecycleState #53
Comments
I've done something like this: extension VisibilityDetector on Widget {
Widget toVisibilityDetector(String key, Function(bool visible) callback) {
final appLifecycleObserver = _AppLifecycleObserver(callback);
var visible = false;
return google.VisibilityDetector(
key: Key(key),
child: this,
onVisibilityChanged: (google.VisibilityInfo info) {
final isNowVisible = info.visibleFraction > 0;
if (isNowVisible == visible) {
return;
}
visible = isNowVisible;
callback(visible);
if (visible) {
WidgetsBinding.instance.addObserver(appLifecycleObserver);
} else {
WidgetsBinding.instance.removeObserver(appLifecycleObserver);
}
},
);
}
}
class _AppLifecycleObserver extends WidgetsBindingObserver {
final Function(bool visible) callback;
_AppLifecycleObserver(this.callback);
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
callback(state == AppLifecycleState.resumed);
}
} Any suggestions? |
Sorry, I somehow missed this when it was filed.
I'm currently leaning toward leaving this as the application's responsibility, but I'll have to think about this for a bit. Feel free to convince me in either direction. |
People usually want to detect the visibility of view because they want to reload data when the view becomes visible. So whether the view becomes visible because the application come to foreground or because it is added to the widget tree, they are not so different, in which case data should be reloaded |
Is there a good solution to this problem? |
you should use that works fine in my case to controll a stream, is pretty well explained here |
@jamesderlin This thing might need to add in the documentation, because everyone will think that the visibility will get reported if app went to background state. |
When my app go to background or come back to foreground, nothing is called in VisibilityDetector. Is there any way to do this?
The text was updated successfully, but these errors were encountered: