From 6fe0f6967e536582d2b674bf974d2fb309b8c899 Mon Sep 17 00:00:00 2001 From: zoe Date: Sat, 1 Oct 2022 17:19:22 +0200 Subject: [PATCH] custom emojis in names and no more markdown --- lib/pages/notifications/single_notif.dart | 9 +++-- lib/partials/name.dart | 43 +++++++++++++++++++++++ lib/partials/post.dart | 13 ++++--- 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 lib/partials/name.dart diff --git a/lib/pages/notifications/single_notif.dart b/lib/pages/notifications/single_notif.dart index bc43a72..cb81388 100644 --- a/lib/pages/notifications/single_notif.dart +++ b/lib/pages/notifications/single_notif.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:loris/business_logic/notifications/notifs.dart'; import 'package:loris/dialogues/profile_view.dart'; +import 'package:loris/partials/name.dart'; import 'package:loris/partials/post.dart'; import '../../global.dart' as global; import 'package:loris/themes/themes.dart' as themes; @@ -49,9 +51,10 @@ class SingleNotif extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SelectableText( - model.account.displayName, - style: Theme.of(context).textTheme.displaySmall, + NameDisplay( + emoji: model.account.emojis, + content: model.account.displayName, + style: Theme.of(context).textTheme.displaySmall!, ), SelectableText.rich( TextSpan( diff --git a/lib/partials/name.dart b/lib/partials/name.dart new file mode 100644 index 0000000..683e9d4 --- /dev/null +++ b/lib/partials/name.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:loris/business_logic/emoji/emoji.dart'; + +class NameDisplay extends StatelessWidget { + const NameDisplay({ + super.key, + required this.emoji, + required this.content, + required this.style, + }); + final List emoji; + final String content; + final TextStyle style; + + @override + Widget build(BuildContext context) { + String newtext = content; + newtext = newtext + .replaceAll("~", r"\~") + .replaceAll("_", r"\_") + .replaceAll("*", r"\*"); + for (var e in emoji) { + newtext = insertEmojiInMd(newtext, e); + } + + return MarkdownBody( + data: newtext, + styleSheet: MarkdownStyleSheet(p: style), + imageBuilder: (uri, title, alt) { + try { + return Image.network( + uri.toString(), + height: style.fontSize, + errorBuilder: (context, error, stackTrace) => + SelectableText(alt ?? error.toString()), + ); + } catch (e) { + return SelectableText(alt ?? ""); + } + }); + } +} diff --git a/lib/partials/post.dart b/lib/partials/post.dart index b7d5574..02129f4 100644 --- a/lib/partials/post.dart +++ b/lib/partials/post.dart @@ -9,6 +9,7 @@ import 'package:loris/dialogues/makepost.dart'; import 'package:loris/dialogues/profile_view.dart'; import 'package:loris/partials/interaction_button.dart'; import 'package:loris/partials/media_attachment.dart'; +import 'package:loris/partials/name.dart'; import 'package:loris/partials/post_options.dart'; import 'package:loris/partials/post_text_renderer.dart'; import 'package:url_launcher/url_launcher_string.dart'; @@ -117,13 +118,11 @@ class DisplayName extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ - MarkdownBody( - data: dname, - selectable: true, - imageBuilder: (uri, title, alt) => Image.network( - uri.toString(), - height: usernameStyle?.fontSize), - styleSheet: MarkdownStyleSheet(p: usernameStyle)), + NameDisplay( + emoji: account.emojis, + content: account.displayName, + style: usernameStyle!, + ), SelectableText( account.acct, style: Theme.of(context).textTheme.bodySmall,