search image in SauceNAO
This commit is contained in:
@ -37,13 +37,7 @@ class ImageGrid extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ImageGridState extends State<ImageGrid> {
|
||||
late ScrollController _scrollController;
|
||||
|
||||
List<ImageResp> imageList = [];
|
||||
int pageNum = 1;
|
||||
int pageSize = 10;
|
||||
bool hasMore = true;
|
||||
bool loading = false;
|
||||
|
||||
final PagingController<int, ImageResp> _pagingController =
|
||||
PagingController(firstPageKey: 1);
|
||||
@ -66,26 +60,6 @@ class _ImageGridState extends State<ImageGrid> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> loadImages() async {
|
||||
loading = true;
|
||||
if (!hasMore) {
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
print(pageNum);
|
||||
var resp = await dio.get("/image/history",
|
||||
queryParameters: {"page": pageNum, "size": pageSize});
|
||||
ImageListResp imageListResp = ImageListResp.fromJson(resp.data);
|
||||
hasMore = imageListResp.hasNext;
|
||||
pageNum = pageNum + 1;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
imageList.addAll(imageListResp.list);
|
||||
});
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
@ -93,39 +67,19 @@ class _ImageGridState extends State<ImageGrid> {
|
||||
_fetchPage(pageKey);
|
||||
});
|
||||
super.initState();
|
||||
// print("init");
|
||||
//
|
||||
// _scrollController = ScrollController(initialScrollOffset: 5.0)
|
||||
// ..addListener(() {
|
||||
// if (_scrollController.offset >=
|
||||
// _scrollController.position.maxScrollExtent &&
|
||||
// !_scrollController.position.outOfRange) {
|
||||
// print("到底了 controller $loading");
|
||||
// if (!loading) {
|
||||
// loadImages();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// loadImages();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PagedGridView(
|
||||
pagingController: _pagingController,
|
||||
builderDelegate: PagedChildBuilderDelegate<ImageResp>(
|
||||
itemBuilder: (context, item, index) => ImageItem(image: item)),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
||||
);
|
||||
// return GridView.builder(
|
||||
// itemCount: imageList.length,
|
||||
// controller: _scrollController,
|
||||
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
// crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
||||
// itemBuilder: (BuildContext context, int index) {
|
||||
// return ImageItem(image: imageList[index]);
|
||||
// });
|
||||
return RefreshIndicator(
|
||||
child: PagedGridView(
|
||||
pagingController: _pagingController,
|
||||
builderDelegate: PagedChildBuilderDelegate<ImageResp>(
|
||||
itemBuilder: (context, item, index) => ImageItem(image: item)),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
||||
),
|
||||
onRefresh: () => Future.sync(() => _pagingController.refresh()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +100,6 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
||||
if (_contextMenuController.isShown) {
|
||||
_contextMenuController.remove();
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -233,61 +186,24 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoContextMenu(
|
||||
actions: [
|
||||
CupertinoContextMenuAction(
|
||||
trailingIcon: CupertinoIcons.delete,
|
||||
child: const Text('删除'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
// Navigator.pop(context);
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// builder: (BuildContext dialogContext) => AlertDialog(
|
||||
// title: const Text('删除图片'),
|
||||
// content: const Text("确认删除图片"),
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// onPressed: () =>
|
||||
// Navigator.pop(dialogContext, 'Cancel'),
|
||||
// child: const Text('Cancel'),
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(dialogContext, 'OK');
|
||||
// // Navigator.pop(context);
|
||||
// dio
|
||||
// .delete("/image/delete/${widget.image.id}")
|
||||
// .then((resp) {
|
||||
// ref.read(uniqueIdProvider.notifier).updateId();
|
||||
// // context.go("/");
|
||||
// });
|
||||
// },
|
||||
// child: const Text('OK'),
|
||||
// ),
|
||||
// ],
|
||||
// ));
|
||||
},
|
||||
)
|
||||
],
|
||||
child: GestureDetector(
|
||||
onSecondaryTapUp: (TapUpDetails details) {
|
||||
_showContextMenu(details.globalPosition);
|
||||
},
|
||||
onTap: () {
|
||||
context.go(Uri(
|
||||
path: "/detail",
|
||||
queryParameters: {"id": "${widget.image.id}"}).toString());
|
||||
},
|
||||
child: Image.network(
|
||||
kIsWeb
|
||||
? "/images-api/?url=${dio.options.baseUrl}/image/${widget.image.file_path}&w=512"
|
||||
: 'https://raichi.hodokencho.com/images-api/?url=${dio.options.baseUrl}/image/${widget.image.file_path}&w=512',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (BuildContext context, o, err) {
|
||||
return const Icon(Icons.error_outline);
|
||||
},
|
||||
),
|
||||
));
|
||||
return GestureDetector(
|
||||
onSecondaryTapUp: (TapUpDetails details) {
|
||||
_showContextMenu(details.globalPosition);
|
||||
},
|
||||
onTap: () {
|
||||
context.go(Uri(
|
||||
path: "/detail",
|
||||
queryParameters: {"id": "${widget.image.id}"}).toString());
|
||||
},
|
||||
child: Image.network(
|
||||
kIsWeb
|
||||
? "/images-api/?url=${dio.options.baseUrl}/image/${widget.image.file_path}&w=512"
|
||||
: 'https://raichi.hodokencho.com/images-api/?url=${dio.options.baseUrl}/image/${widget.image.file_path}&w=512',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (BuildContext context, o, err) {
|
||||
return const Icon(Icons.error_outline);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user