💄 Optimize file upload prograss indicates

This commit is contained in:
2025-11-09 01:59:24 +08:00
parent 5e7d77e1a1
commit e4019dadc8
10 changed files with 61 additions and 28 deletions

View File

@@ -44,7 +44,7 @@ class ChatInput extends HookConsumerWidget {
final Function(int) onDeleteAttachment;
final Function(int, int) onMoveAttachment;
final Function(List<UniversalFile>) onAttachmentsChanged;
final Map<String, Map<int, double>> attachmentProgress;
final Map<String, Map<int, double?>> attachmentProgress;
const ChatInput({
super.key,

View File

@@ -40,7 +40,7 @@ class MessageItem extends HookConsumerWidget {
final LocalChatMessage message;
final bool isCurrentUser;
final Function(String action)? onAction;
final Map<int, double>? progress;
final Map<int, double?>? progress;
final bool showAvatar;
final Function(String messageId) onJump;
final bool isSelectionMode;
@@ -689,7 +689,7 @@ class MessageHoverActionMenu extends StatelessWidget {
class MessageItemDisplayBubble extends HookConsumerWidget {
final LocalChatMessage message;
final bool isCurrentUser;
final Map<int, double>? progress;
final Map<int, double?>? progress;
final bool showAvatar;
final Function(String messageId) onJump;
final String? translatedText;
@@ -821,7 +821,7 @@ class MessageItemDisplayBubble extends HookConsumerWidget {
class MessageItemDisplayIRC extends HookConsumerWidget {
final LocalChatMessage message;
final bool isCurrentUser;
final Map<int, double>? progress;
final Map<int, double?>? progress;
final bool showAvatar;
final Function(String messageId) onJump;
final String? translatedText;
@@ -949,7 +949,7 @@ class MessageItemDisplayIRC extends HookConsumerWidget {
class MessageItemDisplayDiscord extends HookConsumerWidget {
final LocalChatMessage message;
final bool isCurrentUser;
final Map<int, double>? progress;
final Map<int, double?>? progress;
final bool showAvatar;
final Function(String messageId) onJump;
final String? translatedText;
@@ -1238,7 +1238,7 @@ class MessageQuoteWidget extends HookConsumerWidget {
}
class FileUploadProgressWidget extends StatelessWidget {
final Map<int, double>? progress;
final Map<int, double?>? progress;
final Color textColor;
final bool hasContent;
@@ -1266,7 +1266,9 @@ class FileUploadProgressWidget extends StatelessWidget {
'fileUploadingProgress'.tr(
args: [
(entry.key + 1).toString(),
(entry.value * 100).toStringAsFixed(1),
entry.value != null
? (entry.value! * 100).toStringAsFixed(1)
: '0.0',
],
),
style: TextStyle(

View File

@@ -411,10 +411,7 @@ class AttachmentPreview extends HookConsumerWidget {
),
Gap(6),
Center(
child: LinearProgressIndicator(
value:
progress != null ? progress! / 100.0 : null,
),
child: LinearProgressIndicator(value: progress),
),
],
),

View File

@@ -131,7 +131,7 @@ class ArticleComposeAttachments extends ConsumerWidget {
],
),
children: [
ValueListenableBuilder<Map<int, double>>(
ValueListenableBuilder<Map<int, double?>>(
valueListenable: state.attachmentProgress,
builder: (context, progressMap, _) {
return Wrap(

View File

@@ -33,7 +33,7 @@ class ComposeState {
final TextEditingController slugController;
final ValueNotifier<int> visibility;
final ValueNotifier<List<UniversalFile>> attachments;
final ValueNotifier<Map<int, double>> attachmentProgress;
final ValueNotifier<Map<int, double?>> attachmentProgress;
final ValueNotifier<SnPublisher?> currentPublisher;
final ValueNotifier<bool> submitting;
final ValueNotifier<List<SnPostCategory>> categories;
@@ -520,7 +520,7 @@ class ComposeLogic {
onProgress: (progress, _) {
state.attachmentProgress.value = {
...state.attachmentProgress.value,
index: progress,
index: progress ?? 0.0,
};
},
).future;

View File

@@ -246,7 +246,8 @@ class _ShareSheetState extends ConsumerState<ShareSheet> {
onProgress: (progress, _) {
if (mounted) {
setState(() {
_fileUploadProgress[messageId]?[idx] = progress;
_fileUploadProgress[messageId]?[idx] =
progress ?? 0.0;
});
}
},