Reputation: 21
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?
Upvotes: 0
Views: 932
Reputation: 21
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";
}
},
Upvotes: 0
Reputation: 96
you can use recognizer property of textspan and for open url in browser you can use this https://pub.dev/packages/url_launcher
Widget
TextSpan(text: 'Non touchable. ', children: [
new TextSpan(
text: 'Tap here.',
recognizer: new TapGestureRecognizer()..onTap = () => {
_launchURL();
},
)
])
Method
_launchURL() async {
const url = 'https://flutter.dev';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Upvotes: 0