2022-07-18 04:45:06 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-07-27 11:51:43 +00:00
|
|
|
import 'package:photos/db/files_db.dart';
|
2022-07-18 04:45:06 +00:00
|
|
|
import 'package:photos/ente_theme_data.dart';
|
2022-08-05 04:52:47 +00:00
|
|
|
import 'package:photos/models/collection_items.dart';
|
|
|
|
import 'package:photos/models/file.dart';
|
2022-08-04 16:16:16 +00:00
|
|
|
import 'package:photos/models/search/album_search_result.dart';
|
|
|
|
import 'package:photos/models/search/file_search_result.dart';
|
|
|
|
import 'package:photos/models/search/search_results.dart';
|
2022-07-19 09:21:52 +00:00
|
|
|
import 'package:photos/services/collections_service.dart';
|
2022-07-29 05:27:39 +00:00
|
|
|
import 'package:photos/services/user_service.dart';
|
2022-07-25 10:24:06 +00:00
|
|
|
import 'package:photos/ui/viewer/search/search_results_suggestions.dart';
|
2022-07-18 04:45:06 +00:00
|
|
|
|
|
|
|
class SearchIconWidget extends StatefulWidget {
|
2022-07-28 05:08:20 +00:00
|
|
|
const SearchIconWidget({Key key}) : super(key: key);
|
2022-07-18 04:45:06 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<SearchIconWidget> createState() => _SearchIconWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchIconWidgetState extends State<SearchIconWidget> {
|
2022-07-28 05:08:20 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2022-07-18 04:45:06 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-05 07:21:39 +00:00
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(
|
|
|
|
() {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => const SearchWidget(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.search),
|
|
|
|
);
|
2022-07-18 04:45:06 +00:00
|
|
|
}
|
2022-08-05 06:12:16 +00:00
|
|
|
}
|
2022-07-18 04:45:06 +00:00
|
|
|
|
2022-08-05 06:12:16 +00:00
|
|
|
class SearchWidget extends StatefulWidget {
|
|
|
|
final String searchQuery = '';
|
2022-08-05 07:21:39 +00:00
|
|
|
const SearchWidget({Key key}) : super(key: key);
|
2022-08-05 06:12:16 +00:00
|
|
|
@override
|
|
|
|
State<SearchWidget> createState() => _SearchWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchWidgetState extends State<SearchWidget> {
|
|
|
|
final List<SearchResult> results = [];
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-05 07:21:39 +00:00
|
|
|
return SafeArea(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
2022-08-05 06:12:16 +00:00
|
|
|
children: [
|
2022-08-05 07:21:39 +00:00
|
|
|
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),
|
2022-08-05 06:12:16 +00:00
|
|
|
),
|
2022-08-05 07:21:39 +00:00
|
|
|
prefixIcon: const Icon(Icons.search),
|
2022-07-28 07:52:20 +00:00
|
|
|
),
|
2022-08-05 07:21:39 +00:00
|
|
|
onChanged: (value) async {
|
|
|
|
List<SearchResult> combinedResults = [];
|
|
|
|
|
|
|
|
final collectionResults = await CollectionsService
|
|
|
|
.instance
|
|
|
|
.getFilteredCollectionsWithThumbnail(value);
|
|
|
|
for (CollectionWithThumbnail collectionResult
|
|
|
|
in collectionResults) {
|
|
|
|
combinedResults
|
|
|
|
.add(AlbumSearchResult(collectionResult));
|
|
|
|
}
|
|
|
|
final locationResults = await UserService.instance
|
|
|
|
.getLocationsToMatchedFiles(value);
|
|
|
|
for (final result in locationResults) {
|
|
|
|
combinedResults.add(result);
|
|
|
|
}
|
|
|
|
final fileResults = await FilesDB.instance
|
|
|
|
.getFilesOnFileNameSearch(value);
|
|
|
|
for (File file in fileResults) {
|
|
|
|
combinedResults.add(FileSearchResult(file));
|
|
|
|
}
|
2022-08-05 06:12:16 +00:00
|
|
|
setState(() {
|
2022-08-05 07:21:39 +00:00
|
|
|
results.clear();
|
|
|
|
results.addAll(combinedResults);
|
2022-08-05 06:12:16 +00:00
|
|
|
});
|
|
|
|
},
|
2022-08-05 07:21:39 +00:00
|
|
|
autofocus: true,
|
2022-08-05 06:12:16 +00:00
|
|
|
),
|
2022-08-05 07:21:39 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
Navigator.pop(context);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.close),
|
2022-07-20 10:57:45 +00:00
|
|
|
),
|
2022-08-05 06:12:16 +00:00
|
|
|
],
|
2022-08-05 07:21:39 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
|
|
|
|
SearchResultsSuggestionsWidget(results),
|
|
|
|
// const SizedBox.shrink();
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-07-18 04:45:06 +00:00
|
|
|
}
|
|
|
|
}
|