ente/lib/ui/search_tab.dart

95 lines
2.6 KiB
Dart
Raw Normal View History

2023-02-25 08:00:42 +00:00
import "package:flutter/material.dart";
import "package:photos/models/search/search_result.dart";
2023-02-25 08:00:42 +00:00
import "package:photos/models/search/search_types.dart";
import "package:photos/ui/common/loading_widget.dart";
2023-02-25 08:00:42 +00:00
import "package:photos/ui/viewer/search/search_section.dart";
import "package:photos/ui/viewer/search/search_widget.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-02-25 08:00:42 +00:00
// Focus nodes are necessary
String _email = '';
final textFieldFocusNode = FocusNode();
final _textController = TextEditingController();
2023-02-23 17:14:56 +00:00
@override
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.only(
2023-02-25 08:00:42 +00:00
left: 12.0,
right: 12.0,
bottom: 100,
),
child: Column(
children: [
Align(
2023-02-25 08:00:42 +00:00
alignment: Alignment.topRight,
child: SearchIconWidget(),
),
AllSearchSections(),
2023-02-25 08:00:42 +00:00
],
),
);
}
void clearFocus() {
_textController.clear();
_email = _textController.text;
textFieldFocusNode.unfocus();
setState(() => {});
2023-02-23 17:14:56 +00:00
}
}
class AllSearchSections extends StatefulWidget {
const AllSearchSections({super.key});
@override
State<AllSearchSections> createState() => _AllSearchSectionsState();
}
class _AllSearchSectionsState extends State<AllSearchSections> {
late Future<List<List<SearchResult>>> allFutures;
final locationTags = SectionType.location.getData(limit: 3);
@override
void initState() {
allFutures = Future.wait<List<SearchResult>>([locationTags]);
super.initState();
}
@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(
child: FutureBuilder(
future: allFutures,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: searchTypes.length,
itemBuilder: (context, index) {
return SearchSection(sectionType: searchTypes[index]);
},
);
} else if (snapshot.hasError) {
return const EnteLoadingWidget();
} else {
return const EnteLoadingWidget();
}
},
),
);
}
}