mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Optimize parsing
This commit is contained in:
parent
45d3f93192
commit
7014ded7f0
@ -11,7 +11,7 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class TextWidget extends StatelessWidget {
|
||||
class TextWidget extends StatefulWidget {
|
||||
final String content;
|
||||
final bool parseBBcode;
|
||||
final TextStyle style;
|
||||
@ -25,26 +25,40 @@ class TextWidget extends StatelessWidget {
|
||||
assert(parseBBcode != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_TextWidgetState createState() => _TextWidgetState();
|
||||
}
|
||||
|
||||
class _TextWidgetState extends State<TextWidget> {
|
||||
Widget _cache;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var content = EmojiParser().emojify(this.content);
|
||||
if (_cache == null) _cache = doBuild();
|
||||
|
||||
return _cache;
|
||||
}
|
||||
|
||||
Widget doBuild() {
|
||||
var content = EmojiParser().emojify(this.widget.content);
|
||||
|
||||
// Parse BBcode
|
||||
if (this.parseBBcode)
|
||||
if (this.widget.parseBBcode)
|
||||
return BBCodeParsedWidget(
|
||||
text: content,
|
||||
parseCallback: (style, text) => _parseLinks(context, text, style),
|
||||
parseCallback: (style, text) => _parseLinks(text, style),
|
||||
);
|
||||
|
||||
// Just parse link
|
||||
return RichText(
|
||||
text: TextSpan(children: _parseLinks(context, content, style)),
|
||||
text: TextSpan(children: _parseLinks(content, widget.style)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Sub parse function
|
||||
List<InlineSpan> _parseLinks(
|
||||
BuildContext context, String text, TextStyle style) {
|
||||
List<InlineSpan> _parseLinks(String text, TextStyle style) {
|
||||
if (style == null) style = TextStyle();
|
||||
|
||||
var buff = StringBuffer();
|
||||
final list = new List<InlineSpan>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user