search: submitting query animate query chip like it was tapped
This commit is contained in:
parent
d3e0dd9375
commit
408afd4c9d
2 changed files with 24 additions and 14 deletions
|
@ -9,12 +9,14 @@ class ExpandableFilterRow extends StatelessWidget {
|
|||
final String title;
|
||||
final Iterable<CollectionFilter> filters;
|
||||
final ValueNotifier<String> expandedNotifier;
|
||||
final HeroType Function(CollectionFilter filter) heroTypeBuilder;
|
||||
final FilterCallback onPressed;
|
||||
|
||||
const ExpandableFilterRow({
|
||||
this.title,
|
||||
@required this.filters,
|
||||
this.expandedNotifier,
|
||||
this.heroTypeBuilder,
|
||||
@required this.onPressed,
|
||||
});
|
||||
|
||||
|
@ -59,12 +61,7 @@ class ExpandableFilterRow extends StatelessWidget {
|
|||
child: Wrap(
|
||||
spacing: horizontalPadding,
|
||||
runSpacing: verticalPadding,
|
||||
children: filtersList
|
||||
.map((filter) => AvesFilterChip(
|
||||
filter: filter,
|
||||
onPressed: onPressed,
|
||||
))
|
||||
.toList(),
|
||||
children: filtersList.map(_buildFilterChip).toList(),
|
||||
),
|
||||
);
|
||||
final list = Container(
|
||||
|
@ -78,12 +75,7 @@ class ExpandableFilterRow extends StatelessWidget {
|
|||
physics: BouncingScrollPhysics(),
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
itemBuilder: (context, index) {
|
||||
if (index >= filtersList.length) return null;
|
||||
final filter = filtersList[index];
|
||||
return AvesFilterChip(
|
||||
filter: filter,
|
||||
onPressed: onPressed,
|
||||
);
|
||||
return index < filtersList.length ? _buildFilterChip(filtersList[index]) : null;
|
||||
},
|
||||
separatorBuilder: (context, index) => SizedBox(width: 8),
|
||||
itemCount: filtersList.length,
|
||||
|
@ -109,4 +101,12 @@ class ExpandableFilterRow extends StatelessWidget {
|
|||
)
|
||||
: filterChips;
|
||||
}
|
||||
|
||||
Widget _buildFilterChip(CollectionFilter filter) {
|
||||
return AvesFilterChip(
|
||||
filter: filter,
|
||||
heroType: heroTypeBuilder?.call(filter) ?? HeroType.onTap,
|
||||
onPressed: onPressed,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,19 +62,23 @@ class ImageSearchDelegate extends SearchDelegate<CollectionFilter> {
|
|||
child: ValueListenableBuilder<String>(
|
||||
valueListenable: expandedSectionNotifier,
|
||||
builder: (context, expandedSection, child) {
|
||||
var queryFilter = _buildQueryFilter(false);
|
||||
return ListView(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
children: [
|
||||
_buildFilterRow(
|
||||
context: context,
|
||||
filters: [
|
||||
_buildQueryFilter(false),
|
||||
queryFilter,
|
||||
FavouriteFilter(),
|
||||
MimeFilter(MimeTypes.anyImage),
|
||||
MimeFilter(MimeTypes.anyVideo),
|
||||
MimeFilter(MimeFilter.animated),
|
||||
MimeFilter(MimeTypes.svg),
|
||||
].where((f) => f != null && containQuery(f.label)),
|
||||
// usually perform hero animation only on tapped chips,
|
||||
// but we also need to animate the query chip when it is selected by submitting the search query
|
||||
heroTypeBuilder: (filter) => filter == queryFilter ? HeroType.always : HeroType.onTap,
|
||||
),
|
||||
StreamBuilder(
|
||||
stream: source.eventBus.on<AlbumsChangedEvent>(),
|
||||
|
@ -118,11 +122,17 @@ class ImageSearchDelegate extends SearchDelegate<CollectionFilter> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterRow({@required BuildContext context, String title, @required Iterable<CollectionFilter> filters}) {
|
||||
Widget _buildFilterRow({
|
||||
@required BuildContext context,
|
||||
String title,
|
||||
@required Iterable<CollectionFilter> filters,
|
||||
HeroType Function(CollectionFilter filter) heroTypeBuilder,
|
||||
}) {
|
||||
return ExpandableFilterRow(
|
||||
title: title,
|
||||
filters: filters,
|
||||
expandedNotifier: expandedSectionNotifier,
|
||||
heroTypeBuilder: heroTypeBuilder,
|
||||
onPressed: (filter) => _select(context, filter is QueryFilter ? QueryFilter(filter.query) : filter),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue