box_in_camera

Plugin to cut a portion of a picture from the camera.

Getting Started

This plugin works on Android & iOS. Used to crop an image from the camera section. Without any hassle, just call the BoxInCamera class and the Uint8List image will die.

Example App Example App

For information

The plugin can make errors from 1px to 5px.

Usege in Android

In the android/app/build.gradle file, change

minSdkVersion 16

to

minSdkVersion 21.

In the android/app/src/main/AndroidManifest.xml file, add this

<uses-permission android:name="android.permission.CAMERA" />

Usage in IOS

In the ios/Runner/Info.plist file, add this

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

Usage

Initialize camera

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await BoxInCamera.initialize();
  runApp(MyApp());
}

Get image Uint8List

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BoxInCamera(),
),
).then((value) {
  if (value != null) {
    Uint8List ImageBytes = value;
  }
});

Acceptable parameters

BoxInCamera(
  title : "Crop image from camera",
  appBarColor : Colors.black87,
  boxWidth : 240.0,
  boxHeight : 240.0,
  boxBorderWidth : 5.2,
  boxBorderColor : Colors.white,
  boxBorderRadius : 6.8,
)

Example

Full use for example.

import 'dart:async';

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

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await BoxInCamera.initialize();
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(debugShowCheckedModeBanner: false, home: MyHomePage());
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Box in Camera Example"),
        backgroundColor: Colors.grey.shade800,
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            ElevatedButton(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => BoxInCamera(),
                  ),
                ).then((value) {
                  if (value != null) {
                    Timer(Duration(milliseconds: 30), () {
                      showDialog(
                        context: context,
                        builder: (context) => AlertDialog(
                          titlePadding:
                              EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 0),
                          contentPadding: EdgeInsets.all(12.0),
                          title: Text("Croped Image"),
                          content: SizedBox(
                            width: 280.0,
                            height: 280.0,
                            child: Image.memory(value),
                          ),
                        ),
                      );
                    });
                  }
                });
              },
              style: ButtonStyle(
                backgroundColor: MaterialStateProperty.all<Color>(
                  Colors.grey.shade800,
                ),
              ),
              child: Text("Start Camera"),
            )
          ],
        ),
      ),
    );
  }
}