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 178 forks source link

[Windows] Restoring window from minimized state triggers onWindowBlur instead of onWindowFocus. #439

Open KevinBrendel opened 4 months ago

KevinBrendel commented 4 months ago

The window is focused in this state, therefore the wrong event is sent. Discovered on Windows 11.

Example App:

import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';

void main() {
  runApp(const MainApp());
}

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

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> with WindowListener {
  @override
  void initState() {
    super.initState();
    windowManager.addListener(this);
  }

  @override
  void dispose() {
    windowManager.removeListener(this);
    super.dispose();
  }

  @override
  void onWindowFocus() async {
    print("onWindowFocus");
  }

  @override
  void onWindowBlur() async {
    print("onWindowBlur");
  }

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