简体   繁体   English

Flutter 将可点击的链接/网址添加到 CheckboxListTile

[英]Flutter add clickable link/url to a CheckboxListTile

I have a CheckboxListTile and a widget in the title tag.我在标题标签中有一个 CheckboxListTile 和一个小部件。 How can I create a html text (text + url) to this widget?如何为此小部件创建 html 文本(文本 + url)?

My text is: 'Hello <a href="www.aaa.aa">Click here</a>!'

I tried this: flutter_html: ^0.10.4我试过这个: flutter_html:^0.10.4

with no luck没有运气

Thanks谢谢

Edit: You can try link: ^1.1.0编辑:您可以尝试链接:^1.1.0

import 'package:link/link.dart';
...
 Link(
    child: Text('This is a link to Flutter', style: TextStyle(
       decoration: TextDecoration.underline, // add add underline in text
    ),),
   url: 'https://google.com',
   onError: _showErrorSnackBar,
 ),

 void _showErrorSnackBar() {
    Scaffold.of(context).showSnackBar(
      SnackBar(
        content: Text('Oops... the URL couldn\'t be opened!'),
      ),
    );
  }
...

Output:输出:

在此处输入图片说明


Have you tried url_launcher ,你有没有试过url_launcher

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

You can also try linkify你也可以试试linkify

linkify("Made by https://cretezy.com");

You could try flutter_linkify .你可以试试flutter_linkify

You need to replace Text with Linkify widget.您需要用Linkify小部件替换Text

With this plugin you code might look like this:使用此插件,您的代码可能如下所示:

Linkify(
  onOpen: (link) => print("Clicked ${link.url}!"),
  text: "Made by https://cretezy.com",
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM