skip to Main Content

I have a flutter web app integrated with firebase.
By pressing a button, I am able to open in a new tab a public URL file that is stored in Google Cloud storage through the command: launchUrl(Uri.parse(gcs_url)); What I would like instead is to download the file to the local Downloads folder. Sorry I am a flutter beginner and despite this being a basic task, I am having a lot of problems. Note that this is a web application. The command should work on Windows, iOS, and Linux.

Thank you

2

Answers


  1. try dio package to download file.

    import 'package:dio/dio.dart';
    
    final dio = Dio();
    var pathToSave= "/WHERE YOU WANTED TO BE"
    response = await dio.download(gcs_url,pathToSave);
    

    Note: you might need permission to store a file, depends on where you save and in which device your are using

    Login or Signup to reply.
  2. Future<void> downloadFile(String url, String fileName) async {
    
      final anchor = AnchorElement(href: url);
    
      anchor.setAttribute('download', fileName);
     
      await anchor.click();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search