flutter_dual_camera 0.0.2 copy "flutter_dual_camera: ^0.0.2" to clipboard
flutter_dual_camera: ^0.0.2 copied to clipboard

PlatformAndroid

A Flutter plugin that enables access to dual camera functionality on Android devices, allowing simultaneous capture from multiple cameras.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dual_camera/flutter_dual_camera.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isDualCameraSupported = false;
  bool _isPreviewActive = false;
  Map<String, String> _imagePaths = {};
  String _status = "Checking camera support...";

  @override
  void initState() {
    super.initState();
    _checkDualCameraSupport();
  }

  Future<void> _checkDualCameraSupport() async {
    final bool isDualCameraSupported = await FlutterDualCamera.isDualCameraSupported();
    setState(() {
      _isDualCameraSupported = isDualCameraSupported;
      _status = _isDualCameraSupported ? "Dual camera supported" : "Dual camera not supported";
    });
  }

  Future<void> _startPreview() async {
    setState(() {
      _status = "Starting camera preview...";
    });

    try {
      if (await FlutterDualCamera.startDualCameraPreview()) {
        setState(() {
          _isPreviewActive = true;
          _status = "Camera preview active";
        });
      } else {
        setState(() {
          _status = "Failed to start camera preview";
        });
      }
    } on PlatformException catch (e) {
      setState(() {
        _status = "Camera error: ${e.message}";
      });
    }
  }

  Future<void> _stopPreview() async {
    if (await FlutterDualCamera.stopDualCameraPreview()) {
      setState(() {
        _isPreviewActive = false;
        _status = "Camera preview stopped";
      });
    }
  }

  Future<void> _takePicture() async {
    setState(() {
      _status = "Taking picture...";
    });

    try {
      final pictures = await FlutterDualCamera.takeDualPicture();
      setState(() {
        _imagePaths = pictures;
        _status = "Picture taken successfully";
      });
    } on PlatformException catch (e) {
      setState(() {
        _status = "Failed to take picture: ${e.message}";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Dual Camera Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Dual camera supported: $_isDualCameraSupported'),
              Text('Status: $_status'),
              const SizedBox(height: 20),
              if (_isDualCameraSupported) ...[
                ElevatedButton(
                  onPressed: _isPreviewActive ? _stopPreview : _startPreview,
                  child: Text(_isPreviewActive ? 'Stop Preview' : 'Start Preview'),
                ),
                const SizedBox(height: 10),
                ElevatedButton(
                  onPressed: _isPreviewActive ? _takePicture : null,
                  child: const Text('Take Picture'),
                ),
                const SizedBox(height: 20),
                if (_imagePaths.isNotEmpty) ...[
                  const SizedBox(height: 20),
                  const Text('Images captured:', style: TextStyle(fontWeight: FontWeight.bold)),
                  Text('Wide image path: ${_imagePaths['wide']}'),
                  Text('Telephoto image path: ${_imagePaths['telephoto']}'),
                ]
              ],
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
38
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that enables access to dual camera functionality on Android devices, allowing simultaneous capture from multiple cameras.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_dual_camera