微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 FutureBuilder 中使用 Uint8List 的 Flutter 出现错误

如何解决在 FutureBuilder 中使用 Uint8List 的 Flutter 出现错误

我正在根据此参考资料构建一个 Flutter gallery 应用 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,],);
      },);
  }

我在谷歌上搜索过,但没有得到任何满意的答案。提前致谢。

解决方法

试试这个解决方案:

FutureBuilder<Uint8List>

FutureBuilder<dynamic>

FutureBuilder<List<int>>
,

忽略类型,编译器足够聪明,可以从您提供的 Future<> 类型中infer

FutureBuilder(
    future: asset.thumbData,

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。