How to create camera overlay with Flutter

In this Google Flutter code snippet example, we are going to learn How to create camera overlay with flutter

You can copy and adopt this source code example to your flutter project easily without issues.

Add this code to your pubspec.yaml file

  camera: ^0.5.2+1

Create a camera_overlay.dart file (use any name of your choice) and add this code:

 import 'dart:async';

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

class CamOverlay extends StatefulWidget {
  _CamOverlayState createState() => _CamOverlayState();

class _CamOverlayState extends State<CamOverlay> {
  CameraController _controller;
  Future<void> _initCamFuture;

  void initState() {

  _initApp() async {
    final cameras = await availableCameras();
    final firstCam = cameras.first;

    _controller = CameraController(

    _initCamFuture = _controller.initialize();

  void dispose() {

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Camera Overylay")),
      body: FutureBuilder<void>(
        future: _initCamFuture,
        builder: (context, snapshot) {
            return Stack(
              children: <Widget>[
                new Positioned.fill(
                  child: new AspectRatio(
                      aspectRatio: _controller.value.aspectRatio,
                      child: new CameraPreview(_controller)),
                new Positioned.fill(
                  child: new Opacity(
                      opacity: 0.3,
                      child: Container(
                        height: 200.0,
                        child: Center(
                          child: Text("", style: TextStyle(fontSize: 20.0, color: Colors.white,)),

In your main.dart file (main entry point of the app), add this:

import 'package:inducesmile/camera_overlay.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return new MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Code Snippets',
      theme: new ThemeData(primarySwatch:,
      home: new CamOverlay(),
A visible red overlay on the camera.

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

Add a Comment