From 74eacf6ee6d45681e790c27caa2d349c9f59de01 Mon Sep 17 00:00:00 2001 From: Asendia Mayco <9080782+asendia@users.noreply.github.com> Date: Mon, 7 Nov 2022 16:21:59 +0700 Subject: [PATCH] Add example download using http package --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 81b710b..c49af56 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,20 @@ _saveVideo() async { print(result); } ``` + +Download using http package +``` dart +Future downloadImage(String urlString) async { + final url = Uri.parse(urlString); + final client = http.Client(); + final request = http.Request('GET', url); + final response = await client.send(request); + final stream = response.stream; + List imageData = []; + await for (final data in stream) { + imageData.addAll(data); + } + client.close(); + await ImageGallerySaver.saveImage(Uint8List.fromList(imageData)); +} +```