Skip to content

Instantly share code, notes, and snippets.

@MCarlomagno
Created January 17, 2022 20:24
Show Gist options
  • Save MCarlomagno/0320a99dd858593d69c116a232266321 to your computer and use it in GitHub Desktop.
Save MCarlomagno/0320a99dd858593d69c116a232266321 to your computer and use it in GitHub Desktop.
import 'package:download_button/services/download_service.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class DownloadButton extends StatelessWidget {
const DownloadButton({Key? key, required this.url}) : super(key: key);
final String url;
Future<void> _downloadFile() async {
DownloadService downloadService =
kIsWeb ? WebDownloadService() : MobileDownloadService();
await downloadService.download(url: url);
}
@override
Widget build(BuildContext context) {
return ElevatedButton.icon(
onPressed: _downloadFile,
icon: const Icon(Icons.download),
label: const Text('Download'),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment