728x90
반응형

Flutter에서 파일을 다운로드하기 위해서는 아래 명령어를 많이들 사용한다.
import 'dart:io';
그러나 위 기능은 Flutter Web은 지원하지 않는다.

그래서 이를 해결할 수 있는 방법을 찾다보니 image_downloader_web이 존재하는 것을 확인할 수 있었다.
해당 라이브러리를 활용하는 방법들이다.
Download image on webb (URL 기반 다운로드)
const _url = "https://picsum.photos/200";
Future<void> _downloadImage() async {
await WebImageDownloader.downloadImageFromWeb(_url);
}
Download image on web from UInt8List (UInt8List 형식 파일 다운로드)
final uint8List = Uint8List();
Future<void> _downloadImage() async {
await WebImageDownloader.downloadImageFromUInt8List(uInt8List: uint8List);
}
Download image with reduced quality (저품질 다운로드)
const _url = "https://picsum.photos/200";
Future<void> _downloadImage() async {
await WebImageDownloader.downloadImageFromWeb(_url, imageQuality: 0.5);
}
Download image with custom headers
const _url = "https://picsum.photos/200";
Future<void> _downloadImage() async {
final Map<String, String> headers = {
'authorization': token,
};
await WebImageDownloader.downloadImageFromWeb(_url, headers: headers);
}
나는 image 라이브러리와 연동하여 Flutter 웹 상에서 UInt8List 형식으로 이미지를 편집한 후 다운로드하는 방식으로 활용할 예정이다.
728x90
반응형
'IT IS IT > Flutter' 카테고리의 다른 글
| flutter doctor, clean 등 Terminal 명령어 모음. (0) | 2023.11.29 |
|---|---|
| Flutter [No Directionality widget found.] 오류 해결법. (0) | 2023.11.05 |
| Flutter Docter Android toolchain Error 해결법 (0) | 2023.11.01 |
| flutter Dart SDK version error 해결하기 (0) | 2023.11.01 |
| 플러터(Flutter) 란? (0) | 2023.02.23 |