Code Monkey home page Code Monkey logo

fl_downloader's Introduction

fl_downloader

Pub Version

A plugin to download files using the native capabilities.

On Android it uses the DownloadManager system service and, on Windows, it uses BITS to download files to user's Downloads folder and, on iOS, it uses the URLSession to download files to the App Documents folder.

iOS Configuration

If you don`t want to show downloaded files to the user on the Files app, there is no need for special configuration.

If you want to show downloaded files to the user on the Files app, add the following lines to your info.plist file:

<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>

Android Configuration

There is no need for special configuration on Android 10+.

If your app supports Android 9 (API 28) or bellow it is mandatory to call requestPermission() before download() and check the permission status.

NOTE: This plugins expects that compileSdk is the latest Android SDK, eg.:

android {
    compileSdk 34

    [...]
}

Windows Configuration

There is no need for special configuration on Windows.

NOTE: The following pages are important to know the limitations and to test the use of BITS:

About BITS
HTTP Requirements for BITS Downloads
BITSAdmin tool

fl_downloader's People

Contributors

inceptusp avatar victorths avatar marlonjd avatar

Stargazers

Jessica Viana avatar Lalli (Naiade Lima) avatar Marcos Koch Salvador avatar Mahan avatar

Watchers

 avatar

fl_downloader's Issues

how to set path of the downloaded file?

Hi, first of all i wanna say thanks very much to created this lib which is so helpfull. But i wanna ask, is it possible to set custom path for the file. or check first if the file exist it just directly open it.

Enhancement: event.url

This is an enhancement request. For purposes of providing different handling of different urls in the applications built, it would be useful to have an event.url attribute on the event object so that one knows the URL requested and can possibly provided different logic depending on the URL. I didn't see another way to get this information.

Getting the status of the downloading-files if app opend after killed

Thanks for the Handy Package,

When start downloading a file, then the app closed (While the file still downloading, let say with 50% percent remaining ..)
Then if we open the app (before download completed..), How I can check the progress of that file ?

I tried to use:
progressStream = FlDownloader.progressStream.listen((event) { } ....

But not worked after app killed and open again.

Question about download()

What is the significance of the int returned by FlDownloader.download() ?
What values mean success and failure?

Download progress freezes at some point with slow connection

Grabacion.de.pantalla.2022-10-29.a.las.21.34.28.mov
Grabacion.de.pantalla.2022-10-29.a.las.21.41.26.mov

This is my code:

  int progress = 0;
  String? status;
  late StreamSubscription progressStream;

  void removeOldInstallers()  {
    final downloads = Directory('/storage/emulated/0/Download').listSync();
    final installers = downloads.where((file) => file.path.contains('adguard-home-manager'));
    for (FileSystemEntity installer in installers) {
      if (installer.existsSync()) {
        installer.deleteSync();
      }
    }
  }


 @override
  void initState() {
    removeOldInstallers();

    FlDownloader.initialize();
    progressStream = FlDownloader.progressStream.listen((event) {
      if (event.status == DownloadStatus.successful) {
        setState(() => progress = event.progress); 
        Navigator.pop(context);
        widget.onFinish(event.filePath!);
      }
      else if (event.status == DownloadStatus.running) {
        print(event.progress);
        setState(() {
          progress = event.progress;
          status = null;
        });
      }
      else if (event.status == DownloadStatus.paused) {
        setState(() => status == "Paused");
      }
      else if (event.status == DownloadStatus.pending) {
        setState(() => status == "Pending");
      }
      else if (event.status == DownloadStatus.failed) {
        setState(() => status == "Failed");
      }
      else if (event.status == DownloadStatus.canceling) {
        setState(() => status == "Canceling");
      }
    });

    FlDownloader.download(widget.url, fileName: 'adguard-home-manager_v${widget.version}.apk');

    super.initState();
  }

Android - java.lang.ArithmeticException: divide by zero

Hello,

For some download, plugin crash with java.lang.ArithmeticException: divide by zero

In file FlDownloaderPlugin.kt line 172, the test if (total >= 0) must be updated to protect progress = (downloaded * 100L / total).toInt()

Great plugin.

Thanks for your work.

iOS - swift::swift_dynamicCastFailure

Hi,

I don't know the conditions of this failure.
The handle code should be protected with a try/catch returning error flutter channel result ?

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  0


Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x00000001c5d2f200 __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib       	0x00000001d5e701ac pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib             	0x0000000190cd5ca0 abort + 180 (abort.c:118)
3   libswiftCore.dylib            	0x0000000183afc304 swift::fatalErrorv(unsigned int, char const*, char*) + 136 (Errors.cpp:374)
4   libswiftCore.dylib            	0x0000000183afc324 swift::fatalError(unsigned int, char const*, ...) + 32 (Errors.cpp:382)
5   libswiftCore.dylib            	0x0000000183af1c80 swift::swift_dynamicCastFailure(void const*, char const*, void const*, char const*, char const*) + 80 (Casting.cpp:407)
6   libswiftCore.dylib            	0x0000000183af1cfc swift::swift_dynamicCastFailure(swift::TargetMetadata<swift::InProcess> const*, swift::TargetMetadata<swift::InProcess> const*, char const*) + 124 (Casting.cpp:421)
7   libswiftCore.dylib            	0x0000000183af65b4 swift_dynamicCast + 344 (DynamicCast.cpp:2547)
8   fl_downloader                 	0x0000000104c50b38 specialized SwiftFlDownloaderPlugin.handle(_:result:) + 1400 (SwiftFlDownloaderPlugin.swift:34)
9   fl_downloader                 	0x0000000104c4ded8 $s13fl_downloader23SwiftFlDownloaderPluginC6handle_6resultySo17FlutterMethodCallC_yypSgctF015$syXlSgIeyBy_ypN7Iegn_TRyXlSgIeyBy_Tf1ncn_n + 16 (<compiler-generated>:0)
10  fl_downloader                 	0x0000000104c4ded8 @objc SwiftFlDownloaderPlugin.handle(_:result:) + 84

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.