Created
April 28, 2025 18:05
-
-
Save Klerith/ff18f7a04c7717e0db6709969c379f8c to your computer and use it in GitHub Desktop.
Esta clase toma un URL, lo descarga y crea un XFile
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 'package:dio/dio.dart'; | |
import 'package:path_provider/path_provider.dart'; | |
import 'dart:io'; | |
import 'package:image_picker/image_picker.dart'; | |
import 'package:uuid/uuid.dart'; | |
// path_provider | |
class TemporalImages { | |
static Future<XFile> xFileFromUrl(String imageUrl) async { | |
final uuid = Uuid(); | |
final tempDir = await getTemporaryDirectory(); | |
final filePath = '${tempDir.path}/${uuid.v4()}.png'; | |
final dio = Dio(); | |
final response = await dio.get<List<int>>( | |
imageUrl, | |
options: Options(responseType: ResponseType.bytes), | |
); | |
final file = File(filePath); | |
await file.writeAsBytes(response.data!); | |
return XFile(file.path); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment