Md Shahnawaz
Md Shahnawaz

Reputation: 584

How to get the callback of Download Complete a file using Dio in Flutter?

I have this code

 await dio.download(fileUrl, "${fileDir.path}/$fileName",
          onReceiveProgress: (received, total) {
        if (total != -1) {
          print("Rec: $received , Total: $total");
          debugPrint("Directory path : " + filePath + "/" + fileName);
          setState(() {
            downloadProgressString =
                ((received / total) * 100).toStringAsFixed(0) + "%";
          });
        }
      });

Like onReceiveProgress, do we have any other callback for 'Download Complete'?

Upvotes: 1

Views: 1177

Answers (1)

Gazihan Alankus
Gazihan Alankus

Reputation: 11984

The future it returns is the callback.

  await dio.download(fileUrl, "${fileDir.path}/$fileName",
      onReceiveProgress: (received, total) {
    if (total != -1) {
      print("Rec: $received , Total: $total");
      debugPrint("Directory path : " + filePath + "/" + fileName);
      setState(() {
        downloadProgressString =
            ((received / total) * 100).toStringAsFixed(0) + "%";
      });
    }
  });
  // HERE
  print("download complete!");

Upvotes: 1

Related Questions