mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +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
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
class TextWidget extends StatelessWidget {
|
class TextWidget extends StatefulWidget {
|
||||||
final String content;
|
final String content;
|
||||||
final bool parseBBcode;
|
final bool parseBBcode;
|
||||||
final TextStyle style;
|
final TextStyle style;
|
||||||
@ -25,26 +25,40 @@ class TextWidget extends StatelessWidget {
|
|||||||
assert(parseBBcode != null),
|
assert(parseBBcode != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_TextWidgetState createState() => _TextWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TextWidgetState extends State<TextWidget> {
|
||||||
|
Widget _cache;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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
|
// Parse BBcode
|
||||||
if (this.parseBBcode)
|
if (this.widget.parseBBcode)
|
||||||
return BBCodeParsedWidget(
|
return BBCodeParsedWidget(
|
||||||
text: content,
|
text: content,
|
||||||
parseCallback: (style, text) => _parseLinks(context, text, style),
|
parseCallback: (style, text) => _parseLinks(text, style),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Just parse link
|
// Just parse link
|
||||||
return RichText(
|
return RichText(
|
||||||
text: TextSpan(children: _parseLinks(context, content, style)),
|
text: TextSpan(children: _parseLinks(content, widget.style)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sub parse function
|
/// Sub parse function
|
||||||
List<InlineSpan> _parseLinks(
|
List<InlineSpan> _parseLinks(String text, TextStyle style) {
|
||||||
BuildContext context, String text, TextStyle style) {
|
if (style == null) style = TextStyle();
|
||||||
|
|
||||||
var buff = StringBuffer();
|
var buff = StringBuffer();
|
||||||
final list = new List<InlineSpan>();
|
final list = new List<InlineSpan>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user