imageToFile method
File file = await 'images/avatar.png'.imageToFile(); // from assets
Implementation
Future<File> imageToFile() async {
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
var bytes = await rootBundle.load('assets/${this}');
String tempPath = (await getTemporaryDirectory()).path;
File file = File('$tempPath/$fileName.png');
await file.writeAsBytes(
bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes));
return file;
}