flutter - _Callback<>、_toByteData() 和 _futurize() 未定义
问题描述
我在 Flutter 中遇到了这个问题:
Error: The method '_futurize' isn't defined for the class '_MainPage'.
Error: The method '_toByteData' isn't defined for the class '_MainPage'
Error: '_Callback' isn't a type.
这在https://api.flutter.dev/flutter/dart-ui/Image/toByteData.html中提到的函数中,用于获取图像的二进制值。
实际代码是:
Future<ByteData?> toByteData({ImageByteFormat format = ImageByteFormat.rawRgba}) {
return _futurize((_Callback<ByteData> callback) {
return _toByteData(format.index, (Uint8List? encoded) {
callback(encoded!.buffer.asByteData());
});
});
}
解决方案
您引用的代码代表了代码的实现方式。
出于这个原因,_futurize
and_toByteData
方法是private
类的Image
,不能从外部访问,因此会出现错误。
如果您想使用该toByteData()
功能,您可以简单地使用如下代码:
ByteData byteData = await image.toByteData();
推荐阅读
- ruby-on-rails - 我可以运行我的 rake 作业吗:在运行我的 rails 服务器时在同一个 docker 容器中工作?
- javascript - 切换新的 li 仍然计算最后一个
- c++ - 在 GUI 应用程序中使用线程
- python - pandas 中的平均值和虚拟值
- function - 如何正确地将 Win32 类对象传递给函数
- firebase - 添加 Firestore 依赖项会导致 Flutter 应用程序出错
- c# - Unity:如何递归找到所有邻居(邻居的邻居)?
- sql-server - 为什么光标没有终止?
- php - 将 MySQL 数据读入 Bootstrap 4 列
- node.js - 添加代理以响应 package.json 后,不断收到“代理错误:无法代理请求”错误