mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-23 20:26:50 +08:00
Add tooltip for tags
This commit is contained in:
28
lib/components/tag_tooltip.dart
Normal file
28
lib/components/tag_tooltip.dart
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<TagsPanel> 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<TagsPanel> {
|
||||
List<(String, List<Tag>)>? data;
|
||||
@override
|
||||
@@ -77,8 +71,9 @@ class _TagsPanel extends State<TagsPanel> {
|
||||
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));
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user