upload
This commit is contained in:
@ -12,45 +12,73 @@ class Gallery extends ConsumerStatefulWidget {
|
||||
ConsumerState<Gallery> createState() => _GalleryState();
|
||||
}
|
||||
|
||||
List<ImageResp> imageList = [];
|
||||
|
||||
class _GalleryState extends ConsumerState<Gallery> {
|
||||
List<ImageResp> imageList = [];
|
||||
int pageNum = 1;
|
||||
int pageSize = 10;
|
||||
bool hasMore = false;
|
||||
bool loading = true;
|
||||
|
||||
Future<dynamic> loadImages() async {
|
||||
var resp = await dio.get("/image/history");
|
||||
loading = true;
|
||||
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 = ImageListResp.fromJson(resp.data).list;
|
||||
imageList.addAll(imageListResp.list);
|
||||
});
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
void resetState() {
|
||||
imageList = [];
|
||||
pageNum = 1;
|
||||
hasMore = false;
|
||||
loading = true;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
print("init");
|
||||
// resetState();
|
||||
loadImages();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GridView.builder(
|
||||
// controller: ,
|
||||
itemCount: imageList.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: MediaQuery.of(context).size.width > 640 ? 5 : 3),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index == imageList.length - 1 && imageList.length < 200) {
|
||||
if (hasMore && pageNum != 1 && !loading) {
|
||||
loadImages();
|
||||
} else {
|
||||
print("没有了");
|
||||
}
|
||||
}
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
context.go("/detail");
|
||||
context.go(Uri(
|
||||
path: "/detail",
|
||||
queryParameters: {"id": "${imageList[index].id}"})
|
||||
.toString());
|
||||
},
|
||||
child: Image.network(
|
||||
"${dio.options.baseUrl}/image/thumbnail/${imageList[index].file_path}",
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (BuildContext context, o, err) {
|
||||
return const Icon(Icons.error_outline);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user