open_camera_flutter 0.0.1 copy "open_camera_flutter: ^0.0.1" to clipboard
open_camera_flutter: ^0.0.1 copied to clipboard

This is open camera plugin project that helps you to capture photo from android native side and return path of photo.

example/lib/main.dart

import 'dart:developer';

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

import 'package:flutter/services.dart';
import 'package:open_camera_flutter/open_camera_flutter.dart';
import 'package:permission_handler/permission_handler.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _openCameraFlutterPlugin = OpenCameraFlutter();
  String imagePath = "";

  @override
  void initState() {
    super.initState();
    initPlatformState();
    requestPermission();
  }

  requestPermission() async {
    Map<Permission, PermissionStatus> statuses = await [
      Permission.camera,
      //Permission.storage,
    ].request();
  }

  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion = await _openCameraFlutterPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          padding: const EdgeInsets.all(16),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Center(
                child: Text('Running on: $_platformVersion\n'),
              ),
              ElevatedButton(
                onPressed: () async {
                  if (await Permission.camera.request().isGranted) {
                    capturePhoto();
                  } else {
                    log("camera permission not granted");
                  }
                },
                child: const Text('Capture Image'),
              ),
              const SizedBox(height: 100),
              const Text('Image Path:'),
              Text(imagePath),
            ],
          ),
        ),
      ),
    );
  }

  capturePhoto() async {
    imagePath = await _openCameraFlutterPlugin.capturePhoto() ?? "";
    setState(() {});
  }
}
1
likes
120
pub points
0%
popularity

Publisher

unverified uploader

This is open camera plugin project that helps you to capture photo from android native side and return path of photo.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on open_camera_flutter