mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 05:49:03 +08:00
Add refresh support for gallery page
This commit is contained in:
@@ -28,7 +28,11 @@ class GalleryBasicInfo extends StatelessWidget {
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 8),
|
||||
child: firstPage != null
|
||||
? Thumbnail(firstPage!, fileId: fileId, gid: gMeta.gid)
|
||||
? Thumbnail(firstPage!,
|
||||
fileId: fileId,
|
||||
gid: gMeta.gid,
|
||||
key: Key(
|
||||
"thumbnail${gMeta.gid}-${firstPage!.index}-$fileId"))
|
||||
: Container(),
|
||||
)),
|
||||
Expanded(
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import '../globals.dart';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../api/file.dart';
|
||||
import '../api/gallery.dart';
|
||||
import '../globals.dart';
|
||||
import 'gallery_basic_info.dart';
|
||||
import 'gallery_info_desktop.dart';
|
||||
import 'gallery_info_detail.dart';
|
||||
@@ -10,9 +11,12 @@ import 'tags.dart';
|
||||
import 'thumbnail_gridview.dart';
|
||||
|
||||
class GalleryInfo extends StatefulWidget {
|
||||
const GalleryInfo(this.gData, {super.key, this.files});
|
||||
const GalleryInfo(this.gData,
|
||||
{super.key, this.files, this.refreshIndicatorKey, this.onRefresh});
|
||||
final GalleryData gData;
|
||||
final EhFiles? files;
|
||||
final GlobalKey<RefreshIndicatorState>? refreshIndicatorKey;
|
||||
final Future<void> Function()? onRefresh;
|
||||
|
||||
@override
|
||||
State<GalleryInfo> createState() => _GalleryInfo();
|
||||
@@ -57,7 +61,7 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
|
||||
final int? firstFileId = widget.files != null && firstPage != null
|
||||
? widget.files!.files[firstPage!.token]!.firstOrNull?.id
|
||||
: null;
|
||||
return CustomScrollView(
|
||||
final v = CustomScrollView(
|
||||
controller: controller,
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
@@ -112,6 +116,20 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
|
||||
gid: widget.gData.meta.gid),
|
||||
],
|
||||
);
|
||||
if (widget.refreshIndicatorKey != null && widget.onRefresh != null) {
|
||||
return RefreshIndicator(
|
||||
key: widget.refreshIndicatorKey,
|
||||
onRefresh: widget.onRefresh!,
|
||||
child: ScrollConfiguration(
|
||||
behavior: ScrollConfiguration.of(context).copyWith(
|
||||
dragDevices: {
|
||||
PointerDeviceKind.touch,
|
||||
PointerDeviceKind.mouse,
|
||||
},
|
||||
),
|
||||
child: v));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -63,7 +63,10 @@ class GalleryInfoDesktop extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: gData.pages.isNotEmpty
|
||||
? Thumbnail(gData.pages.first,
|
||||
fileId: fileId, gid: gData.meta.gid)
|
||||
key: Key(
|
||||
"thumbnail${gData.meta.gid}-${gData.pages.first.index}-$fileId"),
|
||||
fileId: fileId,
|
||||
gid: gData.meta.gid)
|
||||
: Container())),
|
||||
Expanded(
|
||||
flex: 7,
|
||||
|
||||
@@ -24,7 +24,7 @@ class ThumbnailGridView extends StatelessWidget {
|
||||
final page = npages[index]!;
|
||||
final fileId =
|
||||
files != null ? files!.files[page.token]!.firstOrNull?.id : null;
|
||||
final key = Key("thumbnail$gid-${page.index}");
|
||||
final key = Key("thumbnail$gid-${page.index}-$fileId");
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Thumbnail(page,
|
||||
|
||||
@@ -36,6 +36,8 @@ class GalleryPage extends StatefulWidget {
|
||||
class _GalleryPage extends State<GalleryPage>
|
||||
with ThemeModeWidget, IsTopWidget2 {
|
||||
_GalleryPage();
|
||||
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
||||
GlobalKey<RefreshIndicatorState>();
|
||||
int _gid = 0;
|
||||
GalleryData? _data;
|
||||
EhFiles? _files;
|
||||
@@ -136,7 +138,11 @@ class _GalleryPage extends State<GalleryPage>
|
||||
body: isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _data != null
|
||||
? GalleryInfo(_data!, files: _files)
|
||||
? GalleryInfo(_data!,
|
||||
files: _files, refreshIndicatorKey: _refreshIndicatorKey,
|
||||
onRefresh: () async {
|
||||
await _fetchData();
|
||||
})
|
||||
: Center(
|
||||
child: Text("Error: $_error"),
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user