PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Written By
Views

Image Picker Flutter - Pick Image From Gallery or Camera

If we are going to create a Flutter application that is accessing the camera to take a picture or using the gallery to pick an image then in this tutorial we are going to learn how to access Camera or Gallery in a flutter application. Pick Image from gallery Flutter

In this Image Picker Example, we are going to use ImagePicker dependency to access the camera/gallery. You can read also How to Capture Video from camera in flutter

dev_dependencies:
  image_picker: ^0.8.3+3

How to capture Image from Camera?

To capture an image from the camera first we need to create ImagePicker instance

This ImagePicker contains method getImage() will return Image File.

To get from Camera we need to pass the ImageSource.camera parameter to this getImage().

void _openCamera(BuildContext context)  async{
    final pickedFile = await ImagePicker().getImage(
          source: ImageSource.camera ,
          );
          setState(() {
          imageFile = pickedFile!;
    });
    Navigator.pop(context);
}```

we don't know how much time will it take to capture the image from the camera, so we are written this method inside the future method. 

similarly to pick an image from the gallery we need to pass ImageSource.gallery as a parameter.

```java
void _openGallery(BuildContext context) async{
  final pickedFile = await ImagePicker().getImage(
    source: ImageSource.gallery ,
  );
  setState(() {
    imageFile = pickedFile!;
  });

  Navigator.pop(context);
}

Download complete code for Pick Image from Gallery in flutter using Image Picker


Comments (0)

loading comments