Skip to content
This repository has been archived by the owner on Jun 2, 2021. It is now read-only.

mateusfccp/magiceye

Repository files navigation

MagicEye

An abstraction on top of flutter camera.

Version Build License

Features

  • Provides the lower level handling of the camera plugin
    • Handles all camera resources
    • Handle camera status when app activity change
  • Can be used out-of-the-box by simply calling MagicEye().push(context)
  • Can be customized with layers
  • Come with a few, pre-baked, preview layers
  • Has a functional API leveraged by dartz

Version compatibility

  • Dart: 2.7.0
  • Flutter: 1.12.13+hotfix.5 (stable)

See CHANGELOG.md for all breaking (and non-breaking) changes.

Getting started

Add magiceye as a dependency in your project:

dependencies:
  magiceye: ^0.1.7

After this, you should then run flutter packages upgrade or update your packages with your IDE/editor funcionalities.

Finally, follow the camera installations instructions for iOS and Android.

Usage

If you want to use MagicEye default camera widget, you can do this by calling MagicEye.push:

Future<Either<MagicEyeException, String>> result = await MagicEye().push(context);
result.fold(
    (exception) => // Handle exception case
    (path) => // Handle success case. [path] has the path to the file saved
);

Disclaimer: MagicEye widget can be used with Navigator.push instead. However, the disposal of resources won't be handled automatically. Use with caution.

You can customize some functionality of the camera passing parameters to the MagicEye constructor. For detailed info, consult its page on the documentation.

Layers

Although MagicEye may be used as is, you can customize it's controlLayer and previewLayer. Both receives the necessary context and expects to return a Widget.

You can see examples of custom layers in the source:

In the near future, more and simpler examples will be provided in the example.

Preview Layer

The Preview Layer is, usually, used for graphical-only widgets, although it accepts any Widget. The canvas is limited to the preview area, so if the preview aspect ratio is different from the device's aspect ratio, the canvas will not include the black area.

MagicEye provide some default preview layers through PreviewLayer. An example is PreviewLayer.grid, which shows a grid on the preview to help with the Rule of Thirds.

To make a custom preview layer, previewLayer accepts a Widget Function(BuildContext, PreviewLayerContext). PreviewLayerContext provides the allowedDirections parameter used on MagicEye instatiation. Also, a direction stream emits info about the current device orientation.

Control Layer

The Control Layer is used to render the controls of the camera. Its canvas is the entire device screen. The parameter controlLayer is similar to previewLayer, but provides a ControlLayerContext instead, which gives you access to the camera functions like takePicture.


For bugs or additional info, feel free to open an issue.