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