Last active
February 22, 2020 18:22
-
-
Save prasadsunny1/cbc241222a3e7bd31fb9061af6e7ef8d to your computer and use it in GitHub Desktop.
Save image to image gallery using "image_gallery_saver" and asking for permission using "permission_handler" with flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:typed_data'; | |
import 'package:dio/dio.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:image_gallery_saver/image_gallery_saver.dart'; | |
import 'package:permission_handler/permission_handler.dart'; | |
//iOS - add these keys to info.plist in your ios folder | |
// NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription | |
// This gist uses flutter packages | |
// https://pub.dev/packages/image_gallery_saver | |
// https://pub.dev/packages/permission_handler | |
// dio | |
void main() { | |
runApp(MyApp()); | |
_save(); | |
} | |
_save() async { | |
await _askPermission(); | |
var response = await Dio().get( | |
"https://ss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=a62e824376d98d1069d40a31113eb807/838ba61ea8d3fd1fc9c7b6853a4e251f94ca5f46.jpg", | |
options: Options(responseType: ResponseType.bytes)); | |
final result = | |
await ImageGallerySaver.saveImage(Uint8List.fromList(response.data)); | |
print(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment