window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

setFocus not always work and isFocused is always false.

Open 21pages opened this issue 1 year ago • 1 comments

How to reproduce

  1. flutter run -d windows
  2. 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());
  }
}

21pages avatar Jul 05 '23 07:07 21pages

isFocused always returning false is solved in this PR https://github.com/leanflutter/window_manager/pull/461

lijy91 avatar May 18 '24 02:05 lijy91