|
@@ -1,10 +1,13 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
+import 'package:photos/db/files_db.dart';
|
|
|
import 'package:photos/ente_theme_data.dart';
|
|
|
import 'package:photos/models/collection_items.dart';
|
|
|
+import 'package:photos/models/file.dart';
|
|
|
import 'package:photos/services/collections_service.dart';
|
|
|
import 'package:photos/ui/viewer/search/search_results_suggestions.dart';
|
|
|
|
|
|
class SearchIconWidget extends StatefulWidget {
|
|
|
+ final String searchQuery = '';
|
|
|
const SearchIconWidget({Key key}) : super(key: key);
|
|
|
|
|
|
@override
|
|
@@ -12,6 +15,7 @@ class SearchIconWidget extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class _SearchIconWidgetState extends State<SearchIconWidget> {
|
|
|
+ final ValueNotifier<String> _searchQuery = ValueNotifier('');
|
|
|
bool showSearchWidget;
|
|
|
@override
|
|
|
void initState() {
|
|
@@ -21,8 +25,11 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
+ List<CollectionWithThumbnail> matchedCollections = [];
|
|
|
+ List<File> matchedFiles = [];
|
|
|
+ //when false - show the search icon, when true - show the textfield for search
|
|
|
return showSearchWidget
|
|
|
- ? Searchwidget(showSearchWidget)
|
|
|
+ ? searchWidget(matchedCollections, matchedFiles)
|
|
|
: IconButton(
|
|
|
onPressed: () {
|
|
|
setState(
|
|
@@ -34,82 +41,71 @@ class _SearchIconWidgetState extends State<SearchIconWidget> {
|
|
|
icon: const Icon(Icons.search),
|
|
|
);
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-// ignore: must_be_immutable
|
|
|
-class Searchwidget extends StatefulWidget {
|
|
|
- bool openSearch;
|
|
|
- final String searchQuery = '';
|
|
|
- Searchwidget(this.openSearch, {Key key}) : super(key: key);
|
|
|
- @override
|
|
|
- State<Searchwidget> createState() => _SearchwidgetState();
|
|
|
-}
|
|
|
-
|
|
|
-class _SearchwidgetState extends State<Searchwidget> {
|
|
|
- final ValueNotifier<String> _searchQ = ValueNotifier('');
|
|
|
- @override
|
|
|
- Widget build(BuildContext context) {
|
|
|
- List<CollectionWithThumbnail> matchedCollections;
|
|
|
- return widget.openSearch
|
|
|
- ? Column(
|
|
|
- children: [
|
|
|
- Row(
|
|
|
- children: [
|
|
|
- const SizedBox(width: 12),
|
|
|
- Flexible(
|
|
|
- child: Container(
|
|
|
- color:
|
|
|
- Theme.of(context).colorScheme.defaultBackgroundColor,
|
|
|
- child: TextFormField(
|
|
|
- style: Theme.of(context).textTheme.subtitle1,
|
|
|
- decoration: InputDecoration(
|
|
|
- filled: true,
|
|
|
- contentPadding: const EdgeInsets.symmetric(
|
|
|
- horizontal: 16,
|
|
|
- vertical: 14,
|
|
|
- ),
|
|
|
- border: UnderlineInputBorder(
|
|
|
- borderSide: BorderSide.none,
|
|
|
- borderRadius: BorderRadius.circular(8),
|
|
|
- ),
|
|
|
- prefixIcon: const Icon(Icons.search),
|
|
|
- ),
|
|
|
- onChanged: (value) async {
|
|
|
- matchedCollections = await CollectionsService.instance
|
|
|
- .getFilteredCollectionsWithThumbnail(value);
|
|
|
- _searchQ.value = value;
|
|
|
- },
|
|
|
- autofocus: true,
|
|
|
- ),
|
|
|
+ Widget searchWidget(
|
|
|
+ List<CollectionWithThumbnail> matchedCollections,
|
|
|
+ List<File> matchedFiles,
|
|
|
+ ) {
|
|
|
+ return Column(
|
|
|
+ children: [
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ const SizedBox(width: 12),
|
|
|
+ Flexible(
|
|
|
+ child: Container(
|
|
|
+ color: Theme.of(context).colorScheme.defaultBackgroundColor,
|
|
|
+ child: TextFormField(
|
|
|
+ style: Theme.of(context).textTheme.subtitle1,
|
|
|
+ decoration: InputDecoration(
|
|
|
+ filled: true,
|
|
|
+ contentPadding: const EdgeInsets.symmetric(
|
|
|
+ horizontal: 16,
|
|
|
+ vertical: 14,
|
|
|
),
|
|
|
+ border: UnderlineInputBorder(
|
|
|
+ borderSide: BorderSide.none,
|
|
|
+ borderRadius: BorderRadius.circular(8),
|
|
|
+ ),
|
|
|
+ prefixIcon: const Icon(Icons.search),
|
|
|
),
|
|
|
- IconButton(
|
|
|
- onPressed: () {
|
|
|
- setState(() {
|
|
|
- widget.openSearch = !widget.openSearch;
|
|
|
- });
|
|
|
- },
|
|
|
- icon: const Icon(Icons.close),
|
|
|
- ),
|
|
|
- ],
|
|
|
+ onChanged: (value) async {
|
|
|
+ matchedCollections = await CollectionsService.instance
|
|
|
+ .getFilteredCollectionsWithThumbnail(value);
|
|
|
+ matchedFiles =
|
|
|
+ await FilesDB.instance.getFilesOnFileNameSearch(value);
|
|
|
+ _searchQuery.value = value;
|
|
|
+ },
|
|
|
+ autofocus: true,
|
|
|
+ ),
|
|
|
),
|
|
|
- const SizedBox(height: 20),
|
|
|
- ValueListenableBuilder(
|
|
|
- valueListenable: _searchQ,
|
|
|
- builder: (
|
|
|
- BuildContext context,
|
|
|
- String newQuery,
|
|
|
- Widget child,
|
|
|
- ) {
|
|
|
- return newQuery != ''
|
|
|
- ? SearchResultsSuggestions(
|
|
|
- collectionsWithThumbnail: matchedCollections,
|
|
|
- )
|
|
|
- : const SizedBox.shrink();
|
|
|
- },
|
|
|
- ),
|
|
|
- ],
|
|
|
- )
|
|
|
- : SearchIconWidget();
|
|
|
+ ),
|
|
|
+ IconButton(
|
|
|
+ onPressed: () {
|
|
|
+ setState(() {
|
|
|
+ showSearchWidget = !showSearchWidget;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ icon: const Icon(Icons.close),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ const SizedBox(height: 20),
|
|
|
+ ValueListenableBuilder(
|
|
|
+ valueListenable: _searchQuery,
|
|
|
+ builder: (
|
|
|
+ BuildContext context,
|
|
|
+ String newQuery,
|
|
|
+ Widget child,
|
|
|
+ ) {
|
|
|
+ return newQuery != ''
|
|
|
+ ? SearchResultsSuggestions(
|
|
|
+ matchedCollections,
|
|
|
+ matchedFiles,
|
|
|
+ )
|
|
|
+ : const SizedBox.shrink();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ );
|
|
|
}
|
|
|
}
|