Update Galleries page title

This commit is contained in:
2023-09-15 17:09:55 +08:00
parent dae5e13bd8
commit b5a73b4714
9 changed files with 162 additions and 41 deletions

23
lib/components/tag.dart Normal file
View File

@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../api/gallery.dart';
import '../globals.dart';
class TagWidget extends StatelessWidget {
const TagWidget(this.tag, {Key? key, this.name}) : super(key: key);
final Tag tag;
final String? name;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
context.pushNamed("/galleries",
queryParameters: {
"tag": [tag.tag]
},
extra: GalleriesPageExtra(translatedTag: tag.translated));
},
child: Text(name ?? tag.tag));
}
}

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../api/gallery.dart';
import 'tag.dart';
String _getTag(Tag tag) {
final tags = tag.tag.split(":");
@@ -17,13 +16,7 @@ class TagTooltip extends StatelessWidget {
@override
Widget build(BuildContext context) {
final name = _getTag(tag);
final t = InkWell(
onTap: () {
context.pushNamed("/galleries", queryParameters: {
"tag": [tag.tag]
});
},
child: Text(name));
final t = TagWidget(tag, name: name);
return tag.intro != null && tag.intro!.isNotEmpty
? Tooltip(
message: tag.intro!,

View File

@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import '../api/gallery.dart';
import '../globals.dart';
import '../main.dart';
import 'tag.dart';
import 'tag_tooltip.dart';
import 'scroll_parent.dart';
@@ -74,13 +74,7 @@ class _TagsPanel extends State<TagsPanel> {
),
child: stt
? TagTooltip(ta[index - 1]!)
: InkWell(
onTap: () {
context.pushNamed("/galleries", queryParameters: {
"tag": [ta[index - 1]!.tag]
});
},
child: Text(ta[index - 1]!.tag)));
: TagWidget(ta[index - 1]!));
}
}));
});

View File

@@ -6,15 +6,28 @@ import 'package:logging/logging.dart';
import 'api/client.dart';
import 'api/gallery.dart';
import 'globals.dart';
import 'main.dart';
final _log = Logger("GalleriesPage");
class GalleriesPageExtra {
const GalleriesPageExtra({this.translatedTag});
final String? translatedTag;
}
class GalleriesPage extends StatefulWidget {
const GalleriesPage({Key? key, this.sortByGid, this.uploader, this.tag})
const GalleriesPage(
{Key? key, this.sortByGid, this.uploader, this.tag, this.translatedTag})
: super(key: key);
final SortByGid? sortByGid;
final String? uploader;
final String? tag;
final String? translatedTag;
bool _stt(BuildContext context) =>
prefs.getBool("showTranslatedTag") ??
MainApp.of(context).lang.toLocale().languageCode == "zh";
String? preferredTag(BuildContext context) =>
_stt(context) ? translatedTag ?? tag : tag;
static const String routeName = '/galleries';
@@ -22,7 +35,8 @@ class GalleriesPage extends StatefulWidget {
State<GalleriesPage> createState() => _GalleriesPage();
}
class _GalleriesPage extends State<GalleriesPage> with ThemeModeWidget {
class _GalleriesPage extends State<GalleriesPage>
with ThemeModeWidget, IsTopWidget2 {
static const int _pageSize = 20;
bool? _sortByGid;
SortByGid _sortByGid2 = SortByGid.none;
@@ -71,6 +85,7 @@ class _GalleriesPage extends State<GalleriesPage> with ThemeModeWidget {
@override
Widget build(BuildContext context) {
tryInitApi(context);
final i18n = AppLocalizations.of(context)!;
final sortByGidMenu = DropdownMenu<SortByGid>(
initialSelection: _sortByGid2,
onSelected: (v) {
@@ -90,22 +105,28 @@ class _GalleriesPage extends State<GalleriesPage> with ThemeModeWidget {
queryParameters: queryParameters);
}
},
label: Text(AppLocalizations.of(context)!.sortByGid,
label: Text(i18n.sortByGid,
style: MediaQuery.of(context).size.width > 810
? Theme.of(context).textTheme.labelMedium
: Theme.of(context).textTheme.labelLarge),
dropdownMenuEntries: [
DropdownMenuEntry(
value: SortByGid.none, label: AppLocalizations.of(context)!.none),
DropdownMenuEntry(
value: SortByGid.asc, label: AppLocalizations.of(context)!.asc),
DropdownMenuEntry(
value: SortByGid.desc, label: AppLocalizations.of(context)!.desc),
DropdownMenuEntry(value: SortByGid.none, label: i18n.none),
DropdownMenuEntry(value: SortByGid.asc, label: i18n.asc),
DropdownMenuEntry(value: SortByGid.desc, label: i18n.desc),
],
leadingIcon: const Icon(Icons.sort),
);
setCurrentTitle(AppLocalizations.of(context)!.galleries,
Theme.of(context).primaryColor.value);
final title = widget.uploader != null && widget.tag != null
? i18n.tagUploaderGalleries(
widget.preferredTag(context)!, widget.uploader!)
: widget.uploader != null
? i18n.uploaderGalleries(widget.uploader!)
: widget.tag != null
? i18n.tagGalleries(widget.preferredTag(context)!)
: i18n.galleries;
if (isTop(context)) {
setCurrentTitle(title, Theme.of(context).primaryColor.value);
}
return Scaffold(
appBar: AppBar(
leading: IconButton(
@@ -114,7 +135,7 @@ class _GalleriesPage extends State<GalleriesPage> with ThemeModeWidget {
context.canPop() ? context.pop() : context.go("/");
},
),
title: Text(AppLocalizations.of(context)!.galleries),
title: Text(title),
actions: [
MediaQuery.of(context).size.width > 810
? Padding(

View File

@@ -29,7 +29,8 @@ class GalleryPage extends StatefulWidget {
State<GalleryPage> createState() => _GalleryPage();
}
class _GalleryPage extends State<GalleryPage> with ThemeModeWidget {
class _GalleryPage extends State<GalleryPage>
with ThemeModeWidget, IsTopWidget2 {
_GalleryPage();
int _gid = 0;
GalleryData? _data;
@@ -84,14 +85,16 @@ class _GalleryPage extends State<GalleryPage> with ThemeModeWidget {
: _data != null
? _data!.meta.preferredTitle
: i18n.gallery;
if (!kIsWeb || (_data != null && kIsWeb)) {
setCurrentTitle(title, Theme.of(context).primaryColor.value,
includePrefix: false);
} else if (kIsWeb && widget.title != null) {
// 设置预加载标题
// Chrome 和 Firefox 必须尽快设置标题以确保在历史记录菜单显示正确的标题
setCurrentTitle(widget.title!, Theme.of(context).primaryColor.value,
includePrefix: false);
if (isTop(context)) {
if (!kIsWeb || (_data != null && kIsWeb)) {
setCurrentTitle(title, Theme.of(context).primaryColor.value,
includePrefix: false);
} else if (kIsWeb && widget.title != null) {
// 设置预加载标题
// Chrome 和 Firefox 必须尽快设置标题以确保在历史记录菜单显示正确的标题
setCurrentTitle(widget.title!, Theme.of(context).primaryColor.value,
includePrefix: false);
}
}
return Scaffold(
appBar: _data == null

View File

@@ -25,6 +25,7 @@ import 'platform/clipboard.dart';
import 'platform/path.dart';
import 'tags.dart';
import 'utils.dart';
export 'galleries.dart' show GalleriesPageExtra;
export 'gallery.dart' show GalleryPageExtra;
final dio = Dio()
@@ -243,6 +244,32 @@ mixin ThemeModeWidget<T extends StatefulWidget> on State<T> {
}
}
mixin IsTopWidget on Widget {
@protected
bool isTop(BuildContext context) {
final last = GoRouter.of(context)
.routerDelegate
.currentConfiguration
.matches
.last
.pageKey;
return last == key;
}
}
mixin IsTopWidget2<T extends StatefulWidget> on State<T> {
@protected
bool isTop(BuildContext context) {
final last = GoRouter.of(context)
.routerDelegate
.currentConfiguration
.matches
.last
.pageKey;
return last == widget.key;
}
}
enum Lang {
system("System"),
english("English"),

View File

@@ -52,5 +52,32 @@
}
}
},
"gid": "Gallery Id"
"gid": "Gallery Id",
"tagGalleries": "Galleries tagged {tag}",
"@tagGalleries": {
"placeholders": {
"tag": {
"type": "String"
}
}
},
"tagUploaderGalleries": "Galleries tagged {tag} by {uploader}",
"@tagUploaderGalleries": {
"placeholders": {
"tag": {
"type": "String"
},
"uploader": {
"type": "String"
}
}
},
"uploaderGalleries": "Galleries uploaded by {uploader}",
"@uploaderGalleries": {
"placeholders": {
"uploader": {
"type": "String"
}
}
}
}

View File

@@ -52,5 +52,32 @@
}
}
},
"gid": "画廊ID"
"gid": "画廊ID",
"tagGalleries": "带有 {tag} 标签的画廊",
"@tagGalleries": {
"placeholders": {
"tag": {
"type": "String"
}
}
},
"tagUploaderGalleries": "{uploader} 上传的带有 {tag} 标签的画廊",
"@tagUploaderGalleries": {
"placeholders": {
"tag": {
"type": "String"
},
"uploader": {
"type": "String"
}
}
},
"uploaderGalleries": "{uploader} 上传的画廊",
"@uploaderGalleries": {
"placeholders": {
"uploader": {
"type": "String"
}
}
}
}

View File

@@ -57,8 +57,13 @@ final _router = GoRouter(
}
final tag = state.uri.queryParameters["tag"];
final uploader = state.uri.queryParameters["uploader"];
final extra = state.extra as GalleriesPageExtra?;
return GalleriesPage(
sortByGid: sortByGid, tag: tag, uploader: uploader);
key: state.pageKey,
sortByGid: sortByGid,
tag: tag,
uploader: uploader,
translatedTag: extra?.translatedTag);
}),
GoRoute(
path: GalleryPage.routeName,
@@ -66,6 +71,7 @@ final _router = GoRouter(
final extra = state.extra as GalleryPageExtra?;
return GalleryPage(
int.parse(state.pathParameters["gid"]!),
key: state.pageKey,
title: extra?.title,
);
},