【问题标题】:Flutter i get an net:: ERR_UNKNOWN_URL_SCHEME when i click on a tel or mailto link on the website that is wrapped in the flutter webview当我单击包装在颤振 webview 中的网站上的 tel 或 mailto 链接时,颤振我得到一个 net:: ERR_UNKNOWN_URL_SCHEME
【发布时间】:2020-06-16 07:15:44
【问题描述】:

嗨,我将我的网站包装在一个颤振的 webview 中,但是当我在 tel 或 mailto 链接上点击时,应用程序会抛出一个错误

tel: 的网页无法加载,因为 net::ERR_UNKNOWN_URL_SCHEME 有人可以帮我解决这个问题下面的代码是我的应用程序,其中包含我正在使用的所有包我对应用程序开发非常陌生,我真的会感谢一些帮助

提前致谢 亲切的问候。

import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:splashscreen/splashscreen.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {enter code here
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(MaterialApp(
      home: MyApp(),
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: 'Bungee',
        primaryTextTheme: TextTheme(
          title: TextStyle(color: Colors.yellow, fontSize: 24),
        ),
      )));
}

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return new SplashScreen(
      seconds: 20,
      navigateAfterSeconds: AfterSplash(),
      image: new Image.asset(
        'assets/images/icon.png',
        width: 100,
        height: 100,
      ),
      backgroundColor: Colors.blueGrey[800],
      photoSize: 100.0,
      loaderColor: Colors.yellow[300],
    );
  }
}

class AfterSplash extends StatefulWidget {
  @override
  _MyAppsState createState() => _MyAppsState();
}

class _MyAppsState extends State<AfterSplash> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: WebviewScaffold(
        // Enter your custom url
        url: "https://appdev.quintechx.tk/",
        withJavascript: true,
        withLocalStorage: true,
        enableAppScheme: true,
        primary: true,
        supportMultipleWindows: true,
        allowFileURLs: true,
        withLocalUrl: true,
        scrollBar: false,
        appCacheEnabled: true,
      ),
    );
  }
}

【问题讨论】:

标签: flutter


【解决方案1】:

来自https://github.com/fluttercommunity/flutter_webview_plugin/issues/43的解决方案:

_subscription = webViewPlugin.onUrlChanged.listen((String url) async {
      print("navigating to...$url");
      if (url.startsWith("mailto") || url.startsWith("tel") || url.startsWith("http") || url.startsWith("https"))
      {
        await webViewPlugin.stopLoading();
        await webViewPlugin.goBack();
        if (await canLaunch(url))
        {
           await launch(url);
           return;
        }
        print("couldn't launch $url");
      }
    });

【讨论】:

    猜你喜欢
    • 2021-07-28
    • 2020-08-28
    • 2022-11-07
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 2021-05-13
    相关资源
    最近更新 更多