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_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),
|
||||||
);
|
);
|
||||||
|
|
|
@ -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,10 +26,25 @@ 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(
|
||||||
|
color: stringToColor(tag),
|
||||||
|
),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(42),
|
||||||
|
),
|
||||||
|
child: Text(tag),
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _goToTag(BuildContext context, String tag) {
|
||||||
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => FilteredCollectionPage(
|
builder: (context) => FilteredCollectionPage(
|
||||||
|
@ -37,18 +53,6 @@ class XmpTagSection extends AnimatedWidget {
|
||||||
title: tag,
|
title: tag,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
borderSide: BorderSide(
|
|
||||||
color: borderColor,
|
|
||||||
),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(42),
|
|
||||||
),
|
|
||||||
child: Text(tag),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue