adv_camera 0.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

Advanced Camera #

This is our custom Camera that enabling you to tap focus, zoom, flashlight

Note: This plugin is still under development, and some Components might not be available yet or still has so many bugs.

Installation #

First, add adv_camera as a dependency in your pubspec.yaml file.

iOS #

Add two rows to the ios/Runner/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.
  • and one with the key Privacy - Microphone Usage Description and a usage description.

Or in text format add the key:

<key>NSCameraUsageDescription</key>
<string>Can I use the camera please?</string>
<key>NSMicrophoneUsageDescription</key>
<string>Can I use the mic please?</string>

Android #

For Android's permission, you have to configure it yourself (using Dexter, etc.). This plugin is made to support my other plugin adv_image_picker, so this permission is handled in adv_image_picker

Example #

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> pictureSizes = [];
  String imagePath;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: SafeArea(
            child: Stack(
              children: [
                Column(
                  children: [
                    Container(
                      color: Colors.purple,
                      child: Row(
                        children: [
                          FlatButton(
                            child: Text("Auto"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.auto);
                            },
                          ),
                          FlatButton(
                            child: Text("On"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.on);
                            },
                          ),
                          FlatButton(
                            child: Text("Off"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.off);
                            },
                          ),
                          FlatButton(
                            child: Text("Torch"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.torch);
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      color: Colors.orange,
                      child: Row(
                        children: [
                          FlatButton(
                            child: Text("1:1"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r1);
                              cameraController.setSessionPreset(CameraSessionPreset.low);
                            },
                          ),
                          FlatButton(
                            child: Text("4:3"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r4_3);
                              cameraController.setSessionPreset(CameraSessionPreset.medium);
                            },
                          ),
                          FlatButton(
                            child: Text("11:9"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r11_9);
                              cameraController.setSessionPreset(CameraSessionPreset.high);
                            },
                          ),
                          FlatButton(
                            child: Text("16:9"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r16_9);
                              cameraController.setSessionPreset(CameraSessionPreset.photo);
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      color: Colors.blue,
                      child: SingleChildScrollView(
                        child: Row(
                          children: this.pictureSizes.map((pictureSize) {
                            return FlatButton(
                              child: Text(pictureSize),
                              onPressed: () {
                                print("pictureSize ($pictureSize) => ${pictureSize.indexOf(":")}");
                                print(
                                    "pictureSize ($pictureSize) => ${pictureSize.substring(0, pictureSize.indexOf(":"))}");
                                print(
                                    "pictureSize ($pictureSize) => ${pictureSize.substring(pictureSize.indexOf(":") + 1, pictureSize.length)}");
                                cameraController.setPictureSize(
                                    int.tryParse(
                                        pictureSize.substring(0, pictureSize.indexOf(":"))),
                                    int.tryParse(pictureSize.substring(
                                        pictureSize.indexOf(":") + 1, pictureSize.length)));
                              },
                            );
                          }).toList(),
                        ),
                        scrollDirection: Axis.horizontal,
                      ),
                    ),
                    Expanded(
                        child: Container(
                          child: AdvCamera(
                            onCameraCreated: _onCameraCreated,
                            onImageCaptured: (String path) {
                              setState(() {
                                imagePath = path;
                              });
                            },
                            cameraPreviewRatio: CameraPreviewRatio.r16_9,
                          ),
                        )),
                  ],
                ),
                Positioned(
                  bottom: 16.0,
                  left: 16.0,
                  child: imagePath != null
                      ? Container(width: 100.0, height: 100.0, child: Image.file(File(imagePath)))
                      : Icon(Icons.image),
                )
              ],
            ),
          ),
          floatingActionButton: Column(mainAxisSize: MainAxisSize.min, children: [
            FloatingActionButton(
                child: Icon(Icons.switch_camera),
                onPressed: () {
                  cameraController.switchCamera();
                }),
            FloatingActionButton(
                child: Icon(Icons.camera),
                onPressed: () {
                  print("camera");
                  cameraController.captureImage();
                }),
            FloatingActionButton(
                child: Icon(Icons.camera),
                onPressed: () {
                  setState(() {
                    cameraController.setSavePath("/storage/emulated/0/ricricric");
                  });
                }),
          ])),
    );
  }

  AdvCameraController cameraController;

  _onCameraCreated(AdvCameraController controller) {
    this.cameraController = controller;

    this.cameraController.getPictureSizes().then((pictureSizes) {
      setState(() {
        this.pictureSizes = pictureSizes;
      });
    });
  }
}

0.0.6 #

  • Add bestPictureSize parameter for initial run on Android, because each device's default picture size may vary, example on MI 8 Lite, its default picture size is the lowest

0.0.5 #

  • Fix ios wrong rotation after resized

0.0.4 #

  • Add maxSize argument to resize captured image

0.0.3 #

  • Fix ios bug when tap to focus
  • Fix android capture image to return success

0.0.2+2 #

  • Migrate to Swift 4.2

0.0.2+1 #

  • Migrate to AndroidX

0.0.2 #

  • Some bug fixes
  • Clean up unnecessary codes

0.0.1 #

Initial release with these features

  • tap to focus
  • zoom (although this might not be as smooth, but hopefully I can maintain this plugin often enough to improve it)
  • flashlight

example/README.md

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

import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:adv_camera/adv_camera.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> pictureSizes = [];
  String imagePath;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: SafeArea(
            child: Stack(
              children: [
                Column(
                  children: [
                    Container(
                      color: Colors.purple,
                      child: Row(
                        children: [
                          FlatButton(
                            child: Text("Auto"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.auto);
                            },
                          ),
                          FlatButton(
                            child: Text("On"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.on);
                            },
                          ),
                          FlatButton(
                            child: Text("Off"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.off);
                            },
                          ),
                          FlatButton(
                            child: Text("Torch"),
                            onPressed: () {
                              cameraController.setFlashType(FlashType.torch);
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      color: Colors.orange,
                      child: Row(
                        children: [
                          FlatButton(
                            child: Text("1:1"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r1);
                              cameraController.setSessionPreset(CameraSessionPreset.low);
                            },
                          ),
                          FlatButton(
                            child: Text("4:3"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r4_3);
                              cameraController.setSessionPreset(CameraSessionPreset.medium);
                            },
                          ),
                          FlatButton(
                            child: Text("11:9"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r11_9);
                              cameraController.setSessionPreset(CameraSessionPreset.high);
                            },
                          ),
                          FlatButton(
                            child: Text("16:9"),
                            onPressed: () {
                              cameraController.setPreviewRatio(CameraPreviewRatio.r16_9);
                              cameraController.setSessionPreset(CameraSessionPreset.photo);
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      color: Colors.blue,
                      child: SingleChildScrollView(
                        child: Row(
                          children: this.pictureSizes.map((pictureSize) {
                            return FlatButton(
                              child: Text(pictureSize),
                              onPressed: () {
                                print("pictureSize ($pictureSize) => ${pictureSize.indexOf(":")}");
                                print(
                                    "pictureSize ($pictureSize) => ${pictureSize.substring(0, pictureSize.indexOf(":"))}");
                                print(
                                    "pictureSize ($pictureSize) => ${pictureSize.substring(pictureSize.indexOf(":") + 1, pictureSize.length)}");
                                cameraController.setPictureSize(
                                    int.tryParse(
                                        pictureSize.substring(0, pictureSize.indexOf(":"))),
                                    int.tryParse(pictureSize.substring(
                                        pictureSize.indexOf(":") + 1, pictureSize.length)));
                              },
                            );
                          }).toList(),
                        ),
                        scrollDirection: Axis.horizontal,
                      ),
                    ),
                    Expanded(
                        child: Container(
                          child: AdvCamera(
                            onCameraCreated: _onCameraCreated,
                            onImageCaptured: (String path) {
                              setState(() {
                                imagePath = path;
                              });
                            },
                            cameraPreviewRatio: CameraPreviewRatio.r16_9,
                          ),
                        )),
                  ],
                ),
                Positioned(
                  bottom: 16.0,
                  left: 16.0,
                  child: imagePath != null
                      ? Container(width: 100.0, height: 100.0, child: Image.file(File(imagePath)))
                      : Icon(Icons.image),
                )
              ],
            ),
          ),
          floatingActionButton: Column(mainAxisSize: MainAxisSize.min, children: [
            FloatingActionButton(
                child: Icon(Icons.switch_camera),
                onPressed: () {
                  cameraController.switchCamera();
                }),
            FloatingActionButton(
                child: Icon(Icons.camera),
                onPressed: () {
                  print("camera");
                  cameraController.captureImage();
                }),
            FloatingActionButton(
                child: Icon(Icons.camera),
                onPressed: () {
                  setState(() {
                    cameraController.setSavePath("/storage/emulated/0/ricricric");
                  });
                }),
          ])),
    );
  }

  AdvCameraController cameraController;

  _onCameraCreated(AdvCameraController controller) {
    this.cameraController = controller;

    this.cameraController.getPictureSizes().then((pictureSizes) {
      setState(() {
        this.pictureSizes = pictureSizes;
      });
    });
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  adv_camera: ^0.0.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:adv_camera/adv_camera.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Health suggestions

Fix lib/controller.dart. (-1 points)

Analysis of lib/controller.dart reported 2 hints:

line 71 col 21: The member 'setState' can only be used within instance members of subclasses of 'package:flutter/src/widgets/framework.dart'.

line 103 col 23: The member 'setState' can only be used within instance members of subclasses of 'package:flutter/src/widgets/framework.dart'.

Format lib/adv_camera.dart.

Run flutter format to format lib/adv_camera.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test