magiceye 0.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 80

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.3

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.

0.1.4 #

  • Added a new parameter to MagicEye to control preview alignment.
  • Possibly Breaking Change: By default, the alignment is now topCenter.

0.1.3+2 #

0.1.3+1 #

  • Fix regression (issue #3)

0.1.3 #

  • Fix defaultCameraControlLayer secondChild getting the firstChild hit

0.1.2 #

  • Assert that MagicEye parameters are not null, except for key
  • Export default layers
  • Constrained example orientation with SystemChrome.setPreferredOrientations

0.1.1 #

  • Now the default allowed directions is not portrait, but all of them, as it's more intuitive
  • Little improvement on in-code documentation
  • Possibly Breaking Change: Change DeviceDirection enum to represent more intuitively the directions. Now, landscape is landscapeLeft, and landscapeReversed is landscapeRight

0.1.0+3 #

  • Updated README.md
  • Formatting

0.1.0+2 #

  • Updated README.md

0.1.0+1 #

  • Updated README.md

0.1.0 #

  • API has reached a reasonable stability
  • README.md has been updated with enough info
  • Little update on the documentation

0.0.15+4 #

  • Fix [BehaviorSubject] instantiation

0.0.15 #

  • Little improvement on NaviveDeviceDirection handling

0.0.14+4 #

  • Fix for [DeviceDirection.difference]
  • Tests for [DeviceDirection.difference]

0.0.14+1 #

  • Adjustment on [DeviceDirection.difference] method

0.0.14 #

  • Added a method to returs the difference of directions in degrees
  • See [DeviceDirection.difference]

0.0.13+4 #

  • Center image on default control layer confirmation

0.0.13+3 #

  • Small update on README.md

0.0.13+1 #

  • Deal with all warnings

0.0.13 #

  • Dealing with controllers' resources release (issue present since 0.0.1)
  • Fixes camera freezing by disconnection (issue present since 0.0.1)
  • Small cleanup and documentation update

0.0.12 #

  • Fixed error handling

0.0.11 #

  • Provide direction as a BehaviorSubject instead of a Stream on contexts
  • Improvements on defaultCameraControl
  • Example cleanups

0.0.10 #

  • Fixed PreviewLayer functions

0.0.9+1 #

  • Some corrections on formatting
  • Updated description
  • Updated rxdart dependency

0.0.9 #

  • This breaks the API
  • Instead of returning an [Option
  • Improvements on documentation

0.0.8 #

  • Make functions [toRadian] and [toDegrees] for [DeviceDirection] into extension methods ([.radian] and [.degrees] respectively)
  • For this, raised Dart SDK requirement to 2.7
  • Also, reraised required path_provider version to 1.5.1

0.0.7 #

  • Lowered required path_provider version to 1.5.0 so it's backward compatible with Flutter 1.9

0.0.6 #

  • Lowered required rxdart version to ^0.22.5

0.0.5 #

  • Lowered required Dart SDK to 2.5

0.0.4 #

  • Exported DeviceCamera

0.0.3 #

  • Unexported default_camera_control_layer

0.0.2 #

  • Instead of [pushWithConfirmation] (not yet implemented), the confirmation screen has been implemented on the [defaultCameraControlLayer] method
  • Change on package structure
  • Little change on API: instead of returning a String, now the MagicEye return an [Option

0.0.1 #

  • Initial release: basic functionality
  • Default preview and controls
  • Allow for custom control and preview layers

Known Issues #

  • Old controllers not being disposed
  • Camera goes disabled by policy if the device locked
  • Camera freezes if you change to another app that uses the camera
  • No proper handle of black area when the device's aspect ratio is higher than camera's one

Other info #

The readme will be made later. Thanks

The example folder is working, but its just a personal test of the package. A proper example with MREs and diverse options will be available in the future

example/lib/main.dart

import 'dart:async';
import 'dart:io';

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
    [DeviceOrientation.portraitUp],
  ).then(
    (_) => runApp(MyApp()),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('MagicEye'),
        ),
        body: Center(
          child: LoucoButton(),
        ),
      ),
    );
  }
}

class LoucoButton extends StatelessWidget {
  final StreamController<File> file = StreamController.broadcast();

  LoucoButton({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text("Take Picture"),
              onPressed: () => MagicEye(
                previewAlignment: AlignmentDirectional.topCenter,
              ).push(context).then(
                    (path) => path?.fold(
                      (e) => print("Error :: ${e.message}"),
                      (path) => file.add(
                        File(path),
                      ),
                    ),
                  ),
            ),
            SizedBox(height: 16),
            StreamBuilder<File>(
              stream: file.stream,
              initialData: null,
              builder: (context, snapshot) => snapshot.hasData
                  ? Image.file(snapshot.data)
                  : AspectRatio(
                      aspectRatio: 9 / 16,
                      child: Container(color: Colors.grey[300]),
                    ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  magiceye: ^0.1.4

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:magiceye/magiceye.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
camera ^0.5.7+3 0.5.7+4
dartz ^0.8.9 0.8.9 0.9.0-dev.6
flutter 0.0.0
native_device_orientation ^0.3.0 0.3.0
path_provider ^1.5.1 1.6.5
rxdart ^0.23.1 0.23.1 0.24.0-dev.1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
platform 2.2.1
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test ^1.9.4