fixed query filter
This commit is contained in:
parent
54ba3c977f
commit
94b8ddc854
4 changed files with 59 additions and 42 deletions
|
@ -6,12 +6,12 @@ import 'package:outline_material_icons/outline_material_icons.dart';
|
||||||
class QueryFilter extends CollectionFilter {
|
class QueryFilter extends CollectionFilter {
|
||||||
static const type = 'query';
|
static const type = 'query';
|
||||||
|
|
||||||
final String query;
|
final String query, upQuery;
|
||||||
|
|
||||||
const QueryFilter(this.query);
|
QueryFilter(this.query) : upQuery = query.toUpperCase();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool filter(ImageEntry entry) => entry.search(query);
|
bool filter(ImageEntry entry) => entry.search(upQuery);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isUnique => false;
|
bool get isUnique => false;
|
||||||
|
@ -32,5 +32,5 @@ class QueryFilter extends CollectionFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => hashValues('MetadataFilter', query);
|
int get hashCode => hashValues('QueryFilter', query);
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,9 +205,9 @@ class ImageEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool search(String query) {
|
bool search(String query) {
|
||||||
if (title.toLowerCase().contains(query)) return true;
|
if (title?.toUpperCase()?.contains(query) ?? false) return true;
|
||||||
if (catalogMetadata?.xmpSubjects?.toLowerCase()?.contains(query) ?? false) return true;
|
if (catalogMetadata?.xmpSubjects?.toUpperCase()?.contains(query) ?? false) return true;
|
||||||
if (isLocated && addressDetails.addressLine.toLowerCase().contains(query)) return true;
|
if (addressDetails?.addressLine?.toUpperCase()?.contains(query) ?? false) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import 'package:aves/model/filters/filters.dart';
|
import 'package:aves/model/filters/filters.dart';
|
||||||
import 'package:aves/utils/constants.dart';
|
import 'package:aves/utils/constants.dart';
|
||||||
import 'package:aves/widgets/album/search/search_delegate.dart';
|
|
||||||
import 'package:aves/widgets/common/aves_filter_chip.dart';
|
import 'package:aves/widgets/common/aves_filter_chip.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:outline_material_icons/outline_material_icons.dart';
|
import 'package:outline_material_icons/outline_material_icons.dart';
|
||||||
|
@ -47,9 +46,12 @@ class ExpandableFilterRow extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
final filtersList = filters.toList();
|
final filtersList = filters.toList();
|
||||||
final filterChips = isExpanded
|
final wrap = Container(
|
||||||
? Padding(
|
key: ValueKey('wrap$title'),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: AvesFilterChip.buttonBorderWidth / 2 + 6),
|
padding: const EdgeInsets.symmetric(horizontal: AvesFilterChip.buttonBorderWidth / 2 + 6),
|
||||||
|
// specify transparent as a workaround to prevent
|
||||||
|
// chip border clipping when the floating app bar is fading
|
||||||
|
color: Colors.transparent,
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
children: filtersList
|
children: filtersList
|
||||||
|
@ -59,8 +61,12 @@ class ExpandableFilterRow extends StatelessWidget {
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
)
|
);
|
||||||
: Container(
|
final list = Container(
|
||||||
|
key: ValueKey('list$title'),
|
||||||
|
// specify transparent as a workaround to prevent
|
||||||
|
// chip border clipping when the floating app bar is fading
|
||||||
|
color: Colors.transparent,
|
||||||
height: kMinInteractiveDimension,
|
height: kMinInteractiveDimension,
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
|
@ -80,12 +86,22 @@ class ExpandableFilterRow extends StatelessWidget {
|
||||||
itemCount: filtersList.length,
|
itemCount: filtersList.length,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
final filterChips = isExpanded ? wrap : list;
|
||||||
return titleRow != null
|
return titleRow != null
|
||||||
? Column(
|
? Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
titleRow,
|
titleRow,
|
||||||
filterChips,
|
AnimatedSwitcher(
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
child: filterChips,
|
||||||
|
layoutBuilder: (currentChild, previousChildren) => Stack(
|
||||||
|
children: [
|
||||||
|
...previousChildren,
|
||||||
|
if (currentChild != null) currentChild,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: filterChips;
|
: filterChips;
|
||||||
|
|
|
@ -53,7 +53,7 @@ class ImageSearchDelegate extends SearchDelegate<CollectionFilter> {
|
||||||
@override
|
@override
|
||||||
Widget buildSuggestions(BuildContext context) {
|
Widget buildSuggestions(BuildContext context) {
|
||||||
final source = collection.source;
|
final source = collection.source;
|
||||||
final upQuery = query.toUpperCase();
|
final upQuery = query.trim().toUpperCase();
|
||||||
final containQuery = (String s) => s.toUpperCase().contains(upQuery);
|
final containQuery = (String s) => s.toUpperCase().contains(upQuery);
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: ValueListenableBuilder<String>(
|
child: ValueListenableBuilder<String>(
|
||||||
|
@ -98,7 +98,8 @@ class ImageSearchDelegate extends SearchDelegate<CollectionFilter> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildResults(BuildContext context) {
|
Widget buildResults(BuildContext context) {
|
||||||
close(context, QueryFilter(query));
|
final cleanQuery = query.trim();
|
||||||
|
close(context, cleanQuery.isNotEmpty ? QueryFilter(cleanQuery) : null);
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue