【问题标题】:Flutter, Dart: The value of the local variable'uint8list' isn't used. Is displayed even though the declared variable is usedFlutter,Dart:没有使用局部变量'uint8list'的值。即使使用了声明的变量也会显示
【发布时间】:2020-09-14 06:48:15
【问题描述】:
//main.dart
// The declared uint8list turns gray (android studio).
//The value of the local variable 'uint8list' isn't used.
//It is displayed as above. It is considered unused.

                  var uint8list;  //←string color is gray.
                  var file;
                  var bytes;
                  Widget sumb=Container(width:100);

                  try{
                      uint8list = await VideoThumbnail.thumbnailFile(
                      video: tempurl,
                      thumbnailPath: (await getTemporaryDirectory()).path,
                      imageFormat: ImageFormat.WEBP,
                      maxHeight: 200,
                      // specify the height of the thumbnail, let the width auto-scaled to keep the source aspect ratio
                      quality: 75,
                    );
                  }catch(e){

                  }


                  uint8list="";  //←← Described as a trial. Even with this, the declaration part remains gray.

我正在尝试从上传到 firebase 中 cloud_storage 的视频文件创建缩略图,但在途中我遇到了不熟悉的行为。

我正在使用 VideoThumbnail 包中的 VideoThumbnail.thumbnailFile 方法。 该方法是异步方法,返回Future,但有时创建缩略图失败并出现错误,所以我正在尝试编写异常处理。

在上面的代码中,uint8list 是灰色的,并且出现了“变量未使用”的消息,但我认为即使考虑到范围,它也可以清楚地使用。

我认为可以从 try 块 {} 内部访问外部范围内的变量, 在飞镖朗。 我错了吗?

【问题讨论】:

    标签: android-studio flutter dart


    【解决方案1】:

    在上面的代码中,uint8list 是灰色的,并且出现了“变量未使用”的消息,但我认为即使考虑到范围,它也可以清楚地使用。

    您误解了警告。 未使用。您正在为其分配值。但是您从不关心,也从不阅读这些价值观。所以有这个变量是没有意义的。

    一旦您实际使用变量并读取分配给它的内容,警告就会消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 2012-10-31
      相关资源
      最近更新 更多