首页 > 解决方案 > Flutter webview 无法将网页与屏幕匹配

问题描述

我正在使用 webview_flutter:^0.3.14+1。

Webview 无法正确加载网页https://m.bilibili.com/video/av57346110.html网页过大

但是如果我用 chrome 打开它,网页会正确地适合屏幕。

而且我不明白网络浏览器和flutter webview之间的区别。

这是重现的最少代码:

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

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(),
        body: Container(
          child: WebView(
            initialUrl: "https://m.bilibili.com/video/av57346110.html",
            javascriptMode: JavascriptMode.unrestricted,
            navigationDelegate: (NavigationRequest request) {
              print("Loading... ${request.url}");
              if(request.url.startsWith("http")) {
                return NavigationDecision.navigate;
              } else {
                return NavigationDecision.prevent;
              }
            },
          ),
        ),
      ),
    );
  }
}

标签: flutterwebview

解决方案


推荐阅读