Skip to content

Commit 82da93d

Browse files
authored
Adding a camera plugin (flutter#337)
* initial import
1 parent c6c19b9 commit 82da93d

File tree

76 files changed

+2982
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2982
-0
lines changed

packages/camera/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.idea/
2+
.vagrant/
3+
.sconsign.dblite
4+
.svn/
5+
6+
.DS_Store
7+
*.swp
8+
profile
9+
10+
DerivedData/
11+
build/
12+
13+
*.pbxuser
14+
*.mode1v3
15+
*.mode2v3
16+
*.perspectivev3
17+
18+
!default.pbxuser
19+
!default.mode1v3
20+
!default.mode2v3
21+
!default.perspectivev3
22+
23+
xcuserdata
24+
25+
*.moved-aside
26+
27+
*.pyc
28+
*sync/
29+
Icon?
30+
.tags*
31+

packages/camera/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Initial release

packages/camera/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/camera/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Camera Plugin
2+
3+
[![pub package](https://img.shields.io/pub/v/camera.svg)](https://pub.dartlang.org/packages/camera)
4+
5+
A Flutter plugin for iOS and Android allowing access to the device cameras.
6+
7+
## Features:
8+
9+
* Display live camera preview in a widget.
10+
* Snapshots can be captured and saved to a file.
11+
12+
## Installation
13+
14+
First, add `camera` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/).
15+
16+
### iOS
17+
18+
Add a row to the `ios/Runner/Info.plist` of your app with the key `Privacy - Camera Usage Description` and a usage description.
19+
20+
Or in text format add the key:
21+
22+
```xml
23+
<key>NSCameraUsageDescription</key>
24+
<string>Can I use the camera please?</string>
25+
```
26+
27+
### Android
28+
29+
Change the minimum Android sdk version to 21 (or higher) in your `android/app/build.gradle` file.
30+
31+
```
32+
minSdkVersion 21
33+
```
34+
35+
### Example
36+
37+
Here is a small example flutter app displaying a full screen camera preview.
38+
39+
```dart
40+
import 'dart:async';
41+
import 'package:flutter/material.dart';
42+
import 'package:camera/camera.dart';
43+
44+
List<CameraDescription> cameras;
45+
46+
Future<Null> main() async {
47+
cameras = await availableCameras();
48+
runApp(new CameraApp());
49+
}
50+
51+
class CameraApp extends StatefulWidget {
52+
@override
53+
_CameraAppState createState() => new _CameraAppState();
54+
}
55+
56+
class _CameraAppState extends State<CameraApp> {
57+
CameraController controller;
58+
59+
@override
60+
void initState() {
61+
super.initState();
62+
controller = new CameraController(cameras[0], ResolutionPreset.medium);
63+
controller.initialize().then((_) {
64+
if (!mounted) {
65+
return;
66+
}
67+
setState(() {});
68+
});
69+
}
70+
71+
@override
72+
void dispose() {
73+
controller?.dispose();
74+
super.dispose();
75+
}
76+
77+
@override
78+
Widget build(BuildContext context) {
79+
if (!controller.value.initialized) {
80+
return new Container();
81+
}
82+
return new AspectRatio(
83+
aspectRatio:
84+
controller.value.aspectRatio,
85+
child: new CameraPreview(controller));
86+
}
87+
}
88+
```
89+
90+
For a more elaborate usage example see [here](https://github.com/flutter/plugins/tree/master/packages/camera/example).
91+
92+
*Note*: This plugin is still under development, and some APIs might not be available yet.
93+
[Feedback welcome](https://github.com/flutter/flutter/issues) and
94+
[Pull Requests](https://github.com/flutter/plugins/pulls) are most welcome!

packages/camera/android/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

packages/camera/android/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
group 'io.flutter.camera'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
google()
7+
jcenter()
8+
}
9+
10+
dependencies {
11+
classpath 'com.android.tools.build:gradle:3.0.1'
12+
}
13+
}
14+
15+
rootProject.allprojects {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
}
21+
22+
apply plugin: 'com.android.library'
23+
24+
android {
25+
compileSdkVersion 26
26+
buildToolsVersion '26.0.3'
27+
28+
defaultConfig {
29+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
30+
minSdkVersion 21
31+
}
32+
lintOptions {
33+
disable 'InvalidPackage'
34+
}
35+
dependencies {
36+
implementation 'com.android.support:support-annotations:26.0.0'
37+
}
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'camera'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.camera">
3+
<uses-permission android:name="android.permission.CAMERA"/>
4+
</manifest>

0 commit comments

Comments
 (0)