From 3389ca18f70604645a19298e3b0646cfde0dd56e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 16 Apr 2020 10:14:45 +0200 Subject: [PATCH] Parse emojies --- lib/ui/tiles/comment_tile.dart | 5 +++-- lib/ui/tiles/post_tile.dart | 5 ++++- lib/ui/widgets/text_widget.dart | 22 +++++++++++++++++++--- pubspec.lock | 7 +++++++ pubspec.yaml | 3 +++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/ui/tiles/comment_tile.dart b/lib/ui/tiles/comment_tile.dart index 154dbe6..d3b1492 100644 --- a/lib/ui/tiles/comment_tile.dart +++ b/lib/ui/tiles/comment_tile.dart @@ -3,6 +3,7 @@ import 'package:comunic/models/user.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/ui/widgets/like_widget.dart'; import 'package:comunic/ui/widgets/network_image_widget.dart'; +import 'package:comunic/ui/widgets/text_widget.dart'; import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; @@ -90,8 +91,8 @@ class CommentTile extends StatelessWidget { // Comment text Container( child: comment.hasContent - ? Text( - comment.content, + ? TextWidget( + content: comment.content, style: TextStyle( color: darkTheme() ? darkAccentColor : Colors.black), ) diff --git a/lib/ui/tiles/post_tile.dart b/lib/ui/tiles/post_tile.dart index 6b39ba2..a573c11 100644 --- a/lib/ui/tiles/post_tile.dart +++ b/lib/ui/tiles/post_tile.dart @@ -199,7 +199,10 @@ class _PostTileState extends State { // Post text Container( child: widget.post.hasContent - ? TextWidget(content: widget.post.content) + ? TextWidget( + content: widget.post.content, + parseBBcode: true, + ) : null), ], ); diff --git a/lib/ui/widgets/text_widget.dart b/lib/ui/widgets/text_widget.dart index 24b90e0..c8eb115 100644 --- a/lib/ui/widgets/text_widget.dart +++ b/lib/ui/widgets/text_widget.dart @@ -1,5 +1,6 @@ import 'package:comunic/utils/bbcode_parser.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_emoji/flutter_emoji.dart'; /// Text widget /// @@ -9,13 +10,28 @@ import 'package:flutter/material.dart'; class TextWidget extends StatelessWidget { final String content; + final bool parseBBcode; + final TextStyle style; - const TextWidget({Key key, @required this.content}) - : assert(content != null), + const TextWidget({ + Key key, + @required this.content, + this.parseBBcode = false, + this.style, + }) : assert(content != null), + assert(parseBBcode != null), super(key: key); @override Widget build(BuildContext context) { - return BBCodeParsedWidget(text: content); + var content = EmojiParser().emojify(this.content); + + if (this.parseBBcode) + return BBCodeParsedWidget(text: content); + else + return Text( + content, + style: style, + ); } } diff --git a/pubspec.lock b/pubspec.lock index 323468b..b109512 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -97,6 +97,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.3" + flutter_emoji: + dependency: "direct main" + description: + name: flutter_emoji + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1+1" flutter_plugin_android_lifecycle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index fd37160..7a83d79 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,6 +51,9 @@ dependencies: # Get current system language intl: ^0.16.1 + # Parse emojies + flutter_emoji: ^2.2.1+1 + dev_dependencies: flutter_test: sdk: flutter