upload
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class ImageDetail extends StatefulWidget {
|
||||
const ImageDetail({Key? key}) : super(key: key);
|
||||
@ -10,6 +11,8 @@ class ImageDetail extends StatefulWidget {
|
||||
class _ImageDetailState extends State<ImageDetail> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
return Center(
|
||||
child: Text(GoRouterState.of(context).queryParams["id"] ?? ""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
@ -21,6 +21,7 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
{"path": "/", "title": "相册"},
|
||||
{"path": "/profile", "title": "用户"}
|
||||
];
|
||||
int key = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -58,26 +59,25 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
contentType: MediaType(mimeType!.split("/").first,
|
||||
mimeType.split("/").last))
|
||||
});
|
||||
await dio.post("/image/upload", data: data);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text("上传成功")
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.lightGreen,
|
||||
));
|
||||
await dio.post("/image/upload", data: data).then((value) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text("上传成功")
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.lightGreen,
|
||||
));
|
||||
});
|
||||
} else {}
|
||||
|
||||
// context.go("/login");
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
@ -99,7 +99,9 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
setState(() {
|
||||
selectedIndex = idx;
|
||||
});
|
||||
context.go(tabList[idx]["path"] ?? "");
|
||||
context.go(Uri(
|
||||
path: tabList[idx]["path"] ?? "",
|
||||
).toString());
|
||||
},
|
||||
destinations: const [
|
||||
NavigationRailDestination(
|
||||
|
@ -89,12 +89,9 @@ class _LoginFormState extends ConsumerState<LoginForm> {
|
||||
print(resp.statusCode);
|
||||
}
|
||||
} catch (e) {
|
||||
// print(e is DioError);
|
||||
// DioError err = e;
|
||||
if (e is DioError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(e.response?.data["msg"] ?? "请求错误")));
|
||||
// print(e.response?.data["msg"] ?? "请求错误");
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
@ -11,6 +11,7 @@ class MyMaterialRouterConfig {
|
||||
|
||||
MyMaterialRouterConfig(String? token) {
|
||||
router = GoRouter(
|
||||
initialLocation: "/",
|
||||
routes: <RouteBase>[
|
||||
ShellRoute(
|
||||
builder: (BuildContext context, GoRouterState state, Widget child) {
|
||||
|
Reference in New Issue
Block a user