【问题标题】:How to use two different packages together on the same data如何在同一数据上同时使用两个不同的包
【发布时间】:2021-10-22 05:51:30
【问题描述】:

我有这两个包,我想使用flutter_linkifyreadmorelinkify 将文本中的 url 和电子邮件转换为可点击的链接,而 readmore 将长文本切割成较短的文本,我想将它们与相同的文本一起使用

String randomText = "DetectableTextField is published as a refinement of this isaackelechi2000@gmail.com package. hashtagale forces you to use hashtag, but this one allows you to detect anything you want. If you also want https://www.google.com to decorate At sign, you can do that by adding the argument decorateAtSign: true. "

//Using linkify
Linkify(
  onOpen: (link) => print("Clicked ${link.url}!"),
  text: randomText,
);

//using readmore
ReadMoreText(
  randomText,
  trimLines: 2,
  colorClickableText: Colors.pink,
  trimMode: TrimMode.Line,
  trimCollapsedText: 'Show more',
  trimExpandedText: 'Show less',
  moreStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
);

那么我怎样才能在同一屏幕上不显示两个不同的文本的情况下使用这两个具有相同文本的包

【问题讨论】:

    标签: flutter dart text flutter-packages


    【解决方案1】:

    不幸的是,由于这些小部件中的每一个都需要一个字符串(而不是子小部件),因此它们不能相互组合。

    我认为最好的办法是使用ExpandablePanel 小部件,而不是ReadMoreText,然后在子小部件上使用Linkify

    这样的事情可能会奏效(尽管您可能需要针对您的确切用例进行调整)。

    ExpandablePanel(
      collapsed: Linkify(article.body, softWrap: true, maxLines: 2, overflow: TextOverflow.ellipsis,),
      expanded: Linkify(article.body, softWrap: true, ),
      tapHeaderToExpand: true,
      hasIcon: true,
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 2017-11-12
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      相关资源
      最近更新 更多