英文:
"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;
});
}
英文:
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 'pickImage' can't be accessed using static access
." error. How to fix this error.
This is my code
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;
});
}
答案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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论