Created
December 4, 2019 04:21
-
-
Save eldetulado/b207213e6afee0461a0263fe5a9077ed to your computer and use it in GitHub Desktop.
convert image to base64 and base64 to image
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 'dart:convert'; | |
import 'dart:io'; | |
import 'dart:typed_data'; | |
import 'package:flutter/material.dart'; | |
class ImageUtil { | |
Image imageFromBase64String(String base64String) { | |
return Image.memory( | |
base64Decode(base64String), | |
fit: BoxFit.cover, | |
height: 100, | |
); | |
} | |
Uint8List dataFromBase64String(String base64String) { | |
return base64Decode(base64String); | |
} | |
String base64String(Uint8List data) { | |
return base64Encode(data); | |
} | |
String imageFileToString(File file) { | |
List<int> data = file.readAsBytesSync(); | |
return base64Encode(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment