@@ -189,13 +189,22 @@ class MediaCellBloc extends Bloc<MediaCellEvent, MediaCellState> {
189189 return ;
190190 }
191191
192- mediaUploadProgress ?? = MediaUploadProgress (
193- fileId: id,
194- uploadState: progress.progress >= 1
195- ? MediaUploadState .completed
196- : MediaUploadState .uploading,
197- fileProgress: progress,
198- );
192+ if (mediaUploadProgress == null ) {
193+ mediaUploadProgress ?? = MediaUploadProgress (
194+ fileId: id,
195+ uploadState: progress.progress >= 1
196+ ? MediaUploadState .completed
197+ : MediaUploadState .uploading,
198+ fileProgress: progress,
199+ );
200+ } else {
201+ mediaUploadProgress = mediaUploadProgress.copyWith (
202+ uploadState: progress.progress >= 1
203+ ? MediaUploadState .completed
204+ : MediaUploadState .uploading,
205+ fileProgress: progress,
206+ );
207+ }
199208
200209 final uploadProgress = [...state.uploadProgress];
201210 uploadProgress
@@ -246,8 +255,17 @@ class MediaCellBloc extends Bloc<MediaCellEvent, MediaCellState> {
246255 add (MediaCellEvent .onProgressUpdate (file.id));
247256 }
248257
249- void _onProgressChanged (String id) =>
250- add (MediaCellEvent .onProgressUpdate (id));
258+ void _onProgressChanged (String id) {
259+ // Ignore events if the file is already uploaded
260+ final progress =
261+ state.uploadProgress.firstWhereOrNull ((u) => u.fileId == id);
262+ if (progress == null ||
263+ progress.uploadState == MediaUploadState .completed) {
264+ return ;
265+ }
266+
267+ add (MediaCellEvent .onProgressUpdate (id));
268+ }
251269
252270 /// Removes and disposes of a progress notifier if found
253271 ///
@@ -347,4 +365,19 @@ class MediaUploadProgress {
347365 final String fileId;
348366 final MediaUploadState uploadState;
349367 final FileProgress fileProgress;
368+
369+ @override
370+ String toString () =>
371+ 'MediaUploadProgress(fileId: $fileId , uploadState: $uploadState , fileProgress: $fileProgress )' ;
372+
373+ MediaUploadProgress copyWith ({
374+ MediaUploadState ? uploadState,
375+ FileProgress ? fileProgress,
376+ }) {
377+ return MediaUploadProgress (
378+ fileId: fileId,
379+ uploadState: uploadState ?? this .uploadState,
380+ fileProgress: fileProgress ?? this .fileProgress,
381+ );
382+ }
350383}
0 commit comments