import 'package:flutter/material.dart'; import "package:photos/generated/l10n.dart"; import "package:photos/models/search/search_types.dart"; import "package:photos/states/all_sections_examples_state.dart"; import "package:photos/theme/ente_theme.dart"; class NoResultWidget extends StatefulWidget { const NoResultWidget({Key? key}) : super(key: key); @override State createState() => _NoResultWidgetState(); } class _NoResultWidgetState extends State { late final List searchTypes; final searchTypeToQuerySuggestion = >{}; @override void initState() { super.initState(); searchTypes = SectionType.values.toList(growable: true); // remove face and content sectionType searchTypes.remove(SectionType.face); searchTypes.remove(SectionType.content); } @override void didChangeDependencies() { super.didChangeDependencies(); InheritedAllSectionsExamples.of(context) .allSectionsExamplesFuture .then((value) { for (int i = 0; i < searchTypes.length; i++) { final querySuggestions = []; 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, }); } } setState(() {}); }); } @override Widget build(BuildContext context) { final textTheme = getEnteTextTheme(context); final searchTypeAndSuggestion = []; searchTypeToQuerySuggestion.forEach( (key, value) { searchTypeAndSuggestion.add( Row( children: [ Text( key, style: textTheme.bodyMuted, ), const SizedBox(width: 6), Flexible( child: Text( formatList(value), style: textTheme.miniMuted, maxLines: 1, overflow: TextOverflow.ellipsis, ), ), ], ), ); }, ); 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).noResultsFound, style: textTheme.largeBold, ), const SizedBox(height: 6), searchTypeToQuerySuggestion.isNotEmpty ? Text( S.of(context).modifyYourQueryOrTrySearchingFor, style: textTheme.smallMuted, ) : const SizedBox.shrink(), ], ), const SizedBox(height: 20), Padding( padding: const EdgeInsets.symmetric(horizontal: 4), child: ListView.separated( itemBuilder: (context, index) { return searchTypeAndSuggestion[index]; }, separatorBuilder: (context, index) { return const SizedBox(height: 12); }, itemCount: searchTypeToQuerySuggestion.length, shrinkWrap: true, ), ), ], ), ); } /// Join the strings with ', ' and wrap each element with double quotes String formatList(List strings) { return strings.map((str) => '"$str"').join(', '); } }