Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Download Video from Online and store it local Device then play video on Flutter apps Using video player?

I want to develop a flutter application where users can download all Videos from Online by one single button and store it local Device then play those videos offline on Flutter apps Using video player?

I did this by assets video. But if I use video from assets and build the application then the apk size will bigger. That's why I want to make this flutter application where users open the app and click one single button by button on pressed the list videos downloaded from the predefined server via a link in selected widgets. Then users can play those videos via video player.

like image 407
Masud Sarker Avatar asked Oct 17 '25 20:10

Masud Sarker


1 Answers

You might wanna give a try to the dio package it is an http client that supports file downloading and save it locally to a given path.

Here's a code sample (source: iampawan's Github)

Future downloadFile(String url) async {
  Dio dio = Dio();

  try {
    var dir = await getApplicationDocumentsDirectory();
    await dio.download(url, "${dir.path}/myFile.txt", onProgress: (rec, total) {
      print("Rec: $rec , Total: $total");
    });
  } catch (e) {
    print(e);
  }
  print("Download completed");
}
like image 80
Guillaume Roux Avatar answered Oct 20 '25 10:10

Guillaume Roux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!