CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.16k stars 359 forks source link

[BUG] FileSaver.SaveAsync Progress callback percentage #1794

Open NRTnarathip opened 3 months ago

NRTnarathip commented 3 months ago

Is there an existing issue for this?

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

My code

var progress = new Progress<double>((percent) =>
 {
     Console.WriteLine($"On update FileSaver: {percent}");
 });

FileSaver.SaveAsync(fileName, stream, progress, cancelToken) 

The progress callback "percent" it's always return 0

Expected Behavior

it's should return 0.11199 or 0.5123123 or 0.22332

How to fix code ref: https://github.com/CommunityToolkit/Maui/blob/d7a84df2b2d8db8c1597cabf32de63cd3dccd449/src/CommunityToolkit.Maui.Core/Essentials/FileSaver/FileSaverImplementation.android.cs#L105

just change progress?.Report(totalRead / stream.Length); to progress?.Report((double)totalRead / stream.Length);

Thanks you

Steps To Reproduce

.

Link to public reproduction project repository

N.A.

Environment

- .NET MAUI CommunityToolkit:8.0.0

Anything else?

No response

NRTnarathip commented 3 months ago

And i found code here same like this issue calculate wrong in file **.shared.cs

https://github.com/CommunityToolkit/Maui/blob/d7a84df2b2d8db8c1597cabf32de63cd3dccd449/src/CommunityToolkit.Maui.Core/Essentials/FileSaver/FileSaverImplementation.shared.cs#L86