Use better way to handle gallery with no images and page with no images

This commit is contained in:
2024-06-02 07:49:03 +00:00
committed by GitHub
parent 9e0aa9ca84
commit f5666a8c46
7 changed files with 54 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ class GalleryBasicInfo extends StatelessWidget {
const GalleryBasicInfo(this.gMeta, this.firstPage,
{super.key, this.fileId, this.gData, this.files});
final GMeta gMeta;
final ExtendedPMeta firstPage;
final ExtendedPMeta? firstPage;
final int? fileId;
final GalleryData? gData;
final EhFiles? files;
@@ -27,7 +27,9 @@ class GalleryBasicInfo extends StatelessWidget {
flex: 2,
child: Container(
margin: const EdgeInsets.only(right: 8),
child: Thumbnail(firstPage, fileId: fileId, gid: gMeta.gid),
child: firstPage != null
? Thumbnail(firstPage!, fileId: fileId, gid: gMeta.gid)
: Container(),
)),
Expanded(
flex: 3,

View File

@@ -53,9 +53,9 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
@override
Widget build(BuildContext context) {
bool useMobile = MediaQuery.of(context).size.width <= 810;
final firstPage = widget.gData.pages.first;
final int? firstFileId = widget.files != null
? widget.files!.files[firstPage.token]!.first.id
final firstPage = widget.gData.pages.firstOrNull;
final int? firstFileId = widget.files != null && firstPage != null
? widget.files!.files[firstPage!.token]!.firstOrNull?.id
: null;
return CustomScrollView(
controller: controller,

View File

@@ -59,9 +59,12 @@ class GalleryInfoDesktop extends StatelessWidget {
child: Row(children: [
Expanded(
flex: 3,
child: Padding(padding: const EdgeInsets.only(right: 8.0),
child: Thumbnail(gData.pages.first,
fileId: fileId, gid: gData.meta.gid))),
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: gData.pages.isNotEmpty
? Thumbnail(gData.pages.first,
fileId: fileId, gid: gData.meta.gid)
: Container())),
Expanded(
flex: 7,
child: Column(

View File

@@ -23,7 +23,7 @@ class ThumbnailGridView extends StatelessWidget {
itemBuilder: (context, index) {
final page = npages[index]!;
final fileId =
files != null ? files!.files[page.token]!.first.id : null;
files != null ? files!.files[page.token]!.firstOrNull?.id : null;
final key = Key("thumbnail$gid-${page.index}");
return Container(
padding: const EdgeInsets.all(4),

View File

@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
@@ -89,13 +90,42 @@ class _TaskPage extends State<TaskPage> {
final maxWidth = MediaQuery.of(context).size.width;
final endIndent = maxWidth < 400 ? 5.0 : 10.0;
final indent = endIndent + 70;
final allowLink = task.base.gid != 0 &&
(typ != TaskType.download ||
task.status == TaskStatus.running ||
task.status == TaskStatus.finished);
String? title;
if (typ == TaskType.download && tasks.meta.containsKey(task.base.gid)) {
title = tasks.meta[task.base.gid]!.preferredTitle;
}
final cs = Theme.of(context).colorScheme;
return Column(
children: [
_KeyValue(i18n.taskId, widget.id.toString(), fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.taskType, typ.text(context), fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.gid, gid, fontSize: 16),
Row(children: [
SizedBox(
width: 80,
child: Center(
child: Text(i18n.gid,
textAlign: TextAlign.center,
style: TextStyle(color: cs.primary, fontSize: 16)))),
Expanded(
child: allowLink
? SelectableText.rich(TextSpan(
text: gid,
style: TextStyle(color: cs.secondary, fontSize: 16),
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap = () {
context.push("/gallery/${task.base.gid}",
extra: GalleryPageExtra(title: title));
}))
: SelectableText(gid,
style: TextStyle(color: cs.secondary, fontSize: 16))),
]),
task.base.token.isEmpty
? Container()
: Divider(indent: indent, endIndent: endIndent),
@@ -324,8 +354,12 @@ class _TaskPage extends State<TaskPage> {
final indent = endIndent + 70;
return Column(key: ValueKey("task_detail_meta_${widget.id}"), children: [
_KeyValue(i18n.title2, meta.title, fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.titleJpn, meta.titleJpn, fontSize: 16),
meta.titleJpn.isNotEmpty
? Divider(indent: indent, endIndent: endIndent)
: Container(),
meta.titleJpn.isNotEmpty
? _KeyValue(i18n.titleJpn, meta.titleJpn, fontSize: 16)
: Container(),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.category, meta.category, fontSize: 16),
Divider(indent: indent, endIndent: endIndent),