image detail
This commit is contained in:
@ -18,6 +18,8 @@ class HomePage extends ConsumerStatefulWidget {
|
||||
|
||||
class _HomePageState extends ConsumerState<HomePage> {
|
||||
int selectedIndex = 0;
|
||||
bool uploading = false;
|
||||
double uploadProgress = 0;
|
||||
final tabList = [
|
||||
{"path": "/", "title": "相册"},
|
||||
{"path": "/profile", "title": "用户资料"},
|
||||
@ -45,48 +47,69 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
),
|
||||
elevation: 10,
|
||||
),
|
||||
floatingActionButton: selectedIndex == 0
|
||||
? FloatingActionButton(
|
||||
onPressed: () async {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(type: FileType.image);
|
||||
floatingActionButton:
|
||||
selectedIndex == 0 && GoRouterState.of(context).fullpath == "/"
|
||||
? (!uploading
|
||||
? FloatingActionButton(
|
||||
onPressed: () async {
|
||||
FilePickerResult? result = await FilePicker.platform
|
||||
.pickFiles(type: FileType.image);
|
||||
|
||||
if (result != null) {
|
||||
String? filePath = result.files.first.path;
|
||||
if (filePath == null) {
|
||||
return;
|
||||
}
|
||||
String? mimeType = lookupMimeType(filePath);
|
||||
FormData data = FormData.fromMap({
|
||||
"pic": await MultipartFile.fromFile(filePath,
|
||||
filename: result.files.first.name,
|
||||
contentType: MediaType(mimeType!.split("/").first,
|
||||
mimeType.split("/").last))
|
||||
});
|
||||
await dio.post("/image/upload", data: data).then((value) {
|
||||
ref.read(uniqueIdProvider.notifier).updateId();
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text("上传成功")
|
||||
],
|
||||
if (result != null) {
|
||||
String? filePath = result.files.first.path;
|
||||
if (filePath == null) {
|
||||
return;
|
||||
}
|
||||
String? mimeType = lookupMimeType(filePath);
|
||||
FormData data = FormData.fromMap({
|
||||
"pic": await MultipartFile.fromFile(filePath,
|
||||
filename: result.files.first.name,
|
||||
contentType: MediaType(
|
||||
mimeType!.split("/").first,
|
||||
mimeType.split("/").last))
|
||||
});
|
||||
setState(() {
|
||||
uploading = true;
|
||||
});
|
||||
await dio.post("/image/upload", data: data,
|
||||
onSendProgress: (sended, total) {
|
||||
print("$sended / $total");
|
||||
setState(() {
|
||||
uploadProgress = sended / total;
|
||||
});
|
||||
}).then((value) {
|
||||
setState(() {
|
||||
uploading = false;
|
||||
});
|
||||
ref.read(uniqueIdProvider.notifier).updateId();
|
||||
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 {}
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: FloatingActionButton(
|
||||
onPressed: null,
|
||||
child: CircularProgressIndicator(
|
||||
value: uploadProgress,
|
||||
),
|
||||
backgroundColor: Colors.lightGreen,
|
||||
));
|
||||
});
|
||||
} else {}
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: null,
|
||||
))
|
||||
: null,
|
||||
body: Row(
|
||||
children: [
|
||||
MediaQuery.of(context).size.width > 640
|
||||
|
Reference in New Issue
Block a user