Skip to content
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

[Bug] window_manager breaks AppLifecycleListener's onExitRequested #466

Open
Merrit opened this issue Jun 19, 2024 · 4 comments
Open

[Bug] window_manager breaks AppLifecycleListener's onExitRequested #466

Merrit opened this issue Jun 19, 2024 · 4 comments

Comments

@Merrit
Copy link
Contributor

Merrit commented Jun 19, 2024

Having window_manager installed as a dependency breaks onExitRequested from Flutter's AppLifecycleListener.

Tested so far on Linux (Fedora 40 KDE, Wayland). Not sure of other platforms.

import 'dart:ui';

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  final windowService = WindowService();

  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text('Hello World!'),
        ),
      ),
    );
  }
}

class WindowService {
  late final AppLifecycleListener _appLifecycleListener;

  WindowService() {
    _appLifecycleListener = AppLifecycleListener(
      onExitRequested: _handleExitRequest,
    );
  }

  Future<AppExitResponse> _handleExitRequest() async {
    print('Exit requested');
    return AppExitResponse.cancel;
  }
}
  • Run the example, without window_manager as a dependency
  • Try to close the window, Exit requested is printed instead of it closing (expected behaviour)
  • Add window_manager as a dependency
  • Run the example again, and again try to close the window
  • Instead of printing Exit requested, the window closes with a message Lost connection to device. (unexpected behaviour)
@Levi-Lesches
Copy link

I'm getting the same issue on Windows

@azlekov
Copy link

azlekov commented Jul 4, 2024

+1 any workaround?

@Levi-Lesches
Copy link

I did not realize it, but window_manager ended up giving me exactly what I need anyway, in the form of windowManager.setPreventClose(true). I used that instead of AppLifecycleListener.onExitRequested and it works very well.

@Merrit
Copy link
Contributor Author

Merrit commented Jul 26, 2024

Seems like onWindowClose isn't reliable, but if you check for eventName == 'close' in onWindowEvent along with setting setPreventClose(true), it works to manually handle closing the app as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants