Skip to content

Instantly share code, notes, and snippets.

@rommyarb
Last active May 7, 2020 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rommyarb/5832367b6a9d4f14344e6e00d50ba381 to your computer and use it in GitHub Desktop.
Save rommyarb/5832367b6a9d4f14344e6e00d50ba381 to your computer and use it in GitHub Desktop.
Promise (Future) in Dart
// example to convert base64 string to image
import 'dart:async'; // for Completer()
import 'dart:convert'; // for base64Decode()
import 'dart:ui' as ui; // for Image & decodeImageFromList()
Future<ui.Image> getImageFromString(String imageString) {
var imageBytes = base64Decode(imageString);
final Completer<ui.Image> completer = Completer();
ui.decodeImageFromList(imageBytes, (image) => completer.complete(image));
return completer.future;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment