2023-11-14 07:09:31 +00:00
|
|
|
import "package:fade_indexed_stack/fade_indexed_stack.dart";
|
2023-02-25 08:00:42 +00:00
|
|
|
import "package:flutter/material.dart";
|
2023-12-20 15:27:41 +00:00
|
|
|
import "package:flutter_animate/flutter_animate.dart";
|
2023-11-01 09:30:48 +00:00
|
|
|
import "package:photos/core/constants.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-11-03 16:07:24 +00:00
|
|
|
import "package:photos/states/all_sections_examples_state.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-31 11:04:32 +00:00
|
|
|
import "package:photos/ui/viewer/search/tab_empty_state.dart";
|
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-12-21 12:11:55 +00:00
|
|
|
// var _searchResults = <SearchResult>[];
|
|
|
|
late Stream<List<SearchResult>>? _searchResults;
|
2023-10-31 10:13:28 +00:00
|
|
|
int index = 0;
|
2023-10-24 07:27:59 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
super.didChangeDependencies();
|
2023-12-21 12:11:55 +00:00
|
|
|
_searchResults = InheritedSearchResults.of(context).searchResultsStream;
|
2023-12-23 13:18:28 +00:00
|
|
|
print(
|
|
|
|
"____ Updating dependencies for SearchTabState. New stream : ${_searchResults.hashCode}",
|
|
|
|
);
|
2023-12-21 12:11:55 +00:00
|
|
|
// if (_searchResults.isEmpty) {
|
|
|
|
// if (isSearchQueryEmpty) {
|
|
|
|
// index = 0;
|
|
|
|
// } else {
|
|
|
|
// index = 2;
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// index = 1;
|
|
|
|
// }
|
|
|
|
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-12-23 13:18:28 +00:00
|
|
|
print("_____ rebuilding SearchTab with stream: ${_searchResults.hashCode}");
|
2023-12-20 13:50:05 +00:00
|
|
|
return AllSectionsExamplesProvider(
|
|
|
|
child: FadeIndexedStack(
|
|
|
|
duration: const Duration(milliseconds: 150),
|
|
|
|
index: index,
|
|
|
|
children: [
|
|
|
|
const AllSearchSections(),
|
|
|
|
SearchSuggestionsWidget(_searchResults),
|
|
|
|
const NoResultWidget(),
|
|
|
|
],
|
2023-10-31 10:13:28 +00:00
|
|
|
),
|
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> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final searchTypes = SectionType.values.toList(growable: true);
|
|
|
|
// remove face and content sectionType
|
|
|
|
searchTypes.remove(SectionType.face);
|
|
|
|
searchTypes.remove(SectionType.content);
|
2023-12-20 13:50:05 +00:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
FutureBuilder(
|
|
|
|
future: InheritedAllSectionsExamples.of(context)
|
|
|
|
.allSectionsExamplesFuture,
|
|
|
|
builder: (context, snapshot) {
|
2023-12-20 15:09:33 +00:00
|
|
|
if (snapshot.hasData && snapshot.data!.isNotEmpty) {
|
2023-12-20 13:50:05 +00:00
|
|
|
if (snapshot.data!.every((element) => element.isEmpty)) {
|
|
|
|
return const Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 72),
|
|
|
|
child: SearchTabEmptyState(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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: searchSectionLimit,
|
|
|
|
);
|
|
|
|
},
|
2023-12-20 15:27:41 +00:00
|
|
|
)
|
|
|
|
.animate(
|
|
|
|
delay: const Duration(milliseconds: 150),
|
|
|
|
)
|
|
|
|
.slide(
|
|
|
|
begin: const Offset(0, -0.015),
|
|
|
|
end: const Offset(0, 0),
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
curve: Curves.easeOut,
|
|
|
|
)
|
|
|
|
.fadeIn(
|
|
|
|
duration: const Duration(milliseconds: 150),
|
|
|
|
curve: Curves.easeOut,
|
|
|
|
);
|
2023-12-20 13:50:05 +00:00
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
//Errors are handled and this else if condition will be false always
|
|
|
|
//is the understanding.
|
2023-11-14 06:55:56 +00:00
|
|
|
return const Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 72),
|
2023-12-20 13:50:05 +00:00
|
|
|
child: EnteLoadingWidget(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 72),
|
|
|
|
child: EnteLoadingWidget(),
|
2023-11-14 06:55:56 +00:00
|
|
|
);
|
|
|
|
}
|
2023-12-20 13:50:05 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ValueListenableBuilder(
|
|
|
|
valueListenable:
|
|
|
|
InheritedAllSectionsExamples.of(context).isDebouncingNotifier,
|
|
|
|
builder: (context, value, _) {
|
|
|
|
return value
|
|
|
|
? const EnteLoadingWidget(
|
|
|
|
alignment: Alignment.topRight,
|
|
|
|
)
|
|
|
|
: const SizedBox.shrink();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-10-06 12:35:11 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|