localImageToBase64 static method
localImageToBase64 method to convert local image to base64 This method takes image path as input This method returns the base64 image string This method uses File class to read the image This method uses base64Encode method to encode the image This method returns null if image is not found This method returns base64 image string if image is found This method is a static method
Example:
ImageUtils.localImageToBase64("path/to/image.png");
Implementation
static String? localImageToBase64(String imagePath) {
if (imagePath.isEmpty) {
return null;
}
List<int> imageBytes = File(imagePath).readAsBytesSync();
String base64Image = base64Encode(imageBytes);
return base64Image;
}