Open CaoGiaHieu-dev opened 1 month ago
There is a workaround. Refer to this comment.
https://github.com/MixinNetwork/flutter-plugins/issues/289#issuecomment-1874255766
There is a workaround. Refer to this comment.
Thank you . for now this was the only solutions
Unfortunately, this was something I didn't expect and I didn't find any solution to fix it. It seems to be something related to Flutter itself on macOS. Instead, on Windows I didn't have any problem.
On macOS, the curious thing is that if I resize the window, it updates. If I lose focus and then regain it by switching to another window of another program, then it works correctly again.
for reference: https://github.com/flutter/flutter/issues/133533
I was able to create a workaround without changing the Flutter source code, using an AppLifecycleListener
to force to trigger _setFramesEnabledState(true);
instead of _setFramesEnabledState(false);
.
In your app implement this listener this way inside your main widget extending a State
:
class _MyAppState extends State<MyApp> {
// your code ....
late final AppLifecycleListener? _appLifecycleListener;
@override
void initState() {
// your code ....
// workaround applies for all sub-windows (all windows with id > 0) on macOS
if (WindowManagerPlus.current.id > 0 && Platform.isMacOS) {
_appLifecycleListener = AppLifecycleListener(
onStateChange: _handleStateChange,
);
}
super.initState();
}
void _handleStateChange(AppLifecycleState state) {
// workaround applies for all sub-windows (all windows with id > 0) on macOS
if (WindowManagerPlus.current.id > 0 && Platform.isMacOS && state == AppLifecycleState.hidden) {
// trigger _setFramesEnabledState(true); method
SchedulerBinding.instance.handleAppLifecycleStateChanged(
AppLifecycleState.inactive);
}
}
@override
void dispose() {
// your code ....
_appLifecycleListener?.dispose();
super.dispose();
}
// your code ....
}
It is using the protected method SchedulerBinding.handleAppLifecycleStateChanged
but this seems to be the only way to achieve that without changing the Flutter source code.
same as this issue https://github.com/MixinNetwork/flutter-plugins/issues/319
it also happen when i create new window then quickly switch to other app or main window