leanflutter / window_manager

This plugin allows Flutter desktop apps to resizing and repositioning the window.
https://pub.dev/packages/window_manager
MIT License
676 stars 177 forks source link

[Bug] window_manager breaks AppLifecycleListener's onExitRequested #466

Open Merrit opened 3 weeks ago

Merrit commented 3 weeks ago

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;
  }
}
Levi-Lesches commented 1 week ago

I'm getting the same issue on Windows

azlekov commented 1 week ago

+1 any workaround?

Levi-Lesches commented 1 week ago

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.