我正在与学校管理应用程序,在这里我需要发送图像和视频到应用程序,并允许用户下载图像和视频到他们的手机画廊.我坚持这一点!请帮助我。.谢谢。.
gj3fmq9x1#
下面是可能有所帮助的函数
saveImage(String url) async { var response = await Dio() .get(url, options: Options(responseType: ResponseType.bytes)); final result = await ImageGallerySaver.saveImage( Uint8List.fromList(response.data), quality: 100, name: "${widget.id}"); }
saveImage(String url) async {
var response = await Dio()
.get(url, options: Options(responseType: ResponseType.bytes));
final result = await ImageGallerySaver.saveImage(
Uint8List.fromList(response.data),
quality: 100,
name: "${widget.id}");
}
字符串为了使用这个功能,你必须安装两个软件包(在你的pubspec.ymal文件中):
dio: ^3.0.10image_gallery_saver: '^1.5.0'
dio: ^3.0.10
image_gallery_saver: '^1.5.0'
型
tjjdgumg2#
ElevatedButton( onPressed:()async{ try{ // Get the ByteData for the asset image ByteData data = await rootBundle.load('backgrounds/$nameOfImage.jpg'); List<int> bytes = data.buffer.asUint8List(); // Get the external storage directory Directory? externalStorageDirectory = await getExternalStorageDirectory(); // Create a File object with the appropriate path File file = File(path.join(externalStorageDirectory!.path, '$nameOfImage.jpg')); // Write the image bytes to the file await file.writeAsBytes(bytes); // Save the image to the gallery await ImageGallerySaver.saveFile(file.path, isReturnPathOfIOS: true); // Show a dialog indicating success showDialog( context: context, builder: (BuildContext context) => AlertDialog( title: const Text('Image saved to gallery successfully'), ), ); }catch (e) { print('Error: $e'); // Handle the error (show a snackbar, display an error message, etc.) } }, child: Text('Download')),
ElevatedButton(
onPressed:()async{
try{
// Get the ByteData for the asset image
ByteData data = await rootBundle.load('backgrounds/$nameOfImage.jpg');
List<int> bytes = data.buffer.asUint8List();
// Get the external storage directory
Directory? externalStorageDirectory = await getExternalStorageDirectory();
// Create a File object with the appropriate path
File file = File(path.join(externalStorageDirectory!.path, '$nameOfImage.jpg'));
// Write the image bytes to the file
await file.writeAsBytes(bytes);
// Save the image to the gallery
await ImageGallerySaver.saveFile(file.path, isReturnPathOfIOS: true);
// Show a dialog indicating success
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Image saved to gallery successfully'),
),
);
}catch (e) {
print('Error: $e');
// Handle the error (show a snackbar, display an error message, etc.)
},
child: Text('Download')),
字符串
2条答案
按热度按时间gj3fmq9x1#
下面是可能有所帮助的函数
字符串
为了使用这个功能,你必须安装两个软件包(在你的pubspec.ymal文件中):
型
tjjdgumg2#
字符串