Skip to content

Commit

Permalink
fix: Highlight file event
Browse files Browse the repository at this point in the history
  • Loading branch information
drminh2807 authored and hoangdat committed Sep 27, 2023
1 parent 0abd8e0 commit e53a479
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
85 changes: 77 additions & 8 deletions lib/pages/chat/events/message_download_content.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,10 +18,13 @@ class MessageDownloadContent extends StatelessWidget {
final Event event;
final void Function(Event event) onFileTapped;

final ValueNotifier<Either<Failure, Success>>? searchStatus;

const MessageDownloadContent(
this.event, {
Key? key,
required this.onFileTapped,
this.searchStatus,
}) : super(key: key);

@override
Expand Down Expand Up @@ -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<ChatRoomSearchSuccess>();
final searchKeyword = success?.keyword ?? '';
return _FileNameWithSearchText(
filename: filename,
searchKeyword: searchKeyword,
);
},
),
overflow: TextOverflow.ellipsis,
),
] else ...[
_FileNameText(filename: filename),
],
Row(
children: [
if (sizeString != null)
Expand All @@ -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});
Expand Down

0 comments on commit e53a479

Please sign in to comment.