【问题标题】:This expression has a type of 'void' so its value can't be used in a set state此表达式的类型为 \'void\',因此它的值不能用于设置状态
【发布时间】:2023-02-23 15:16:22
【问题描述】:

为了有更好的看法,这是


  void _addImage(c) async {
    final ImagePicker picker = ImagePicker();
    final XFile? image = await picker.pickImage(source: ImageSource.gallery);
    print(image?.path);
    print(_imagePath?.split('/').last);
    if (image != null) {
      setState(() {
        String _imagePath = attachments.add(image.path);
      });
    }
  }
}

无效,是渲染图片上传的名称。

【问题讨论】:

    标签: android flutter dart user-interface setstate


    【解决方案1】:

    你的代码应该像..

    Future<void> _addImage(c) async {
        final ImagePicker picker = ImagePicker();
        final XFile? image = await picker.pickImage(source: ImageSource.gallery);
        print(image?.path);
        print(_imagePath?.split('/').last);
        if (image != null) {
          setState(() {
            String _imagePath =  image!.path;
            attachments.add(_imagePath);
          });
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-02
      • 2020-01-12
      • 2022-10-23
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      相关资源
      最近更新 更多