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 String title;
|
||||||
final Iterable<CollectionFilter> filters;
|
final Iterable<CollectionFilter> filters;
|
||||||
final ValueNotifier<String> expandedNotifier;
|
final ValueNotifier<String> expandedNotifier;
|
||||||
|
final HeroType Function(CollectionFilter filter) heroTypeBuilder;
|
||||||
final FilterCallback onPressed;
|
final FilterCallback onPressed;
|
||||||
|
|
||||||
const ExpandableFilterRow({
|
const ExpandableFilterRow({
|
||||||
this.title,
|
this.title,
|
||||||
@required this.filters,
|
@required this.filters,
|
||||||
this.expandedNotifier,
|
this.expandedNotifier,
|
||||||
|
this.heroTypeBuilder,
|
||||||
@required this.onPressed,
|
@required this.onPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,12 +61,7 @@ class ExpandableFilterRow extends StatelessWidget {
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
spacing: horizontalPadding,
|
spacing: horizontalPadding,
|
||||||
runSpacing: verticalPadding,
|
runSpacing: verticalPadding,
|
||||||
children: filtersList
|
children: filtersList.map(_buildFilterChip).toList(),
|
||||||
.map((filter) => AvesFilterChip(
|
|
||||||
filter: filter,
|
|
||||||
onPressed: onPressed,
|
|
||||||
))
|
|
||||||
.toList(),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final list = Container(
|
final list = Container(
|
||||||
|
@ -78,12 +75,7 @@ class ExpandableFilterRow extends StatelessWidget {
|
||||||
physics: BouncingScrollPhysics(),
|
physics: BouncingScrollPhysics(),
|
||||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index >= filtersList.length) return null;
|
return index < filtersList.length ? _buildFilterChip(filtersList[index]) : null;
|
||||||
final filter = filtersList[index];
|
|
||||||
return AvesFilterChip(
|
|
||||||
filter: filter,
|
|
||||||
onPressed: onPressed,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
separatorBuilder: (context, index) => SizedBox(width: 8),
|
separatorBuilder: (context, index) => SizedBox(width: 8),
|
||||||
itemCount: filtersList.length,
|
itemCount: filtersList.length,
|
||||||
|
@ -109,4 +101,12 @@ class ExpandableFilterRow extends StatelessWidget {
|
||||||
)
|
)
|
||||||
: filterChips;
|
: 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>(
|
child: ValueListenableBuilder<String>(
|
||||||
valueListenable: expandedSectionNotifier,
|
valueListenable: expandedSectionNotifier,
|
||||||
builder: (context, expandedSection, child) {
|
builder: (context, expandedSection, child) {
|
||||||
|
var queryFilter = _buildQueryFilter(false);
|
||||||
return ListView(
|
return ListView(
|
||||||
padding: EdgeInsets.only(top: 8),
|
padding: EdgeInsets.only(top: 8),
|
||||||
children: [
|
children: [
|
||||||
_buildFilterRow(
|
_buildFilterRow(
|
||||||
context: context,
|
context: context,
|
||||||
filters: [
|
filters: [
|
||||||
_buildQueryFilter(false),
|
queryFilter,
|
||||||
FavouriteFilter(),
|
FavouriteFilter(),
|
||||||
MimeFilter(MimeTypes.anyImage),
|
MimeFilter(MimeTypes.anyImage),
|
||||||
MimeFilter(MimeTypes.anyVideo),
|
MimeFilter(MimeTypes.anyVideo),
|
||||||
MimeFilter(MimeFilter.animated),
|
MimeFilter(MimeFilter.animated),
|
||||||
MimeFilter(MimeTypes.svg),
|
MimeFilter(MimeTypes.svg),
|
||||||
].where((f) => f != null && containQuery(f.label)),
|
].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(
|
StreamBuilder(
|
||||||
stream: source.eventBus.on<AlbumsChangedEvent>(),
|
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(
|
return ExpandableFilterRow(
|
||||||
title: title,
|
title: title,
|
||||||
filters: filters,
|
filters: filters,
|
||||||
expandedNotifier: expandedSectionNotifier,
|
expandedNotifier: expandedSectionNotifier,
|
||||||
|
heroTypeBuilder: heroTypeBuilder,
|
||||||
onPressed: (filter) => _select(context, filter is QueryFilter ? QueryFilter(filter.query) : filter),
|
onPressed: (filter) => _select(context, filter is QueryFilter ? QueryFilter(filter.query) : filter),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue