【问题标题】:Flutter: how to insert a link in a RichText widget [duplicate]Flutter:如何在 RichText 小部件中插入链接 [重复]
【发布时间】:2020-12-02 11:40:52
【问题描述】:

video 中,他们说您可以使用手势识别器在 TextSpan 中创建可点击的链接,但我在 RichText 官方文档和互联网上一般都没有找到示例。有人可以解释一下怎么做吗?

【问题讨论】:

    标签: android ios flutter flutter-layout


    【解决方案1】:

    基本上是这样的

    RichText(
      text: TextSpan(
        children: [
          TextSpan(text: 'Hello'),
            TextSpan(
              text: 'World',
                recognizer: TapGestureRecognizer()
                  ..onTap = () async {
                    //Code to launch your URL
                  }
            )
          ]
       )
    );
    

    您可以使用URL launcher 来管理链接,如下所示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      相关资源
      最近更新 更多