如何修复webview_flutter中的白色?

weylhg0b  于 2023-01-14  发布在  Flutter
关注(0)|答案(7)|浏览(248)

使用初始URL运行webview_flutter示例应用程序(https://github.com/flutter/plugins/tree/master/packages/webview_flutter/example):“https://kreatryx.com“在Android上它只显示白色,右下角有Zopim聊天栏。在iOS上它运行良好。有Android的解决方案吗?
我已经试过了:1.Flutter通道开发2.Flutter通道主控

odopli94

odopli941#

多亏了这篇文章中的github Issues reference,下面的解决方案对我编辑Info.plist很有效:

<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key> <true/>
  <key>NSAllowsArbitraryLoadsInWebContent</key> <true/>
</dict>

我是第一次使用Info.plist,不确定<dict>标记是否可以像这样嵌套,但显然这是可以的。

ncecgwcz

ncecgwcz2#

如果你使用的url不是全英语或者有一些空格字符,你需要这样编码网址

WebView(
      initialUrl: Uri.encodeFull(yourUrl),
      ...
 )
qnakjoqk

qnakjoqk3#

你可以试试我的插件flutter_inappwebview,这是一个Flutter插件,允许你添加内联WebView或打开一个应用内浏览器窗口,并有很多事件,方法和选项来控制WebView。
使用URL的完整示例:

import 'dart:async';

import 'package:flutter/material.dart';

import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {
  runApp(new MyApp());
}

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

class _MyAppState extends State<MyApp> {

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: InAppWebViewPage()
    );
  }
}

class InAppWebViewPage extends StatefulWidget {
  @override
  _InAppWebViewPageState createState() => new _InAppWebViewPageState();
}

class _InAppWebViewPageState extends State<InAppWebViewPage> {
  InAppWebViewController webView;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: Text("InAppWebView")
        ),
        body: Container(
            child: Column(children: <Widget>[
              Expanded(
                child: Container(
                  child: InAppWebView(
                    initialUrl: "https://kreatryx.com",
                    initialHeaders: {},
                    initialOptions: InAppWebViewWidgetOptions(
                      inAppWebViewOptions: InAppWebViewOptions(
                        debuggingEnabled: true,
                      ),
                      androidInAppWebViewOptions: AndroidInAppWebViewOptions(
                        domStorageEnabled: true,
                        databaseEnabled: true,
                      ),
                    ),
                    onWebViewCreated: (InAppWebViewController controller) {
                      webView = controller;
                    },
                    onLoadStart: (InAppWebViewController controller, String url) {

                    },
                    onLoadStop: (InAppWebViewController controller, String url) {

                    },
                  ),
                ),
              ),
            ]))
    );
  }
}

它在Android和iOS平台上都运行良好,这是结果:

5cnsuln7

5cnsuln74#

更新

类似于Android Webview: "Uncaught TypeError: Cannot read property 'getItem' of null"
缺少settings.setDomStorageEnabled(true);
相关问题https://github.com/flutter/flutter/issues/26347

原件

webview_flutter当前不能自动重定向.
https://kreatryx.com重定向到https://www.kreatryx.com,插件不遵循该重定向,只是显示https://kreatryx.com返回的内容,这是什么都没有。
遵循https://github.com/flutter/flutter/issues/25351

jmp7cifd

jmp7cifd5#

对我来说,我需要通过设置启用Javascript:

javascriptMode: JavascriptMode.unrestricted
WebView(
        javascriptMode: JavascriptMode.unrestricted,
        initialUrl: 'https://example.com',
)
i1icjdpr

i1icjdpr6#

因为有另一个插件可以自动重定向到所请求的页面。使用给定的dart插件:flutter网页浏览插件0.3.0+2
您可以从以下URL使用该插件:https://pub.dartlang.org/packages/flutter_webview_plugin#-readme-tab-
示例代码可在此处找到:

new MaterialApp(
      routes: {
        "/": (_) => new WebviewScaffold(
          url: "https://kreatryx.com",
          appBar: new AppBar(
            title: new Text("Widget webview"),
          ),
        ),
      },
    );
uemypmqf

uemypmqf7#

Try This Guys U Can Easily Preview PDF Getting From Response.
    
    Uint8List? _documentBytes;
    @override
    void initState() {
      getPdfBytes();
      super.initState();
    }
     
    ///Get the PDF document as bytes
    void getPdfBytes() async {
 Map<String, String> _header = <String, String>{
      'Authorization': _userDataController.userDataModel.token,
      'content-type': 'application/json',
    };
      _documentBytes = await http.readBytes(Uri.parse(
          'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf' Or 'url'));
    headers: _header,
      setState(() {});
    }
     
    @override
    Widget build(BuildContext context) {
      Widget child = const Center(child: CircularProgressIndicator());
      if (_documentBytes != null) {
        child = SfPdfViewer.memory(
          _documentBytes!,
        );
      }
      return Scaffold(
        appBar: AppBar(title: const Text('Syncfusion Flutter PDF Viewer')),
        body: child,
      );
    }

相关问题