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_collection.dart';
import 'package:aves/model/image_entry.dart'; import 'package:aves/model/image_entry.dart';
import 'package:aves/utils/android_file_utils.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/album/filtered_collection_page.dart';
import 'package:aves/widgets/common/icons.dart'; import 'package:aves/widgets/common/icons.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -46,7 +47,10 @@ class AllCollectionDrawer extends StatelessWidget {
); );
final buildTagEntry = (tag) => _FilteredCollectionNavTile( final buildTagEntry = (tag) => _FilteredCollectionNavTile(
collection: collection, collection: collection,
leading: const Icon(OMIcons.label), leading: Icon(
OMIcons.label,
color: stringToColor(tag),
),
title: tag, title: tag,
filter: (entry) => entry.xmpSubjects.contains(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_collection.dart';
import 'package:aves/model/image_entry.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/album/filtered_collection_page.dart';
import 'package:aves/widgets/fullscreen/info/info_page.dart'; import 'package:aves/widgets/fullscreen/info/info_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -25,30 +26,33 @@ class XmpTagSection extends AnimatedWidget {
const SectionRow('XMP Tags'), const SectionRow('XMP Tags'),
Wrap( Wrap(
spacing: 8, spacing: 8,
children: tags.map((tag) { children: tags
final borderColor = Theme.of(context).accentColor; .map((tag) => OutlineButton(
return OutlineButton( onPressed: () => _goToTag(context, tag),
onPressed: () => Navigator.push( borderSide: BorderSide(
context, color: stringToColor(tag),
MaterialPageRoute( ),
builder: (context) => FilteredCollectionPage( shape: RoundedRectangleBorder(
collection: collection, borderRadius: BorderRadius.circular(42),
filter: (entry) => entry.xmpSubjects.contains(tag), ),
title: tag, child: Text(tag),
), ))
), .toList(),
),
borderSide: BorderSide(
color: borderColor,
),
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,
),
),
);
}
} }