我正在尝试将带有链接的assetImage(“assets/image.png”)转换为文件/uint 8List/
final ByteData byteData = await rootBundle.load(logoUrl);
final File assetLogoFile =
File("${(await getTemporaryDirectory()).path}/$logoUrl");
File markerLogoFile = await assetLogoFile.writeAsBytes(byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
final Uint8List logoUint8List = await markerLogoFile.readAsBytes();
我收到以下错误;
E/flutter ( 5136): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: FileSystemException: Cannot open file, path = '/data/user/0/com.example.project/cache/assets/images/flare.png' (OS Error: No such file or directory, errno = 2)
E/flutter ( 5136): #0 _File.open.<anonymous closure> (dart:io/file_impl.dart:356:9)
E/flutter ( 5136): #1 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter ( 5136): #2 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
1条答案
按热度按时间carvr3hs1#
您可以使用以下代码将资产文件转换为Uint 8List;