colored tags

This commit is contained in:
Thibault Deckers 2019-12-31 09:15:42 +09:00
parent ac1458f6de
commit 07f073bd77
3 changed files with 38 additions and 23 deletions

View 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();
}

View file

@ -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),
);

View file

@ -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,10 +26,25 @@ 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(
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(
@ -37,18 +53,6 @@ class XmpTagSection extends AnimatedWidget {
title: tag,
),
),
),
borderSide: BorderSide(
color: borderColor,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(42),
),
child: Text(tag),
);
}).toList(),
),
],
);
}
}