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

时间:2019-12-03 11:59:10

标签: flutter

我在标题标签中有一个CheckboxListTile和一个小部件。如何为此小部件创建html文本(文本+网址)?

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

我尝试了此操作: flutter_html:^ 0.10.4

没有运气

谢谢

2 个答案:

答案 0 :(得分:0)

您可以尝试flutter_linkify

您需要将Text替换为Linkify小部件。

使用此插件,您的代码可能如下所示:

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

答案 1 :(得分:0)

编辑: 您可以尝试link: ^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!'),
      ),
    );
  }
...

输出:

enter image description here


您是否尝试过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';
  }

您也可以尝试linkify

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