【问题标题】:Flutter open webview inside the Dialog在 Dialog 内颤动打开 webview
【发布时间】:2019-07-06 21:31:42
【问题描述】:

//这是我的 webview 的颤振代码

  @override
  Widget build(BuildContext context) {
   return Scaffold(
    body: Center(
    child : WebviewScaffold(
      url: "https://www.facebook.com/",
      // appBar: new AppBar(
      //   // title: new Text('Hairtips'),
      // ),
      withZoom: true,
      withLocalStorage: true,    
     )
   ),
 );

  }

我正在我的颤振应用程序中实现 webview。我的片段中有三个 textview。当我点击 textview 时,我想在对话框中打开 webview。我知道如何在 android 中实现它。请建议我一些解决方案来修复这个问题

【问题讨论】:

    标签: flutter


    【解决方案1】:

    check this output 您可以通过将 WebViewScaffold 包装在 Container 中来添加填充。

    import 'package:flutter/material.dart';
    import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
    
    
    class WebViewDialogDemo extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
       return Container(
         padding:EdgeInsets.Symmetric(
           horizontal:20,
           vertical:40
         ),
         child: WebviewScaffold(
          url: "https://instagram.com/mahi7781",       
          withZoom: true,
          withLocalStorage: true,
          initialChild: Container(
              color: Colors.redAccent,
              child: const Center(
                child: Text("Loading...."),
            ),
          ),
        ));
      }
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用“https://pub.dartlang.org/packages/url_launcher”包来启动 URL。但它不会在您的应用程序中打开。它将打开默认平台浏览器。

      您也可以尝试使用“https://pub.dartlang.org/packages/flutter_webview_plugin”包。它应该在您的应用程序对话框中打开 Web 视图。但是,我还没有尝试过。让我知道它是否有效..

      === 更新 ===

      我使用了 flutter_web_view 插件并运行了下面的代码。它工作正常。

      我按照“https://pub.dartlang.org/packages/flutter_webview_plugin#-readme-tab-”中提供的确切步骤进行操作

      希望这会有所帮助。

      import 'package:flutter/material.dart';
      import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
      
      /// call this widget in MaterialApp - home.
      class WebViewDialogDemo extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return WebviewScaffold(
            url: "https://google.com",
            appBar: AppBar(
              title: Text("WebView Demo"),
              centerTitle: true,
            ),
            withZoom: true,
            withLocalStorage: true,
            initialChild: Container(
              color: Colors.redAccent,
              child: const Center(
                child: Text("Loading...."),
              ),
            ),
          );
        }
      }
      
      

      【讨论】:

      • 我会试试你的建议
      • 我尝试了你建议的链接中可用的代码
      猜你喜欢
      • 2019-07-21
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      相关资源
      最近更新 更多