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),