urlflutterwebviewtextspan

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


Here is My Code.

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)
            ),
            ...

I would like to tap the text string ('URL IS IN HERE.COM!) and for it to open in my webview widget?


Solution

  • I have worked it out after a lot of reading and research, This was the best solution Using a URL Scheme.

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