window_manager
window_manager copied to clipboard
setFocus not always work and isFocused is always false.
How to reproduce
- flutter run -d windows
- Put the windows behide other window in 10 seconds
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget with WindowListener {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
Timer.periodic(const Duration(seconds: 10), (timer) async {
debugPrint("focused:${await windowManager.isFocused()}");
await windowManager.focus();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Container());
}
}
isFocused always returning false is solved in this PR https://github.com/leanflutter/window_manager/pull/461