From 50ff4b3fdd8716f7b0a26c1fb5dc3db1d4d43177 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Fri, 22 Sep 2023 16:40:30 +0800 Subject: [PATCH] add rating --- lib/components/gallery_info_desktop.dart | 12 +++++++++++ lib/components/rate.dart | 26 ++++++++++++++++++++++++ lib/components/scroll_parent.dart | 3 ++- lib/l10n/app_en.arb | 3 ++- lib/l10n/app_zh.arb | 3 ++- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 lib/components/rate.dart diff --git a/lib/components/gallery_info_desktop.dart b/lib/components/gallery_info_desktop.dart index db1f31a..11af656 100644 --- a/lib/components/gallery_info_desktop.dart +++ b/lib/components/gallery_info_desktop.dart @@ -5,6 +5,7 @@ import 'package:intl/intl.dart'; import '../api/gallery.dart'; import '../main.dart'; import '../utils/filesize.dart'; +import 'rate.dart'; import 'tags.dart'; import 'thumbnail.dart'; @@ -112,6 +113,17 @@ class GalleryInfoDesktop extends StatelessWidget { gData.meta.gid.toString(), fontSize: 12, ), + Row( + children: [ + SizedBox( + width: 60, + child: Text("${i18n.rating}${i18n.colon}", + style: TextStyle( + color: cs.primary, + fontSize: 12))), + Rate(gData.meta.rating), + ], + ) ])), const VerticalDivider(indent: 10, endIndent: 10), Expanded(child: TagsPanel(gData.tags)), diff --git a/lib/components/rate.dart b/lib/components/rate.dart new file mode 100644 index 0000000..4c4bf76 --- /dev/null +++ b/lib/components/rate.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; + +class Rate extends StatelessWidget { + const Rate(this.rate, {Key? key}) : super(key: key); + final double rate; + + @override + Widget build(BuildContext context) { + final cs = Theme.of(context).colorScheme; + return Row( + children: [ + for (var i = 1; i < 6; i++) + Icon( + i <= rate + 0.25 + ? Icons.star + : i > rate + 0.75 + ? Icons.star_border + : Icons.star_half, + color: cs.primary, + size: 12, + ), + Text(" $rate", style: TextStyle(color: cs.secondary, fontSize: 12)), + ], + ); + } +} diff --git a/lib/components/scroll_parent.dart b/lib/components/scroll_parent.dart index 2cb0cad..725da27 100644 --- a/lib/components/scroll_parent.dart +++ b/lib/components/scroll_parent.dart @@ -17,8 +17,9 @@ class ScrollParent extends StatelessWidget { } if (controller.offset + value.overscroll >= controller.position.maxScrollExtent) { - if (controller.offset != controller.position.maxScrollExtent) + if (controller.offset != controller.position.maxScrollExtent) { controller.jumpTo(controller.position.maxScrollExtent); + } return true; } controller.jumpTo(controller.offset + value.overscroll); diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 6dd51c9..f45a634 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -84,5 +84,6 @@ "exportAd": "Export pages which marked as ads", "maxZipFilenameLength": "Maximum length of filenames in Zip files", "downloadComplete": "Download completed.", - "downloadZipFailed": "Failed to download ZIP file." + "downloadZipFailed": "Failed to download ZIP file.", + "rating": "Rating" } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 4a9c350..986e5b8 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -84,5 +84,6 @@ "exportAd": "导出标记为广告的页面", "maxZipFilenameLength": "Zip文件中文件名的最大长度", "downloadComplete": "下载完毕。", - "downloadZipFailed": "Zip文件下载失败。" + "downloadZipFailed": "Zip文件下载失败。", + "rating": "评分" }