The method getImage isn't defined - flutter

I am using image_picker 0.6.7+17 library in order to take an image using the phone camera.
I am using an android device and not an ios device.
A problem
It seems like that getImage method is not defined, I took this exact code from the docs:
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
}
I am getting this error:
lib/pickers/image_picker.dart:17:37: Error: The method 'getImage' isn't defined for the class
'ImagePicker'.
- 'ImagePicker' is from 'package:chat_app/pickers/image_picker.dart'
('lib/pickers/image_picker.dart').
Try correcting the name to the name of an existing method, or defining a method named 'getImage'.
final pickedFile = await picker.getImage(source: ImageSource.camera);
^^^^^^^^
What I have done so far:
Added the dependency to my pubspec.yaml: file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
cloud_firestore: 0.13.5
firebase_auth: 0.16.1
image_picker: ^0.6.7+17
Added android:requestLegacyExternalStorage="true" to the AndroidManifest.xml file
Also Imported import 'package:image_picker/image_picker.dart' to use this library
What could be the problem?

You are trying to use an old API with a plugin version that specifies to use the new API.
Old API
File image = await ImagePicker.pickImage(...)
New API
final _picker = ImagePicker();
.
.
.
PickedFile image = await _picker.getImage(...)

Are you sure the ImagePicker you are using is not the one from this package:chat_app/pickers/image_picker.dart ? Maybe there is a class name conflict and you must rename your own ImagePicker class

I got the same problem I solved by defining the picker like that
final picker = ImagePicker();
and then use this
Future<void> _chooseImage() async {
var pickedFile = await picker.getImage(source: ImageSource.gallery);
}

1)you may forget import the library of "image picker":import 'package:image_picker/image_picker.dart';
2)or import wrong library with the same name with some differences in the syntax of Sentence

Just upgrade to latest version of image_picker.
And replace getImage by pickImage bcz getImage has deprecated.

Related

Some images are automatically rotated when i picked with image picker in my flutter app

I use image_picker: ^0.8.4 in my flutter app.When i wan't to pick image from gallery some images are automatically rotated .How can i solve this problem?
I try image_picker: ^0.8.5+3 and image_picker: ^0.8.6 packages.I want to pick image as it show in gallery without any rotation And i also want to keep meta data.
This is my code :
Future<XFile?> _getImage(ImageSource source, ImagePicker _picker) async {
final pickedFile = await _picker.pickImage(source: source,imageQuality: 25);
return pickedFile;
}

Is it possible to change the location of sorted video of image_picker plugin?

I am picking video from camera in this way. and using image_picker: ^0.6.7+22 plugin.
final _picker = ImagePicker();
Future<String> recordAndGetVideo()async{
PickedFile file = await _picker.getVideo(source: ImageSource.camera);
if(file != null){
return file.path;
}
return null;
}
After record ad video it stored the video and final path is this path. /storage/emulated/0/Android/data/com.example.app/files/Pictures/a190e227-a42c-4b09-bad8-4a9591454ff64584234230431626592.mp4
Now is it possible to store that video is different dir ? like /storage/emulated/0/Example App/a190e227-a42c-4b09-bad8-4a9591454ff64584234230431626592.mp4
Yes it is possible, But you have to re-write the file from one location to another.
This is the only way.

No implementation found for method pickImage on channel plugins.flutter.io/image_picker

image_picker: ^0.6.7+4
No implementation found for method pickImage on channel plugins.flutter.io/image_picker
sobhan ghosh this package has been updated pickImage and pickVideo APIs are now getImage and getVideo.
For more info visit package image_picker link
Try this:
Future getImage() async{
var photo = await ImagePicker.pickImage(source: ImageSource.camera);//".gallery" if you want to take image from gallery
setState(() {
_image = photo;//_image is the image file where your image is going to store
});
}
It may help you

How to Save set image of PickedFile type to a image in Flutter?

I want to set get image from the camera and set it to the following code:
image: DecorationImage(image: FileImage(file),
So I did this:
File file = await ImagePicker.pickImage(
source: ImageSource.camera,
);
Now above code works fine for now, but 'pickImage' is deprecated and we should use imagePicker.getImage() method instead.
So I used imagePicker.getImage() instead:
PickedFile file = await ImagePicker().getImage(
source: ImageSource.camera,
);
But when I try to set this file to the following image type, it doesn't work
image: DecorationImage(image: FileImage(file),)
How to solve this issue?
You need to use path property of picked file
image: DecorationImage(image: FileImage(File(file.path)),)
If someone might struck on a similar issue
change from pickImage to getImage and still needs a File.
PickedFile selectedFile = await ImagePicker().getImage(source: source);
File selected = File(selectedFile.path);
I was stuck in a similar type of problem where
await ImagePicker.pickImage( source: ImageSource.camera, );
was deprecated, and I have to use
await ImagePicker().getImage( source: ImageSource.camera, );
but the problem raised when I wanted to save it,
so if anyone stuck in suck kind of the problem I used this hack
final savedImage = File(imageFile.path).copy('${appDir.path}/$fileName');
this is one part of my code...
PickedFile to File
If your app needs dart:io File objects to operate, you may transform PickedFile to File like so:
final pickedFile = await _picker.getImage(...);
final File file = File(pickedFile.path);

Flutter image_picker 0.4.12+1 not returning from camera

I am using image_picker version 0.4.12+1 to take a picture from Camera on Android Emulator but the program never returns from ImagePicker.pickImage async call.
_takePicture() async{
print("This is executed");
var image = await ImagePicker.pickImage(source: ImageSource.camera);
print("But is this never executed");
}
This post on Github discusses the same issue and suggests a solution by modifying onMainActivity result. How can I do that? Or is there another solution that does not involve upgrading to AndroidX?
If it helps, the call will return successfully if I am using a different ImageSource.gallery instead of a camera.
Using image picker version,
image_picker: ^0.6.1+10 , this works.
Future _getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
}