From 3f61abdc3dd5d33d3b56b09dbd5e868b2ce07969 Mon Sep 17 00:00:00 2001 From: Talha Gondal Date: Wed, 3 Aug 2022 02:38:28 +0500 Subject: [PATCH] markdown support for chatlist latest messages --- app/lib/common/widget/ChatOverview.dart | 70 ++++++++++++++++++++++++- app/pubspec.lock | 2 +- app/pubspec.yaml | 2 +- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/app/lib/common/widget/ChatOverview.dart b/app/lib/common/widget/ChatOverview.dart index 5cab479e4a29..70a10830dd93 100644 --- a/app/lib/common/widget/ChatOverview.dart +++ b/app/lib/common/widget/ChatOverview.dart @@ -1,11 +1,15 @@ // ignore_for_file: prefer_const_constructors, avoid_unnecessary_containers +import 'dart:io'; + import 'package:effektio/common/store/separatedThemes.dart'; import 'package:effektio/common/widget/AppCommon.dart'; import 'package:effektio/common/widget/customAvatar.dart'; import 'package:effektio/screens/HomeScreens/ChatScreen.dart'; import 'package:effektio_flutter_sdk/effektio_flutter_sdk_ffi.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_link_previewer/flutter_link_previewer.dart'; +import 'package:flutter_parsed_text/flutter_parsed_text.dart'; import 'package:intl/intl.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -89,10 +93,72 @@ class ChatListItem extends StatelessWidget { if (snapshot.hasData) { return Container( margin: const EdgeInsets.only(top: 10, bottom: 10), - child: Text( - '${getNameFromId(snapshot.requireData.sender())}: ${snapshot.requireData.body()}', + child: ParsedText( + text: + '${getNameFromId(snapshot.requireData.sender())}: ${snapshot.requireData.body()}', style: ChatTheme01.latestChatStyle, + regexOptions: const RegexOptions(multiLine: true, dotAll: true), maxLines: 2, + parse: [ + MatchText( + pattern: '(\\*\\*|\\*)(.*?)(\\*\\*|\\*)', + style: ChatTheme01.latestChatStyle + .copyWith(fontWeight: FontWeight.bold), + renderText: ({ + required String str, + required String pattern, + }) { + return { + 'display': str.replaceAll(RegExp('(\\*\\*|\\*)'), '') + }; + }, + ), + MatchText( + pattern: '_(.*?)_', + style: ChatTheme01.latestChatStyle + .copyWith(fontStyle: FontStyle.italic), + renderText: ({ + required String str, + required String pattern, + }) { + return {'display': str.replaceAll('_', '')}; + }, + ), + MatchText( + pattern: '~(.*?)~', + style: ChatTheme01.latestChatStyle.copyWith( + decoration: TextDecoration.lineThrough, + ), + renderText: ({ + required String str, + required String pattern, + }) { + return {'display': str.replaceAll('~', '')}; + }, + ), + MatchText( + pattern: '`(.*?)`', + style: ChatTheme01.latestChatStyle.copyWith( + fontFamily: Platform.isIOS ? 'Courier' : 'monospace', + ), + renderText: ({ + required String str, + required String pattern, + }) { + return {'display': str.replaceAll('`', '')}; + }, + ), + MatchText( + pattern: regexEmail, + style: ChatTheme01.latestChatStyle + .copyWith(decoration: TextDecoration.underline), + ), + MatchText( + pattern: regexLink, + style: ChatTheme01.latestChatStyle + .copyWith(decoration: TextDecoration.underline), + ), + ], ), ); } else { diff --git a/app/pubspec.lock b/app/pubspec.lock index 9f8642d0aae8..8f38ba0f9917 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -304,7 +304,7 @@ packages: source: sdk version: "0.0.0" flutter_parsed_text: - dependency: transitive + dependency: "direct main" description: name: flutter_parsed_text url: "https://pub.dartlang.org" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 5aca383d7734..f71154b84490 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -63,7 +63,7 @@ dependencies: expandable_text: ^2.3.0 get: ^4.6.5 characters: ^1.2.0 - + flutter_parsed_text: ^2.2.1 dev_dependencies: flutter_test: