gpt4 book ai didi

Flutter/webview_flutter 太大而无法适应屏幕

转载 作者:行者123 更新时间:2023-12-05 06:16:55 28 4
gpt4 key购买 nike

我正在运行 flutter 1.17.1,使用 webview_flutter: ^0.3.21添加到 pubspec.yaml 的依赖项并将其添加到 info.plist 的末尾

<key>io.flutter.embedded_views_preview</key>
<string>YES</string>

问题:webview加载的网页太大,手机屏幕放不下。 screenshot

这是带有 webview 的代码:

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

class WebViewContainer extends StatefulWidget {
final url;
WebViewContainer(this.url);
@override
createState() => _WebViewContainerState(this.url);
}

class _WebViewContainerState extends State<WebViewContainer> {
var _url;
final _key = UniqueKey();
_WebViewContainerState(this._url);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
children: [
Expanded(
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: _url))

],
));
}
}

链接到完整的应用程序: https://github.com/bi-samson/mreader

最佳答案

我已经尝试使用 url“https://www.businessinsider.jp/”和 latest version of webview_flutter 进行最小复制,这是输出:

enter image description here enter image description here

最小重现:

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:async';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: WebView(
initialUrl: "https://www.businessinsider.jp/",
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
javascriptMode: JavascriptMode.unrestricted,
),
);
}
}

最新版本好像没有出现这个问题。

关于Flutter/webview_flutter 太大而无法适应屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61885576/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com