如何在同一数据上同时使用两个不同的包
How to use two different packages together on the same data
我有这两个包,我想使用 flutter_linkify and readmore。
linkify 将文本中的 url 和电子邮件变成可点击的 link 而 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),
);
那么我如何使用具有相同文本的两个包而不在同一屏幕上显示两个不同的文本
不幸的是,由于这些小部件中的每一个都采用字符串(而不是子小部件),因此它们不能相互组合。
我认为最好的办法是使用 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,
);
我有这两个包,我想使用 flutter_linkify and readmore。 linkify 将文本中的 url 和电子邮件变成可点击的 link 而 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),
);
那么我如何使用具有相同文本的两个包而不在同一屏幕上显示两个不同的文本
不幸的是,由于这些小部件中的每一个都采用字符串(而不是子小部件),因此它们不能相互组合。
我认为最好的办法是使用 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,
);