fix: hex color parse

This commit is contained in:
Rongjian Zhang 2022-10-01 02:54:09 +08:00
parent a30385a414
commit d5f3bd9f24
6 changed files with 17 additions and 19 deletions

View File

@ -52,7 +52,7 @@ class GhIssuesScreen extends StatelessWidget {
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in p.labels!.nodes!)
HexColorTag(name: label.name, color: '#${label.color}')
HexColorTag(name: label.name, color: label.color)
]),
url: '/github/$owner/$name/issues/${p.number}',
);

View File

@ -45,7 +45,7 @@ class GlIssuesScreen extends StatelessWidget {
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in p.labels!)
HexColorTag(name: label, color: '#428BCA')
HexColorTag(name: label, color: '428BCA')
]),
url: '/gitlab/projects/${p.projectId}/issues/${p.iid}',
),

View File

@ -40,7 +40,7 @@ class GlMergeRequestsScreen extends StatelessWidget {
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in p.labels!)
HexColorTag(name: label, color: '#428BCA')
HexColorTag(name: label, color: '428BCA')
]),
// url: '/gitlab/projects/${p.projectId}/merge_requests/${p.iid}',
url: '$prefix/merge_requests/${p.iid}', // TODO:

View File

@ -47,15 +47,6 @@ class CommonStyle {
static final monospace = Platform.isIOS ? 'Menlo' : 'monospace'; // FIXME:
}
// TODO:
// Color getFontColorByBrightness(Color color) {
// var grayscale = color.red * 0.3 + color.green * 0.59 + color.blue * 0.11;
// // Fimber.d('color: $color, $grayscale');
// var showWhite = grayscale < 128;
// return showWhite ? AntTheme.of(context).white : AntTheme.of(context).text;
// }
TextSpan createLinkSpan(
BuildContext context,
String? text,

View File

@ -3,7 +3,6 @@ import 'package:flutter/widgets.dart';
import 'package:from_css_color/from_css_color.dart';
class HexColorTag extends StatelessWidget {
const HexColorTag({
super.key,
required this.name,
@ -14,10 +13,20 @@ class HexColorTag extends StatelessWidget {
@override
Widget build(BuildContext context) {
final c = fromCssColor('#$color');
final theme = AntTheme.of(context);
return AntTag(
round: true,
color: fromCssColor(color),
child: Text(name),
color: c,
child: Text(
name,
style: TextStyle(
color: c.computeLuminance() > 0.5
? theme.colorText
: theme.colorBackground,
),
),
);
}
}

View File

@ -205,8 +205,7 @@ class TimelineItem extends StatelessWidget {
textSpan: TextSpan(children: [
TextSpan(text: ' ${AppLocalizations.of(context)!.added} '),
WidgetSpan(
child: HexColorTag(
name: p.label.name, color: '#${p.label.color}')),
child: HexColorTag(name: p.label.name, color: p.label.color)),
TextSpan(text: ' ${AppLocalizations.of(context)!.label}'),
]),
);
@ -218,8 +217,7 @@ class TimelineItem extends StatelessWidget {
textSpan: TextSpan(children: [
TextSpan(text: ' ${AppLocalizations.of(context)!.removed} '),
WidgetSpan(
child: HexColorTag(
name: p.label.name, color: '#${p.label.color}')),
child: HexColorTag(name: p.label.name, color: p.label.color)),
TextSpan(text: ' ${AppLocalizations.of(context)!.label}'),
]),
);