diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 2ffc3006bd..20eef6833f 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -177,6 +177,7 @@ class MessageContent extends StatelessWidget with PlayVideoActionMixin { MessageDownloadContent( event, onFileTapped: controller.onFileTapped, + searchStatus: controller.searchStatus, ), Padding( padding: const EdgeInsets.symmetric(vertical: 4), diff --git a/lib/pages/chat/events/message_download_content.dart b/lib/pages/chat/events/message_download_content.dart index c7093670b6..81d915dce5 100644 --- a/lib/pages/chat/events/message_download_content.dart +++ b/lib/pages/chat/events/message_download_content.dart @@ -1,5 +1,11 @@ +import 'package:dartz/dartz.dart'; +import 'package:fluffychat/app_state/failure.dart'; +import 'package:fluffychat/app_state/success.dart'; +import 'package:fluffychat/domain/app_state/room/chat_room_search_state.dart'; import 'package:fluffychat/domain/model/extensions/mime_type_extension.dart'; +import 'package:fluffychat/utils/string_extension.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_matrix_html/color_extension.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:linagora_design_flutter/colors/linagora_ref_colors.dart'; import 'package:linagora_design_flutter/colors/linagora_sys_colors.dart'; @@ -12,10 +18,13 @@ class MessageDownloadContent extends StatelessWidget { final Event event; final void Function(Event event) onFileTapped; + final ValueNotifier>? searchStatus; + const MessageDownloadContent( this.event, { Key? key, required this.onFileTapped, + this.searchStatus, }) : super(key: key); @override @@ -55,15 +64,22 @@ class MessageDownloadContent extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ - Text( - filename, - maxLines: 1, - style: TextStyle( - color: Theme.of(context).colorScheme.onBackground, - fontWeight: FontWeight.bold, + if (searchStatus != null) ...[ + ValueListenableBuilder( + valueListenable: searchStatus!, + builder: (context, searchStatusValue, child) { + final success = searchStatusValue + .getSuccessOrNull(); + final searchKeyword = success?.keyword ?? ''; + return _FileNameWithSearchText( + filename: filename, + searchKeyword: searchKeyword, + ); + }, ), - overflow: TextOverflow.ellipsis, - ), + ] else ...[ + _FileNameText(filename: filename), + ], Row( children: [ if (sizeString != null) @@ -86,6 +102,59 @@ class MessageDownloadContent extends StatelessWidget { } } +class _FileNameWithSearchText extends StatelessWidget { + const _FileNameWithSearchText({ + required this.filename, + required this.searchKeyword, + }); + + final String filename; + final String searchKeyword; + + @override + Widget build(BuildContext context) { + return RichText( + maxLines: 1, + text: TextSpan( + children: filename.buildHighlightTextSpans( + searchKeyword, + style: TextStyle( + color: Theme.of(context).colorScheme.onBackground, + fontWeight: FontWeight.bold, + ), + highlightStyle: TextStyle( + color: Theme.of(context).colorScheme.onBackground, + fontWeight: FontWeight.bold, + backgroundColor: CssColor.fromCss('gold'), + ), + ), + ), + overflow: TextOverflow.ellipsis, + ); + } +} + +class _FileNameText extends StatelessWidget { + const _FileNameText({ + required this.filename, + }); + + final String filename; + + @override + Widget build(BuildContext context) { + return Text( + filename, + maxLines: 1, + style: TextStyle( + color: Theme.of(context).colorScheme.onBackground, + fontWeight: FontWeight.bold, + ), + overflow: TextOverflow.ellipsis, + ); + } +} + class _TextInformationOfFile extends StatelessWidget { final String value; const _TextInformationOfFile({required this.value});