From f6956e0989bdb8d0f0c1245c61905cc41425d2bf Mon Sep 17 00:00:00 2001 From: lifegpc Date: Fri, 8 Sep 2023 17:04:10 +0800 Subject: [PATCH] Add tooltip for tags --- lib/components/tag_tooltip.dart | 28 ++++++++++++++++++++++++++++ lib/components/tags.dart | 13 ++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 lib/components/tag_tooltip.dart diff --git a/lib/components/tag_tooltip.dart b/lib/components/tag_tooltip.dart new file mode 100644 index 0000000..0632f18 --- /dev/null +++ b/lib/components/tag_tooltip.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; +import '../api/gallery.dart'; + +String _getTag(Tag tag) { + final tags = tag.tag.split(":"); + if (tags.length < 2) return tag.translated ?? tag.tag; + final name = tags[1]!; + return tag.translated ?? name; +} + +class TagTooltip extends StatelessWidget { + const TagTooltip(this.tag, {Key? key}) : super(key: key); + final Tag tag; + + @override + Widget build(BuildContext context) { + final name = _getTag(tag); + final t = SelectableText(name); + return tag.intro != null && tag.intro!.isNotEmpty ? Tooltip( + message: tag.intro!, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(4.0), + color: Theme.of(context).colorScheme.secondary, + ), + child: t, + ) : t; + } +} diff --git a/lib/components/tags.dart b/lib/components/tags.dart index a690f5f..2e07a8a 100644 --- a/lib/components/tags.dart +++ b/lib/components/tags.dart @@ -3,6 +3,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../api/gallery.dart'; import '../globals.dart'; import '../main.dart'; +import 'tag_tooltip.dart'; import 'scroll_parent.dart'; class TagsPanel extends StatefulWidget { @@ -14,13 +15,6 @@ class TagsPanel extends StatefulWidget { State createState() => _TagsPanel(); } -String _getTag(Tag tag) { - final tags = tag.tag.split(":"); - if (tags.length < 2) return tag.translated ?? tag.tag; - final name = tags[1]!; - return tag.translated ?? name; -} - class _TagsPanel extends State { List<(String, List)>? data; @override @@ -77,8 +71,9 @@ class _TagsPanel extends State { borderRadius: const BorderRadius.all(Radius.circular(4.0)), border: Border.all(width: 1, color: cs.primary), ), - child: SelectableText( - stt ? _getTag(ta[index - 1]!) : ta[index - 1]!.tag)); + child: stt + ? TagTooltip(ta[index - 1]!) + : SelectableText(ta[index - 1]!.tag)); } })); });