List<Widget> _buildContent(String content) {
List<Widget> contentList = new List();
RegExp url = new RegExp(r"((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+");
List listString = content.split(url);
List listUrl = new List();
Iterable<Match> matches = url.allMatches(content);
int urlIndex = 0;
for (Match m in matches) {
listUrl.add(m.group(0));
}
for (var i = 0; i < listString.length; i++) {
if (listString[i] == '') {
// 空字符串说明应该填充Url
contentList.add(PinsCellLink(
linkUrl: listUrl[urlIndex],
));
urlIndex += 1;
} else {
contentList.add(Text(
listString[i],
style: _textStyle,
overflow: TextOverflow.ellipsis,
maxLines: 5,
));
}
}
return contentList;
}
网友评论