2023-02-25 08:00:42 +00:00
|
|
|
import "package:flutter/material.dart";
|
2023-10-06 12:35:11 +00:00
|
|
|
import "package:photos/models/search/search_result.dart";
|
2023-02-25 08:00:42 +00:00
|
|
|
import "package:photos/models/search/search_types.dart";
|
2023-10-24 07:27:59 +00:00
|
|
|
import "package:photos/states/search_results_state.dart";
|
2023-10-06 12:35:11 +00:00
|
|
|
import "package:photos/ui/common/loading_widget.dart";
|
2023-10-24 08:37:36 +00:00
|
|
|
import "package:photos/ui/viewer/search/result/no_result_widget.dart";
|
2023-02-25 08:00:42 +00:00
|
|
|
import "package:photos/ui/viewer/search/search_section.dart";
|
2023-10-24 07:27:59 +00:00
|
|
|
import "package:photos/ui/viewer/search/search_suggestions.dart";
|
2023-10-24 08:37:36 +00:00
|
|
|
import "package:photos/ui/viewer/search/search_widget_new.dart";
|
2023-02-23 17:14:56 +00:00
|
|
|
|
2023-10-25 14:35:14 +00:00
|
|
|
late Future<List<List<SearchResult>>> allSectionsExamples;
|
|
|
|
|
2023-02-23 17:14:56 +00:00
|
|
|
class SearchTab extends StatefulWidget {
|
|
|
|
const SearchTab({Key? key}) : super(key: key);
|
2023-02-25 08:00:42 +00:00
|
|
|
|
2023-02-23 17:14:56 +00:00
|
|
|
@override
|
|
|
|
State<SearchTab> createState() => _SearchTabState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchTabState extends State<SearchTab> {
|
2023-02-25 08:00:42 +00:00
|
|
|
// Focus nodes are necessary
|
2023-10-24 07:27:59 +00:00
|
|
|
var _searchResults = <SearchResult>[];
|
2023-10-31 10:13:28 +00:00
|
|
|
int index = 0;
|
2023-10-24 07:27:59 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
|
|
|
_searchResults = InheritedSearchResults.of(context).results;
|
2023-10-31 10:13:28 +00:00
|
|
|
if (_searchResults.isEmpty) {
|
|
|
|
if (isSearchQueryEmpty) {
|
|
|
|
index = 0;
|
|
|
|
} else {
|
|
|
|
index = 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
index = 1;
|
|
|
|
}
|
2023-10-24 07:27:59 +00:00
|
|
|
}
|
2023-02-25 08:00:42 +00:00
|
|
|
|
2023-02-23 17:14:56 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-10-24 07:27:59 +00:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
2023-10-31 10:13:28 +00:00
|
|
|
child: IndexedStack(
|
|
|
|
index: index,
|
|
|
|
children: [
|
|
|
|
const AllSearchSections(),
|
|
|
|
SearchSuggestionsWidget(_searchResults),
|
|
|
|
const NoResultWidget(),
|
|
|
|
],
|
|
|
|
),
|
2023-02-25 08:00:42 +00:00
|
|
|
);
|
|
|
|
}
|
2023-02-23 17:14:56 +00:00
|
|
|
}
|
2023-10-06 12:35:11 +00:00
|
|
|
|
|
|
|
class AllSearchSections extends StatefulWidget {
|
|
|
|
const AllSearchSections({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AllSearchSections> createState() => _AllSearchSectionsState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AllSearchSectionsState extends State<AllSearchSections> {
|
2023-10-13 06:55:45 +00:00
|
|
|
late List<Future<List<SearchResult>>> sectionExamples;
|
2023-10-16 14:05:47 +00:00
|
|
|
static const _limit = 7;
|
2023-10-09 07:12:51 +00:00
|
|
|
|
2023-10-06 12:35:11 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2023-10-13 06:55:45 +00:00
|
|
|
super.initState();
|
|
|
|
sectionExamples = <Future<List<SearchResult>>>[];
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
2023-10-09 07:12:51 +00:00
|
|
|
for (SectionType sectionType in SectionType.values) {
|
|
|
|
if (sectionType == SectionType.face ||
|
|
|
|
sectionType == SectionType.content) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-10-16 14:05:47 +00:00
|
|
|
sectionExamples.add(sectionType.getData(limit: _limit, context: context));
|
2023-10-09 07:12:51 +00:00
|
|
|
}
|
2023-10-09 12:47:44 +00:00
|
|
|
allSectionsExamples = Future.wait<List<SearchResult>>(sectionExamples);
|
2023-10-06 12:35:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
// Return a ListViewBuilder for value search_types.dart SectionType,
|
|
|
|
// render search section for each value
|
|
|
|
final searchTypes = SectionType.values.toList(growable: true);
|
|
|
|
// remove face and content sectionType
|
|
|
|
searchTypes.remove(SectionType.face);
|
|
|
|
searchTypes.remove(SectionType.content);
|
|
|
|
return Expanded(
|
2023-10-18 13:05:54 +00:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
FutureBuilder(
|
|
|
|
future: allSectionsExamples,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return ListView.builder(
|
|
|
|
padding: const EdgeInsets.only(bottom: 180),
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
itemCount: searchTypes.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return SearchSection(
|
|
|
|
sectionType: searchTypes[index],
|
|
|
|
examples: snapshot.data!.elementAt(index),
|
|
|
|
limit: _limit,
|
|
|
|
);
|
|
|
|
},
|
2023-10-07 07:41:15 +00:00
|
|
|
);
|
2023-10-18 13:05:54 +00:00
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
//todo: Show something went wrong here
|
|
|
|
return const EnteLoadingWidget();
|
|
|
|
} else {
|
|
|
|
return const EnteLoadingWidget();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2023-10-06 12:35:11 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|