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