Skip to content

Instantly share code, notes, and snippets.

@thetrav
Last active December 30, 2019 21:10
Show Gist options
  • Save thetrav/23c0d1a1299885a910890de5f46a8109 to your computer and use it in GitHub Desktop.
Save thetrav/23c0d1a1299885a910890de5f46a8109 to your computer and use it in GitHub Desktop.
download files in flutter web
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:growdata_shared_web/service/api.dart';
class GdDownloadButton extends StatelessWidget {
final String path;
final Api api;
GdDownloadButton(this.path, this.api);
void _startDownload() {
AnchorElement ele = AnchorElement(href: api.basicAuthLinkFor(path));
ele.click();
}
@override
Widget build(BuildContext context) => RaisedButton.icon(
label: Text("Download"),
icon: Icon(Icons.file_download),
onPressed: _startDownload
);
}
@thetrav
Copy link
Author

thetrav commented Dec 30, 2019

path is in the form of collection/<id>
api.basicAuthLinkFor(path) builds something along the lines of:
$protocol://$domain:$port/$root/$majorVersion/$path/?access_token=$jwt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment