Flutter window_manager全屏嵌入webview_windows不显示全屏

问题描述 投票:0回答:2

在 Flutter 中,我已经能够使用 https://github.com/leanflutter/window_manager.git

使 Windows 桌面应用程序全屏显示

在这个应用程序中,我希望整个屏幕显示网站的内容。现在我正在使用 webview_windows 来执行此操作。它确实显示了我指向的网页,但我的显示器上的最后 3 行像素没有显示该网页。相反,它显示的是 Flutter 应用程序的背景颜色。

为了演示我的意思,这里是应用程序当前外观的屏幕截图:

这里还有应用程序底部的特写:

绿色来自嵌入式网站,红色来自flutter背景颜色

这是我当前的 pubspec.yaml:

name: test
description: A new Flutter project.
publish_to: 'none' 
version: 1.0.0+1
environment:
  sdk: ">=2.17.6 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  window_manager:
    git:
      url: https://github.com/leanflutter/window_manager.git
      ref: main
  webview_windows: ^0.2.0
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0
flutter:
  uses-material-design: true

这是我当前的 main.dart:

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
import 'package:webview_windows/webview_windows.dart';

void main() async {
  // go fullscreen
  WidgetsFlutterBinding.ensureInitialized();

  // Must add this line.
  await windowManager.ensureInitialized();
  
  WindowOptions windowOptions = const WindowOptions(
    //size: Size(1920, 1080),
    center: true,
    backgroundColor: Colors.transparent,
    skipTaskbar: false,
    titleBarStyle: TitleBarStyle.hidden,
  );
    windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.setFullScreen(true);
      await windowManager.show();
      await windowManager.focus();
  });

  runApp(new MaterialApp(
    home: new MyApp(),
  ));
} 

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ExampleBrowser()
    );
  }
}

class ExampleBrowser extends StatefulWidget {
  @override
  State<ExampleBrowser> createState() => _ExampleBrowser();
}

class _ExampleBrowser extends State<ExampleBrowser> {
  LoadingState waitingState = LoadingState.loading;
  final _controller = WebviewController();

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

  Future<void> initPlatformState() async {
    try {
      await _controller.initialize();
      await _controller.setBackgroundColor(Colors.transparent);
      await _controller.setPopupWindowPolicy(WebviewPopupWindowPolicy.deny);
      await _controller.loadUrl('https://abbashouse.net/demo/test.html');

      _controller.loadingState.listen((event) => { 
        setState(() {
          waitingState = event;
        })
      });

      if (!mounted) return;
      setState(() {});
    } on PlatformException catch (e) {
      print(e);
    }
  }
  
  Widget compositeView() {
    return (waitingState == LoadingState.navigationCompleted) 
      ? Scaffold(
        body: Webview( _controller, width:1920.0, height:1080.0 ) 
      )
      : Scaffold(
        backgroundColor: Colors.red
      );
  }

  @override
  Widget build(BuildContext context) {
    return compositeView();
  }

}

这是当我将 webview 的高度硬编码为 200.0 时的样子

flutter webview fullscreen desktop-application window-managers
2个回答
0
投票

这里已经指定尺寸了

Scaffold(
        body: Webview( _controller, width:1920.0, height:1080.0 ) 
      )

您可以尝试添加与设备相同的尺寸

Scaffold(
        body: Webview( _controller, width: MediaQuery.of(context).size.width,height : MediaQuery.of(context).size.height) 
      )

您还可以创建一个屏幕大小的 SizedBox 并将 WebView 添加到其中

Scaffold (
 body :SizedBox(
 height: MediaQuery.of(context).size.height,
 width: MediaQuery.of(context).size.width,
 child: WebView(),
 )
)

0
投票

这是 window_manager 插件中的一个错误。已修复(希望PR#359PR#367。请更新到最新版本(0.3.6)并查看是否已修复。

© www.soinside.com 2019 - 2024. All rights reserved.