// Automatic FlutterFlow imports import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; import 'package:path_provider/path_provider.dart'; import '../../flutter_flow/uploaded_file.dart'; class ImageUtils { static Future convertImageFileToBase64( FFUploadedFile imageFile) async { List? imageBytes = imageFile.bytes; if (imageBytes != null) { String base64Image = base64Encode(imageBytes); return base64Image; } return null; } static Future convertToUploadFile(String img) async { // Decode the base64 string into bytes Uint8List bytes = base64.decode(img); // Create a temporary file to store the image final tempDir = await getTemporaryDirectory(); final tempPath = tempDir.path; final tempFile = await File('$tempPath/image.jpg').create(); await tempFile.writeAsBytes(bytes); // Create an FFUploadedFile object using the temporary file return FFUploadedFile( bytes: bytes, name: 'image.jpg', ); } }