In this recipe, you will add the camera functionality to your app. The users will be able to take a picture with the front or rear camera of their device. Follow these steps:
- In the dependencies section of the project’s pubspec.yaml file, add the camera and path_provider packages:
camera: ^0.8.1
path_provider: ^2.0.1
- For Android, change the minimum Android SDK version to 21 or higher in your android/app/build.gradle file:
minSdkVersion 21
- For iOS, add the following instructions to the ios/Runner/Info.plist file:
<key>NSCameraUsageDescription</key>
<string>Enable MLApp to access your camera to capture your photo</string>
-
In the lib folder of your project, add a new file and call it camera.dart.
-
At the top of the camera.dart file, import material.dart and the camera package:
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
- Create a new stateful widget,...