Flutter Compress Camera Image

I want to click the photo through camera and want to compress it and then upload it to the server

i have included the Image Compress Dependency its Showing me the error The getter 'absolute' isn't defined for the type 'PickedFile'.

written the code of Clicking photo and uploading it to server // Taking Photo From Camera

Widget bottomSheet() {
return Container(
  height: 100.0,
  width: MediaQuery.of(context).size.width,
  margin: EdgeInsets.symmetric(
    horizontal: 20,
    vertical: 20,
  ),
  child: Column(
    children: <Widget>[
      Text(
        "Take A Picture",
        style: TextStyle(
          fontSize: 20.0,
        ),
      ),
      SizedBox(
        height: 20,
      ),
      Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
        // ignore: deprecated_member_use
        FlatButton.icon(
          icon: Icon(Icons.camera),
          onPressed: () {
            takePhoto(ImageSource.camera);
          },
          label: Text("Camera"),
        ),
      ])
    ],
  ),
);
}

void takePhoto(source) async {
final pickedFile = await _picker.getImage(
  source: source,
);
setState(() {
  _imageFile = pickedFile;
});
await FlutterImageCompress.compressWithFile(
  _imageFile.absolute.path,
  minWidth: 2300,
  minHeight: 1500,
  quality: 94,
  rotate: 90,
);
 }

Upvotes: 0

Views: 291

Answers (1)

Suganya
Suganya

Reputation: 439

Instead of using FlutterImageCompress.compressWithFile just add imageQuality in the _picker.getImage

_picker.getImage(
      source:ImageSource.camera,
      minWidth: 2300,
      minHeight: 1500,
      imageQuality: 75
)

As with the image quality value size of the image get changed

Upvotes: 3

Related Questions