Created
March 23, 2020 11:19
-
-
Save Hellomik2002/c3b12c7ef539c8ad587accdad842b7ac to your computer and use it in GitHub Desktop.
This file contains 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:ui' as ui; | |
import 'package:flutter/rendering.dart'; | |
import 'dart:async'; | |
import 'dart:typed_data'; | |
import 'package:flutter/material.dart'; | |
Future<ui.Image> getImageFromPath(String imagePath) async { | |
final netImage = NetworkImage(imagePath); | |
final Completer<ui.Image> mainCompleter = Completer(); | |
netImage.load(netImage, (Uint8List bytes, | |
{int cacheWidth, int cacheHeight}) async { | |
final Completer<ui.Image> completer = new Completer(); | |
ui.decodeImageFromList(bytes, (ui.Image img) { | |
return completer.complete(img); | |
}); | |
mainCompleter.complete(completer.future); | |
return await ui.instantiateImageCodec(bytes); | |
}); | |
return mainCompleter.future; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment