我想在 TextSpan 中的 WebView 中打开一个 URL

I would like to open a URL in a WebView from within a TextSpan

这是我的代码。

Center(
  child: SingleChildScrollView(
    child: Container(
      child: RichText(
        text: TextSpan(
          //style: DefaultTextStyle.of(context).style,
          children: [
            TextSpan(
              text: 'URL IS IN HERE.COM!\n',  
              style: TextStyle(letterSpacing: 1, fontSize: 26.0, fontWeight: FontWeight.bold, color: Colors.black)
            ),
            ...

我想点击文本字符串('URL IS IN HERE.COM!)并在我的网络视图小部件中打开它?

您可以使用 textspan 的识别器 属性,要在浏览器中打开 url,您可以使用此 https://pub.dev/packages/url_launcher

小部件

TextSpan(text: 'Non touchable. ', children: [
  new TextSpan(
    text: 'Tap here.',
    recognizer: new TapGestureRecognizer()..onTap = () => {
      _launchURL();
    },
  )
])

方法

_launchURL() async {
  const url = 'https://flutter.dev';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

经过大量阅读和研究,我已经解决了这个问题,这是使用 URL 方案的最佳解决方案。

               onTap: () async {
                    const url = "https:www.example.com";
                  if (await canLaunch(url)) {
                      await launch(url, forceWebView: true);
                } else {
                      throw "Could not launch $url";
                  }
                },