ente/lib/ui/viewer/search/result/search_result_widget.dart

131 lines
4.1 KiB
Dart
Raw Normal View History

2022-07-27 07:30:51 +00:00
import 'package:flutter/material.dart';
import 'package:photos/ente_theme_data.dart';
2022-09-14 08:40:35 +00:00
import 'package:photos/models/search/search_result.dart';
2023-02-24 07:56:33 +00:00
import "package:photos/models/search/search_types.dart";
2023-10-16 11:15:28 +00:00
import "package:photos/theme/ente_theme.dart";
2022-09-14 08:33:12 +00:00
import 'package:photos/ui/viewer/search/result/search_result_page.dart';
import 'package:photos/ui/viewer/search/result/search_thumbnail_widget.dart';
2022-07-27 07:30:51 +00:00
import 'package:photos/utils/navigation_util.dart';
2022-09-14 08:33:12 +00:00
class SearchResultWidget extends StatelessWidget {
final SearchResult searchResult;
final Future<int>? resultCount;
final Function? onResultTap;
2022-07-28 05:08:20 +00:00
2022-09-14 08:33:12 +00:00
const SearchResultWidget(
this.searchResult, {
Key? key,
this.resultCount,
this.onResultTap,
}) : super(key: key);
2022-07-27 07:30:51 +00:00
@override
Widget build(BuildContext context) {
2022-09-14 08:33:12 +00:00
final heroTagPrefix = searchResult.heroTag();
2023-10-16 11:15:28 +00:00
final textTheme = getEnteTextTheme(context);
2022-09-14 08:33:12 +00:00
2022-07-27 07:30:51 +00:00
return GestureDetector(
behavior: HitTestBehavior.opaque,
2022-08-05 16:56:06 +00:00
child: Container(
2023-10-16 11:15:28 +00:00
//todo: check and change color to figma
2022-08-05 16:56:06 +00:00
color: Theme.of(context).colorScheme.searchResultsColor,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
child: Row(
2022-09-14 08:33:12 +00:00
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2022-08-05 16:56:06 +00:00
crossAxisAlignment: CrossAxisAlignment.center,
children: [
2022-09-14 08:33:12 +00:00
SearchThumbnailWidget(
searchResult.previewThumbnail(),
heroTagPrefix,
),
2023-10-16 11:15:28 +00:00
const SizedBox(width: 12),
2022-08-11 14:45:42 +00:00
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 220,
child: Text(
2022-09-14 08:33:12 +00:00
searchResult.name(),
2023-10-16 11:15:28 +00:00
style: textTheme.body,
overflow: TextOverflow.ellipsis,
),
2022-08-11 14:45:42 +00:00
),
2023-10-16 11:15:28 +00:00
const SizedBox(height: 4),
Row(
children: [
Text(
_resultTypeName(searchResult.type()),
style: textTheme.smallMuted,
),
FutureBuilder<int>(
future: resultCount ??
Future.value(searchResult.resultFiles().length),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data! > 0) {
final noOfMemories = snapshot.data;
return Text(
" \u2022 " + noOfMemories.toString(),
style: textTheme.smallMuted,
);
} else {
return const SizedBox.shrink();
}
},
),
],
2023-08-19 11:39:56 +00:00
),
2023-10-16 11:15:28 +00:00
const SizedBox(height: 2),
2022-08-11 14:45:42 +00:00
],
),
const Spacer(),
Icon(
Icons.chevron_right,
color: Theme.of(context).colorScheme.subTextColor,
),
2022-08-05 16:56:06 +00:00
],
),
2022-07-27 07:30:51 +00:00
),
),
onTap: () {
2022-09-14 08:33:12 +00:00
if (onResultTap != null) {
onResultTap!();
} else {
routeToPage(
context,
SearchResultPage(searchResult),
);
}
2022-07-27 07:30:51 +00:00
},
);
}
2022-09-14 09:11:29 +00:00
String _resultTypeName(ResultType type) {
switch (type) {
case ResultType.collection:
return "Album";
case ResultType.year:
return "Year";
case ResultType.month:
return "Month";
case ResultType.file:
2022-12-26 17:22:17 +00:00
return "File name";
2022-09-14 09:11:29 +00:00
case ResultType.event:
return "Day";
case ResultType.location:
return "Location";
case ResultType.fileType:
return "Type";
case ResultType.fileExtension:
2022-12-26 17:22:17 +00:00
return "File extension";
2022-11-05 05:30:03 +00:00
case ResultType.fileCaption:
return "Description";
case ResultType.shared:
return "Shared";
2022-09-14 09:11:29 +00:00
default:
return type.name.toUpperCase();
}
}
2022-07-27 07:30:51 +00:00
}