window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

Windows:When using webview, the minimize method cannot hide the webview page

Open gk-1213 opened this issue 11 months ago • 1 comments

import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();

  WindowOptions windowOptions = const WindowOptions(
    size: Size(800, 600),
    center: true,
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
    titleBarStyle: TitleBarStyle.normal,
    windowButtonVisibility: false,
  );
  windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.show();
    await windowManager.focus();
  });

  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ThemeMode _themeMode = ThemeMode.light;

  InAppWebViewController? webViewController;
  String url = "";
  double progress = 0;
  final urlController = TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final virtualWindowFrameBuilder = VirtualWindowFrameInit();

    return MaterialApp(
        debugShowCheckedModeBanner: false,
        themeMode: _themeMode,
        builder: (context, child) {
          child = virtualWindowFrameBuilder(context, child);
          return child;
        },
        home: Scaffold(
          appBar: PreferredSize(
              preferredSize: const Size.fromHeight(40),
              child: SizedBox(
                width: 1060,
                child: Row(
                  children: [
                    const Expanded(
                      child: DragWindow(),
                    ),

                    /// 右上角按钮
                    Row(children: [
                      IconButton(
                          onPressed: () async{
                            await windowManager.minimize();
                          }, icon: const Icon(Icons.remove)),
                      IconButton(
                          onPressed: () async{
                            await windowManager.close();
                          }, icon: const Icon(Icons.close)),
                    ])
                  ],
                ),
              )),
          body: SafeArea(
              child: Column(children: <Widget>[
            TextField(
              decoration: const InputDecoration(prefixIcon: Icon(Icons.search)),
              controller: urlController,
              keyboardType: TextInputType.url,
              onSubmitted: (value) {
                var url = WebUri(value);
                if (url.scheme.isEmpty) {
                  url = WebUri("https://www.google.com/search?q=$value");
                }
                webViewController?.loadUrl(urlRequest: URLRequest(url: url));
              },
            ),
            Expanded(
              child: Stack(
                children: [
                  InAppWebView(
                    initialUrlRequest:
                        URLRequest(url: WebUri("https://inappwebview.dev/")),
                    onWebViewCreated: (controller) {
                      webViewController = controller;
                    },
                    onLoadStart: (controller, url) {
                      setState(() {
                        this.url = url.toString();
                        urlController.text = this.url;
                      });
                    },
                  ),
                  progress < 1.0
                      ? LinearProgressIndicator(value: progress)
                      : Container(),
                ],
              ),
            ),
            ButtonBar(
              alignment: MainAxisAlignment.center,
              children: <Widget>[
                ElevatedButton(
                  child: const Icon(Icons.arrow_back),
                  onPressed: () {
                    webViewController?.goBack();
                  },
                ),
                ElevatedButton(
                  child: const Icon(Icons.arrow_forward),
                  onPressed: () {
                    webViewController?.goForward();
                  },
                ),
                ElevatedButton(
                  child: const Icon(Icons.refresh),
                  onPressed: () {
                    webViewController?.reload();
                  },
                ),
              ],
            ),
          ])),
        ));
  }
}

//拖动窗口
class DragWindow extends StatelessWidget {
  const DragWindow({super.key});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      child: Listener(
        onPointerDown: (event) async {
          await windowManager.startDragging();
        },
        child: Container(
          color: Colors.transparent,
        ),
      ),
    );
  }
}

After minimizing the window, the mouse cannot interact with the desktop, and the minimize method does not hide the webview page

Flutter version:3.24.3 Version of plugin used:0.4.3 Other plugins used:flutter_inappwebview: ^6.2.0-beta.2

gk-1213 avatar Feb 06 '25 10:02 gk-1213

After minimizing the window, the mouse cannot interact with the desktop

@lijy91 我在同时使用 window_manager 和 flutter_inappwebview 时,也存在把窗口最小化后,桌面无法点击的情况。 不过我不确定这是window_manager 还是 flutter_inappwebview 的问题。

具体来说,最小化窗口后,会使windows桌面上(程序窗口最初显示的位置)的部分图标无法点击。 如果resize 窗口,会使这个不可点击的区域跟随程序窗口的大小而变化。 如果点击windows工具栏最右侧的"显示桌面"按钮,可以让桌面恢复正常。 就好像是窗口最小化时仍保留了一个透明的窗口,从而遮盖了桌面上的程序图标?

经观察实际导致不可点击的区域,似乎是(最小化之前的)窗口中的webview部分所遮盖的桌面区域(红框) Image

我的环境:

Flutter (Channel stable, 3.32.0, on Microsoft Windows [版本 10.0.19045.5854], locale zh-CN)
Windows Version (10 专业版 64 位, 22H2, 2009)

window_manager: ^0.5.0
flutter_inappwebview: ^6.1.5

最后附上最小代码样本:

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();

  WindowOptions windowOptions = const WindowOptions(
    size: Size(800, 600),
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
  );
  windowManager.waitUntilReadyToShow(windowOptions, () async {
    await windowManager.show();
    await windowManager.focus();
  });

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    final virtualWindowFrameBuilder = VirtualWindowFrameInit();
    return MaterialApp(
      title: 'InAppWebView Demo',
      builder: (context, child) {
        child = virtualWindowFrameBuilder(context, child);
        return child;
      },
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const WebViewExample(),
    );
  }
}

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

  @override
  State<WebViewExample> createState() => _WebViewExampleState();
}

class _WebViewExampleState extends State<WebViewExample> {
  late InAppWebViewController webViewController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('InAppWebView Hello World'),
      ),
      body: Column(
        children: [
          Expanded(
            child: InAppWebView(
              
              initialUrlRequest: URLRequest(
                url: WebUri('https://flutter.dev'),
              ),
              
            ),
          ),
        ],
      ),
    );
  }
}

34205037 avatar May 29 '25 22:05 34205037