colored tags
This commit is contained in:
parent
ac1458f6de
commit
07f073bd77
3 changed files with 38 additions and 23 deletions
7
lib/utils/color_utils.dart
Normal file
7
lib/utils/color_utils.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
Color stringToColor(String string, {double saturation = .8, double lightness = .6}) {
|
||||
final hash = string.codeUnits.fold(0, (prev, el) => prev = el + ((prev << 5) - prev));
|
||||
final hue = (hash % 360).toDouble();
|
||||
return HSLColor.fromAHSL(1.0, hue, saturation, lightness).toColor();
|
||||
}
|
|
@ -3,6 +3,7 @@ import 'dart:ui';
|
|||
import 'package:aves/model/image_collection.dart';
|
||||
import 'package:aves/model/image_entry.dart';
|
||||
import 'package:aves/utils/android_file_utils.dart';
|
||||
import 'package:aves/utils/color_utils.dart';
|
||||
import 'package:aves/widgets/album/filtered_collection_page.dart';
|
||||
import 'package:aves/widgets/common/icons.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -46,7 +47,10 @@ class AllCollectionDrawer extends StatelessWidget {
|
|||
);
|
||||
final buildTagEntry = (tag) => _FilteredCollectionNavTile(
|
||||
collection: collection,
|
||||
leading: const Icon(OMIcons.label),
|
||||
leading: Icon(
|
||||
OMIcons.label,
|
||||
color: stringToColor(tag),
|
||||
),
|
||||
title: tag,
|
||||
filter: (entry) => entry.xmpSubjects.contains(tag),
|
||||
);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:aves/model/image_collection.dart';
|
||||
import 'package:aves/model/image_entry.dart';
|
||||
import 'package:aves/utils/color_utils.dart';
|
||||
import 'package:aves/widgets/album/filtered_collection_page.dart';
|
||||
import 'package:aves/widgets/fullscreen/info/info_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -25,30 +26,33 @@ class XmpTagSection extends AnimatedWidget {
|
|||
const SectionRow('XMP Tags'),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: tags.map((tag) {
|
||||
final borderColor = Theme.of(context).accentColor;
|
||||
return OutlineButton(
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FilteredCollectionPage(
|
||||
collection: collection,
|
||||
filter: (entry) => entry.xmpSubjects.contains(tag),
|
||||
title: tag,
|
||||
),
|
||||
),
|
||||
),
|
||||
borderSide: BorderSide(
|
||||
color: borderColor,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(42),
|
||||
),
|
||||
child: Text(tag),
|
||||
);
|
||||
}).toList(),
|
||||
children: tags
|
||||
.map((tag) => OutlineButton(
|
||||
onPressed: () => _goToTag(context, tag),
|
||||
borderSide: BorderSide(
|
||||
color: stringToColor(tag),
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(42),
|
||||
),
|
||||
child: Text(tag),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _goToTag(BuildContext context, String tag) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FilteredCollectionPage(
|
||||
collection: collection,
|
||||
filter: (entry) => entry.xmpSubjects.contains(tag),
|
||||
title: tag,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue