From 07f073bd77c9d7d21586c24fff886904ad8dd68a Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Tue, 31 Dec 2019 09:15:42 +0900 Subject: [PATCH] colored tags --- lib/utils/color_utils.dart | 7 +++ lib/widgets/album/all_collection_drawer.dart | 6 ++- lib/widgets/fullscreen/info/xmp_section.dart | 48 +++++++++++--------- 3 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 lib/utils/color_utils.dart diff --git a/lib/utils/color_utils.dart b/lib/utils/color_utils.dart new file mode 100644 index 000000000..ed4ca50bc --- /dev/null +++ b/lib/utils/color_utils.dart @@ -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(); +} diff --git a/lib/widgets/album/all_collection_drawer.dart b/lib/widgets/album/all_collection_drawer.dart index 1ea3dc1d5..990915b97 100644 --- a/lib/widgets/album/all_collection_drawer.dart +++ b/lib/widgets/album/all_collection_drawer.dart @@ -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), ); diff --git a/lib/widgets/fullscreen/info/xmp_section.dart b/lib/widgets/fullscreen/info/xmp_section.dart index 3686f7c4a..5680bad88 100644 --- a/lib/widgets/fullscreen/info/xmp_section.dart +++ b/lib/widgets/fullscreen/info/xmp_section.dart @@ -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, + ), + ), + ); + } }