“Instance member ‘pickImage’ can’t be accessed using static access.”错误在Flutter中。

huangapple go评论81阅读模式
英文:

"Instance member 'pickImage' can't be accessed using static access." error in flutter

问题

我遇到了一个关于我的Flutter应用程序的问题,想要在Flutter中从相册选择图片,但pickImage下面有下划线并显示了"实例成员 'pickImage' 无法使用静态访问"错误。如何修复这个错误。

这是我的代码:

class _CreateBlogState extends State<CreateBlog> {
  late String authorName, title, description;
  late File selectedImage;

  BlogCrudMethods blogCrudMethods = new BlogCrudMethods();

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);

    setState(() {
      selectedImage = image as File;
    });
  }

“Instance member ‘pickImage’ can’t be accessed using static access.”错误在Flutter中。

英文:

I have ran into a problem concerning my Flutter app , to use select picture from gallery in Flutter and pickImage is underlined and had this "Instance member &#39;pickImage&#39; can&#39;t be accessed using static access." error. How to fix this error.

This is my code

class _CreateBlogState extends State&lt;CreateBlog&gt; {
  late String authorName, title, description;
  late File selectedImage;

  BlogCrudMethods blogCrudMethods = new BlogCrudMethods();


  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);

    setState(() {
      selectedImage = image as File;
    });
  }

“Instance member ‘pickImage’ can’t be accessed using static access.”错误在Flutter中。

答案1

得分: 1

你需要创建一个 ImagePicker 实例,然后使用 pickImage 方法,因为它不是静态方法。

await ImagePicker().pickImage(source: ImageSource.gallery);
英文:

You need to create a ImagePicker instance to use pickImage while it is not static method.

await ImagePicker().pickImage(source: ImageSource.gallery);

huangapple
  • 本文由 发表于 2023年3月20日 23:44:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定