From 30a4a9ebda7376a0d72f42d283ea6eff451065a8 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:45:47 -0300 Subject: [PATCH] feat(upload) - use size of the files instead of the data items being uploaded --- lib/blocs/upload/upload_cubit.dart | 12 ++++++++++++ lib/blocs/upload/upload_state.dart | 5 ++++- lib/components/upload_form.dart | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/blocs/upload/upload_cubit.dart b/lib/blocs/upload/upload_cubit.dart index 0c758da48..37d8a0cbc 100644 --- a/lib/blocs/upload/upload_cubit.dart +++ b/lib/blocs/upload/upload_cubit.dart @@ -120,6 +120,7 @@ class UploadCubit extends Cubit { showArnsCheckbox: showArnsCheckbox, showArnsNameSelection: false, loadingArNSNames: true, + totalSize: await _getTotalSize(), ), ); @@ -156,6 +157,7 @@ class UploadCubit extends Cubit { isArConnect: (state as UploadReadyToPrepare).isArConnect, showArnsCheckbox: showArnsCheckbox, showArnsNameSelection: false, + totalSize: await _getTotalSize(), ), ); } @@ -176,6 +178,16 @@ class UploadCubit extends Cubit { } } + Future _getTotalSize() async { + int size = 0; + + for (final file in files) { + size += await file.ioFile.length; + } + + return size; + } + void initialScreenNext({required LicenseCategory licenseCategory}) { if (state is UploadReady) { final readyState = state as UploadReady; diff --git a/lib/blocs/upload/upload_state.dart b/lib/blocs/upload/upload_state.dart index a855aa938..5cacacf24 100644 --- a/lib/blocs/upload/upload_state.dart +++ b/lib/blocs/upload/upload_state.dart @@ -97,6 +97,7 @@ class UploadReady extends UploadState { final bool showArnsNameSelection; final bool loadingArNSNames; final bool loadingArNSNamesError; + final int totalSize; final bool isArConnect; @@ -112,6 +113,7 @@ class UploadReady extends UploadState { required this.showArnsNameSelection, this.loadingArNSNames = false, this.loadingArNSNamesError = false, + required this.totalSize, }); // copyWith @@ -129,6 +131,7 @@ class UploadReady extends UploadState { bool? showArnsNameSelection, bool? loadingArNSNames, bool? loadingArNSNamesError, + int? totalSize, }) { return UploadReady( loadingArNSNames: loadingArNSNames ?? this.loadingArNSNames, @@ -144,6 +147,7 @@ class UploadReady extends UploadState { showArnsNameSelection ?? this.showArnsNameSelection, loadingArNSNamesError: loadingArNSNamesError ?? this.loadingArNSNamesError, + totalSize: totalSize ?? this.totalSize, ); } @@ -155,7 +159,6 @@ class UploadReady extends UploadState { loadingArNSNamesError, loadingArNSNames, showArnsCheckbox, - ]; @override diff --git a/lib/components/upload_form.dart b/lib/components/upload_form.dart index 93a81f82c..1b7c9c84b 100644 --- a/lib/components/upload_form.dart +++ b/lib/components/upload_form.dart @@ -1568,7 +1568,7 @@ class _StatsScreenState extends State { ), TextSpan( text: filesize( - widget.readyState.paymentInfo.totalSize, + widget.readyState.totalSize, ), style: typography.paragraphNormal( fontWeight: ArFontWeight.bold,