💄 Optimize uploader

This commit is contained in:
LittleSheep 2024-08-21 10:01:09 +08:00
parent 498bb0e5fb
commit 221b97901f
3 changed files with 30 additions and 14 deletions

View File

@ -14,7 +14,7 @@ class AttachmentUploadTask {
Map<String, dynamic>? metadata; Map<String, dynamic>? metadata;
Map<String, int>? chunkFiles; Map<String, int>? chunkFiles;
double progress = 0; double? progress;
bool isUploading = false; bool isUploading = false;
bool isCompleted = false; bool isCompleted = false;
dynamic error; dynamic error;
@ -76,6 +76,7 @@ class AttachmentUploaderController extends GetxController {
_startProgressSyncTimer(); _startProgressSyncTimer();
queueOfUpload[queueIndex].isUploading = true; queueOfUpload[queueIndex].isUploading = true;
queueOfUpload[queueIndex].progress = 0;
final task = queueOfUpload[queueIndex]; final task = queueOfUpload[queueIndex];
try { try {
@ -121,6 +122,7 @@ class AttachmentUploaderController extends GetxController {
} }
queueOfUpload[idx].isUploading = true; queueOfUpload[idx].isUploading = true;
queueOfUpload[idx].progress = 0;
final task = queueOfUpload[idx]; final task = queueOfUpload[idx];
try { try {

View File

@ -174,7 +174,7 @@ const i18nEnglish = {
'attachmentAttached': 'Exists Files', 'attachmentAttached': 'Exists Files',
'attachmentUploadBlocked': 'attachmentUploadBlocked':
'Upload blocked, there is currently a task in progress...', 'Upload blocked, there is currently a task in progress...',
'attachmentAdd': 'Attach attachments', 'attachmentAdd': 'Attach file',
'attachmentAddGalleryPhoto': 'Gallery photo', 'attachmentAddGalleryPhoto': 'Gallery photo',
'attachmentAddGalleryVideo': 'Gallery video', 'attachmentAddGalleryVideo': 'Gallery video',
'attachmentAddCameraPhoto': 'Capture photo', 'attachmentAddCameraPhoto': 'Capture photo',

View File

@ -64,7 +64,7 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (auth.isAuthorized.isFalse) return; if (auth.isAuthorized.isFalse) return;
if (widget.singleMode) { if (!widget.singleMode) {
final medias = await _imagePicker.pickMultiImage( final medias = await _imagePicker.pickMultiImage(
maxWidth: widget.imageMaxWidth, maxWidth: widget.imageMaxWidth,
maxHeight: widget.imageMaxHeight, maxHeight: widget.imageMaxHeight,
@ -341,9 +341,25 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
fontFamily: 'monospace', fontFamily: 'monospace',
), ),
), ),
Text( Row(
'In queue #${index + 1}', children: [
style: const TextStyle(fontSize: 12), FutureBuilder(
future: element.file.length(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const SizedBox();
return Text(
_formatBytes(snapshot.data!),
style: Theme.of(context).textTheme.bodySmall,
);
},
),
const SizedBox(width: 6),
if (element.progress != null)
Text(
'${(element.progress! * 100).toStringAsFixed(2)}%',
style: Theme.of(context).textTheme.bodySmall,
),
],
), ),
], ],
), ),
@ -590,15 +606,13 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> {
children: [ children: [
Expanded( Expanded(
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Expanded( Text(
child: Text( 'attachmentAdd'.tr,
'attachmentAdd'.tr, style: Theme.of(context).textTheme.headlineSmall,
style: maxLines: 1,
Theme.of(context).textTheme.headlineSmall, overflow: TextOverflow.ellipsis,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
Obx(() { Obx(() {