0

I want to download video in flutter with progress indicator. I know video will be huge so its better to use flutter_downloader. I tried what is told here. But I am unable to achieve what I want. The FlutterDownloader.enqueue method does nothing (it seems). No download notification on any logs.

I want to add the progress a stream which I have used for a stream builder.

 ReceivePort _port = ReceivePort();
      IsolateNameServer.registerPortWithName(
          _port.sendPort, 'downloader_send_port');
      _port.listen((dynamic data) {
        print('UI isolate callbac: $data');
        String id = data[0];
        DownloadTaskStatus status = data[1];
        int progress = data[2];
       
        progressStream.add(progress.toDouble());
      }).onDone(() {
    
        Fluttertoast.showToast(msg: "Video downloaded");
      
        progressStream.close();
       
        IsolateNameServer.removePortNameMapping('downloader_send_port');
      });

Then I have requested the download with enqueue method

 final taskId = await FlutterDownloader.enqueue(
      url:
          'http://barbra-coco.dyndns.org/student/learning_android_studio.pdf',
      savedDir: (await getExternalStorageDirectory())!.path +
          Platform.pathSeparator +
          folder,
      fileName: title,
      showNotification:
          true, 
      openFileFromNotification:
          false,  
    );

This is the downloadCallback method

  static void downloadCallback(
  String id, DownloadTaskStatus status, int progress) {
print(
    'Background Isolate Callback: task ($id) is in status ($status) and process ($progress)');
final SendPort? send =
    IsolateNameServer.lookupPortByName('downloader_send_port');
send!.send([id, status, progress]);
}
keval
  • 39
  • 1
  • 7
  • where did initialized `flutter_downloader`? and did you set debug mode to true? – Sajad Abdollahi Aug 14 '21 at 06:18
  • I initialized it in the main method void main() async { WidgetsFlutterBinding.ensureInitialized(); await FlutterDownloader.initialize(debug: debug); runApp(new MyApp()); } I tried running the example app. but gives Backoff delay duration less than minimum value – keval Aug 14 '21 at 08:00

0 Answers0