【发布时间】:2021-06-04 19:27:49
【问题描述】:
我正在根据这个参考 Flutter Image Gallery 构建一个颤振画廊应用程序
一切正常,但我在Future Builder 中遇到错误
这是我收到的错误警告
The name 'Uint8List' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'Uint8List'.
这是我遇到的运行时错误
Error: 'Uint8List' isn't a type.
return FutureBuilder<Uint8List>(
^^^^^^^^^
这个Uint8List对我来说是全新的概念,不知道该怎么办。
这是返回 Future Builder 的小部件
@override
Widget build(BuildContext context) {
// We're using a FutureBuilder since thumbData is a future
return FutureBuilder<Uint8List>(
future: asset.thumbData,
builder: (_, snapshot) {
final bytes = snapshot.data;
// If we have no data, display a spinner
if (bytes == null) return CircularProgressIndicator();
// If there's data, display it as an image
return InkWell(
onTap: () {
// TODO: navigate to Image/Video screen
},
child: Stack(
children: [
// Wrap the image in a Positioned.fill to fill the space
Positioned.fill(
child: Image.memory(bytes, fit: BoxFit.cover),
),
// Display a Play icon if the asset is a video
if (asset.type == AssetType.video)
Center(
child: Container(
color: Colors.blue,
child: Icon(
Icons.play_arrow,
color: Colors.white,
),
),
),
],
),
);
},
);
}
我在谷歌上搜索过,但没有得到任何满意的答案。提前致谢。
【问题讨论】:
-
你为什么要在那里使用类型?
-
我认为您的代码中缺少导入,请在 pubspec 中添加此(包)[pub.dev/packages/typed_data] 并通过导入(typed_data)[pub.dev/documentation/typed_data/latest] 重试。
-
@HarshvardhanJoshi 是的,这对我有用,非常感谢!!!
-
@nvoigt 我只是参考一篇文章。
It returns a Future<Uint8List> representing the actual bytes of the thumbnail
标签: flutter photo-gallery uint8list