filter bar: minor fixes
This commit is contained in:
parent
cb553df009
commit
0cedb70666
5 changed files with 34 additions and 20 deletions
|
@ -26,6 +26,8 @@ abstract class CollectionFilter implements Comparable<CollectionFilter> {
|
|||
|
||||
String get label;
|
||||
|
||||
String get tooltip => label;
|
||||
|
||||
Widget iconBuilder(BuildContext context, double size);
|
||||
|
||||
Future<Color> color(BuildContext context) => SynchronousFuture(stringToColor(label));
|
||||
|
@ -44,6 +46,8 @@ abstract class CollectionFilter implements Comparable<CollectionFilter> {
|
|||
class AlbumFilter extends CollectionFilter {
|
||||
static const type = 'album';
|
||||
|
||||
static Map<String, Color> _appColors = Map();
|
||||
|
||||
final String album;
|
||||
|
||||
const AlbumFilter(this.album);
|
||||
|
@ -54,23 +58,34 @@ class AlbumFilter extends CollectionFilter {
|
|||
@override
|
||||
String get label => album.split(separator).last;
|
||||
|
||||
@override
|
||||
String get tooltip => album;
|
||||
|
||||
@override
|
||||
Widget iconBuilder(context, size) {
|
||||
return IconUtils.getAlbumIcon(context: context, album: album, size: size) ?? Icon(OMIcons.photoAlbum, size: size);
|
||||
}
|
||||
|
||||
Future<Color> color(BuildContext context) async {
|
||||
Color color;
|
||||
@override
|
||||
Future<Color> color(BuildContext context) {
|
||||
// do not use async/await and rely on `SynchronousFuture`
|
||||
// to prevent rebuilding of the `FutureBuilder` listening on this future
|
||||
if (androidFileUtils.getAlbumType(album) == AlbumType.App) {
|
||||
final palette = await PaletteGenerator.fromImageProvider(
|
||||
if (_appColors.containsKey(album)) return SynchronousFuture(_appColors[album]);
|
||||
|
||||
return PaletteGenerator.fromImageProvider(
|
||||
AppIconImage(
|
||||
packageName: androidFileUtils.getAlbumAppPackageName(album),
|
||||
size: 24,
|
||||
),
|
||||
);
|
||||
color = palette.dominantColor?.color;
|
||||
).then((palette) {
|
||||
final color = palette.dominantColor?.color ?? super.color(context);
|
||||
_appColors[album] = color;
|
||||
return color;
|
||||
});
|
||||
} else {
|
||||
return super.color(context);
|
||||
}
|
||||
return color ?? super.color(context);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -35,8 +35,8 @@ class FilterBar extends StatelessWidget implements PreferredSizeWidget {
|
|||
final filter = filters[index];
|
||||
return Center(
|
||||
child: AvesFilterChip(
|
||||
filter,
|
||||
clearable: true,
|
||||
filter: filter,
|
||||
removable: true,
|
||||
onPressed: collection.removeFilter,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -6,7 +6,7 @@ typedef FilterCallback = void Function(CollectionFilter filter);
|
|||
|
||||
class AvesFilterChip extends StatefulWidget {
|
||||
final CollectionFilter filter;
|
||||
final bool clearable;
|
||||
final bool removable;
|
||||
final FilterCallback onPressed;
|
||||
|
||||
static const double buttonBorderWidth = 2;
|
||||
|
@ -14,11 +14,12 @@ class AvesFilterChip extends StatefulWidget {
|
|||
static const double iconSize = 20;
|
||||
static const double padding = 6;
|
||||
|
||||
const AvesFilterChip(
|
||||
this.filter, {
|
||||
this.clearable = false,
|
||||
const AvesFilterChip({
|
||||
Key key,
|
||||
this.filter,
|
||||
this.removable = false,
|
||||
@required this.onPressed,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AvesFilterChipState createState() => _AvesFilterChipState();
|
||||
|
@ -29,8 +30,6 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
|||
|
||||
CollectionFilter get filter => widget.filter;
|
||||
|
||||
String get label => filter.label;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
@ -50,7 +49,7 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final leading = filter.iconBuilder(context, AvesFilterChip.iconSize);
|
||||
final trailing = widget.clearable ? Icon(OMIcons.clear, size: AvesFilterChip.iconSize) : null;
|
||||
final trailing = widget.removable ? Icon(OMIcons.clear, size: AvesFilterChip.iconSize) : null;
|
||||
|
||||
final child = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
@ -61,7 +60,7 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
|||
],
|
||||
Flexible(
|
||||
child: Text(
|
||||
label,
|
||||
filter.label,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.fade,
|
||||
maxLines: 1,
|
||||
|
@ -81,7 +80,7 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
|||
return ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: AvesFilterChip.maxChipWidth),
|
||||
child: Tooltip(
|
||||
message: label,
|
||||
message: filter.tooltip,
|
||||
child: FutureBuilder(
|
||||
future: _colorFuture,
|
||||
builder: (context, AsyncSnapshot<Color> snapshot) {
|
||||
|
|
|
@ -49,7 +49,7 @@ class BasicSection extends StatelessWidget {
|
|||
spacing: 8,
|
||||
children: filters
|
||||
.map((filter) => AvesFilterChip(
|
||||
filter,
|
||||
filter: filter,
|
||||
onPressed: onFilter,
|
||||
))
|
||||
.toList(),
|
||||
|
|
|
@ -113,7 +113,7 @@ class _LocationSectionState extends State<LocationSection> {
|
|||
spacing: 8,
|
||||
children: filters
|
||||
.map((filter) => AvesFilterChip(
|
||||
filter,
|
||||
filter: filter,
|
||||
onPressed: widget.onFilter,
|
||||
))
|
||||
.toList(),
|
||||
|
|
Loading…
Reference in a new issue