Skip to content

Commit

Permalink
Merge pull request #191 from gtalha07/main
Browse files Browse the repository at this point in the history
Markdown support for chat list latest messages.
  • Loading branch information
gtalha07 committed Aug 2, 2022
2 parents 771c8c7 + 95a5709 commit 93347d5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
70 changes: 68 additions & 2 deletions 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';

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.lock
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Expand Up @@ -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:
Expand Down

0 comments on commit 93347d5

Please sign in to comment.