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

135 lines
4.3 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';
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();
2022-07-27 07:30:51 +00:00
return GestureDetector(
behavior: HitTestBehavior.opaque,
2022-08-05 16:56:06 +00:00
child: Container(
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,
),
const SizedBox(width: 16),
2022-08-11 14:45:42 +00:00
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2022-09-14 09:11:29 +00:00
_resultTypeName(searchResult.type()),
2022-08-11 14:45:42 +00:00
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.subTextColor,
2022-07-28 05:54:40 +00:00
),
2022-08-11 14:45:42 +00:00
),
2022-08-20 10:41:05 +00:00
const SizedBox(height: 6),
SizedBox(
width: 220,
child: Text(
2022-09-14 08:33:12 +00:00
searchResult.name(),
style: const TextStyle(fontSize: 18),
overflow: TextOverflow.ellipsis,
),
2022-08-11 14:45:42 +00:00
),
const SizedBox(height: 2),
FutureBuilder<int>(
2022-09-14 08:33:12 +00:00
future: resultCount ??
Future.value(searchResult.resultFiles().length),
2022-08-11 14:45:42 +00:00
builder: (context, snapshot) {
2022-09-14 08:33:12 +00:00
if (snapshot.hasData && snapshot.data! > 0) {
2022-08-11 14:45:42 +00:00
final noOfMemories = snapshot.data;
return RichText(
text: TextSpan(
style: TextStyle(
color: Theme.of(context)
.colorScheme
.searchResultsCountTextColor,
2022-08-05 16:56:06 +00:00
),
2022-08-11 14:45:42 +00:00
children: [
TextSpan(text: noOfMemories.toString()),
TextSpan(
text:
noOfMemories != 1 ? ' memories' : ' memory',
),
],
),
);
} else {
return const SizedBox.shrink();
}
},
2022-09-14 08:33:12 +00:00
)
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:
return "Memory";
case ResultType.event:
return "Day";
case ResultType.location:
return "Location";
case ResultType.fileType:
return "Type";
case ResultType.fileExtension:
return "File Extension";
2022-11-05 05:30:03 +00:00
case ResultType.fileCaption:
return "Caption";
2022-09-14 09:11:29 +00:00
default:
return type.name.toUpperCase();
}
}
2022-07-27 07:30:51 +00:00
}