networkImageToBase64 static method

Future<String?> networkImageToBase64(
  1. String imageUrl
)

networkImageToBase64 method to convert network image to base64 This method takes image url as input This method returns the base64 image string This method uses http package to get 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 an async method This method is a static method

Example:

ImageUtils.networkImageToBase64("https://example.com/image.png");

Implementation

static Future<String?> networkImageToBase64(String imageUrl) async {
  http.Response response = await http.get(Uri.parse(imageUrl));
  final bytes = response.bodyBytes;
  return (bytes != null ? base64Encode(bytes) : null);
}