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

111 lines
3.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import "package:photos/models/search/search_types.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/search_tab.dart";
class NoResultWidget extends StatefulWidget {
2022-12-27 12:23:25 +00:00
const NoResultWidget({Key? key}) : super(key: key);
@override
State<NoResultWidget> createState() => _NoResultWidgetState();
}
class _NoResultWidgetState extends State<NoResultWidget> {
late final List<SectionType> searchTypes;
2023-10-26 08:28:45 +00:00
final searchTypeToQuerySuggestion = <String, List<String>>{};
@override
void initState() {
super.initState();
searchTypes = SectionType.values.toList(growable: true);
// remove face and content sectionType
searchTypes.remove(SectionType.face);
searchTypes.remove(SectionType.content);
2023-10-31 10:48:01 +00:00
allSectionsExamplesFuture.then((value) {
for (int i = 0; i < searchTypes.length; i++) {
final querySuggestions = <String>[];
for (int j = 0; j < 2 && j < value[i].length; j++) {
querySuggestions.add(value[i][j].name());
}
if (querySuggestions.isNotEmpty) {
searchTypeToQuerySuggestion
.addAll({searchTypes[i].sectionTitle(context): querySuggestions});
}
}
2023-10-26 08:35:48 +00:00
setState(() {});
});
}
@override
Widget build(BuildContext context) {
final textTheme = getEnteTextTheme(context);
2023-10-26 08:28:45 +00:00
final searchTypeAndSuggestion = <Widget>[];
searchTypeToQuerySuggestion.forEach(
(key, value) {
2023-10-26 08:28:45 +00:00
searchTypeAndSuggestion.add(
Row(
children: [
Text(
key,
style: textTheme.bodyMuted,
),
const SizedBox(width: 6),
2023-10-26 08:35:48 +00:00
Flexible(
child: Text(
formatList(value),
style: textTheme.miniMuted,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
2023-10-31 10:14:58 +00:00
),
);
},
);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
// S.of(context).noResults,
"No results found",
style: textTheme.largeBold,
2023-10-31 10:14:58 +00:00
),
const SizedBox(height: 6),
searchTypeToQuerySuggestion.isNotEmpty
? Text(
"Modify your query, or try searching for",
style: textTheme.smallMuted,
)
: const SizedBox.shrink(),
],
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: ListView.separated(
itemBuilder: (context, index) {
2023-10-26 08:28:45 +00:00
return searchTypeAndSuggestion[index];
},
separatorBuilder: (context, index) {
return const SizedBox(height: 12);
},
2023-10-26 08:28:45 +00:00
itemCount: searchTypeToQuerySuggestion.length,
shrinkWrap: true,
),
),
],
),
);
}
String formatList(List<String> strings) {
// Join the strings with ', ' and wrap each element with double quotes
return strings.map((str) => '"$str"').join(', ');
}
}