infinite scroll
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -47,82 +48,84 @@ class _HomePageState extends ConsumerState<HomePage> {
|
||||
),
|
||||
elevation: 10,
|
||||
),
|
||||
floatingActionButton:
|
||||
selectedIndex == 0 && GoRouterState.of(context).fullpath == "/"
|
||||
? (!uploading
|
||||
? 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))
|
||||
});
|
||||
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("上传成功")
|
||||
],
|
||||
if (result != null) {
|
||||
String fileName = result.files.first.name;
|
||||
String? mimeType = lookupMimeType(fileName);
|
||||
MultipartFile file;
|
||||
if (kIsWeb) {
|
||||
final fileBytes = result.files.first.bytes;
|
||||
file = MultipartFile.fromBytes(fileBytes as List<int>,
|
||||
filename: result.files.first.name,
|
||||
contentType: MediaType(mimeType!.split("/").first,
|
||||
mimeType.split("/").last));
|
||||
} else {
|
||||
String? filePath = result.files.first.path;
|
||||
if (filePath == null) {
|
||||
return;
|
||||
}
|
||||
file = await MultipartFile.fromFile(filePath,
|
||||
filename: result.files.first.name,
|
||||
contentType: MediaType(mimeType!.split("/").first,
|
||||
mimeType.split("/").last));
|
||||
}
|
||||
FormData data = FormData.fromMap({"pic": file});
|
||||
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(const SnackBar(
|
||||
content: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
backgroundColor: Colors.lightGreen,
|
||||
));
|
||||
});
|
||||
} else {}
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: FloatingActionButton(
|
||||
onPressed: null,
|
||||
child: CircularProgressIndicator(
|
||||
value: uploadProgress,
|
||||
),
|
||||
))
|
||||
: null,
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text("上传成功")
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.lightGreen,
|
||||
));
|
||||
});
|
||||
} else {}
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: FloatingActionButton(
|
||||
onPressed: null,
|
||||
child: CircularProgressIndicator(
|
||||
value: uploadProgress,
|
||||
),
|
||||
))
|
||||
: null,
|
||||
body: Row(
|
||||
children: [
|
||||
MediaQuery.of(context).size.width > 640
|
||||
? NavigationRail(
|
||||
elevation: 10,
|
||||
backgroundColor: const Color(0xffebf6f5),
|
||||
leading: MediaQuery.of(context).size.width >= 1008
|
||||
? const Text(
|
||||
"Side Header",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 36),
|
||||
)
|
||||
: null,
|
||||
onDestinationSelected: (idx) {
|
||||
setState(() {
|
||||
selectedIndex = idx;
|
||||
|
||||
Reference in New Issue
Block a user