【问题标题】:open a website links in my flutter webview app在我的颤振 webview 应用程序中打开一个网站链接
【发布时间】:2021-07-28 15:13:37
【问题描述】:

我正在构建一个颤动的 webview 应用程序来显示和使用我的网站,我希望当用户按下属于我的网站的链接时,应用程序会启动该链接,而不是在浏览器上启动它。 我使用 flutter_webview 包。 我怎样才能做到这一点? 如果您需要其他信息或代码,请告诉我。 提前致谢。

【问题讨论】:

  • 我认为这是不可能的。

标签: flutter webview flutterwebviewplugin


【解决方案1】:

你可以像这样使用flutter_inappwebview

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

class Code extends StatefulWidget {
  @override
  _CodeState createState() => _CodeState();
}

class _CodeState extends State<Code> {
  InAppWebViewController webView;
  String url = "";
  double progress = 0;

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

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

  @override
  Widget build(BuildContext context) {
    final appBar = AppBar(
      elevation: 1.0,
      backgroundColor: Colors.blueGrey,
      title: Text('In-app website'),
      centerTitle: true,
      leading: IconButton(
        icon: Icon(Icons.arrow_back),
        onPressed: () {
          Navigator.of(context).pop();
        },
      ),
    );

    final body = InAppWebView(
      initialUrl: "https://www.google.com",
      initialHeaders: {},
      initialOptions: InAppWebViewGroupOptions(
        crossPlatform: InAppWebViewOptions(
          debuggingEnabled: true,
        ),
      ),
      onWebViewCreated: (InAppWebViewController controller) {
        webView = controller;
      },
      onLoadStart: (InAppWebViewController controller, String url) {
        setState(() {
          this.url = url;
        });
      },
      onLoadStop: (InAppWebViewController controller, String url) async {
        setState(() {
          this.url = url;
        });
      },
      onProgressChanged: (InAppWebViewController controller, int progress) {
        setState(() {
          this.progress = progress / 100;
        });
      },
    );

    return Scaffold(
      appBar: appBar,
      body: body,
    );
  }
}

【讨论】:

    猜你喜欢
    • 2021-07-02
    • 2020-06-16
    • 1970-01-01
    • 2014-12-10
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    相关资源
    最近更新 更多