VOOZH about

URL: https://www.geeksforgeeks.org/flutter/camera-access-in-flutter/

⇱ Camera Access in Flutter - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Camera Access in Flutter

Last Updated : 15 Jul, 2025

To add images from the camera in Flutter, we'll use the image_picker package. For this, you'll need to use your real device.

Follow the below steps to display the images from the camera

Step 1: Create a new Flutter Application

Create a new Flutter application using the command Prompt. To create a new app, write the below command and run it.

flutter create app_name

To know more about it refer this article: Creating a Simple Application in Flutter


Step 2: Adding the Dependency

To add the dependency to the pubspec.yaml file, add image_picker as a dependency in the dependencies part of the pubspec.yaml file, as shown below:

Now run the below command in the terminal.

flutter pub get


Step 3: Importing the Dependency

Use the below line of code in the main.dart file to import the image_picker dependency.

import 'package:image_picker/image_picker.dart';


Step 4: Follow the below flow

- To access the camera.


selectFromCamera:


-

Show the captured picture, if the user doesn't capture anything, then show "Sorry, nothing selected!".


Complete Source Code

main.dart:


Output:

When no image is selected, the following will result:

👁 c1


When the button is tapped, the mobile's camera will be opened to capture the image, as shown below:

When the image is captured, it will be displayed on the screen, as shown below:

👁 c2
Comment
Article Tags:

Explore