forked from flutter/plugins
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera] Add
camera_platform_interface
package (flutter#3253)
* Make sure only camera_platform_interface has updates * add dev dependency to async package * refactored import to package import * Fix formatting issues
- Loading branch information
1 parent
9a22bd9
commit cb86dd8
Showing
21 changed files
with
1,974 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial open-source release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright 2017 The Chromium Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# camera_platform_interface | ||
|
||
A common platform interface for the [`camera`][1] plugin. | ||
|
||
This interface allows platform-specific implementations of the `camera` | ||
plugin, as well as the plugin itself, to ensure they are supporting the | ||
same interface. | ||
|
||
# Usage | ||
|
||
To implement a new platform-specific implementation of `camera`, extend | ||
[`CameraPlatform`][2] with an implementation that performs the | ||
platform-specific behavior, and when you register your plugin, set the default | ||
`CameraPlatform` by calling | ||
`CameraPlatform.instance = MyPlatformCamera()`. | ||
|
||
# Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
on why a less-clean interface is preferable to a breaking change. | ||
|
||
[1]: ../camera | ||
[2]: lib/camera_platform_interface.dart |
10 changes: 10 additions & 0 deletions
10
packages/camera/camera_platform_interface/lib/camera_platform_interface.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
export 'src/events/camera_event.dart'; | ||
export 'src/platform_interface/camera_platform.dart'; | ||
export 'src/types/types.dart'; | ||
|
||
/// Expose XFile | ||
export 'package:cross_file/cross_file.dart'; |
198 changes: 198 additions & 0 deletions
198
packages/camera/camera_platform_interface/lib/src/events/camera_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/// Generic Event coming from the native side of Camera. | ||
/// | ||
/// All [CameraEvent]s contain the `cameraId` that originated the event. This | ||
/// should never be `null`. | ||
/// | ||
/// This class is used as a base class for all the events that might be | ||
/// triggered from a Camera, but it is never used directly as an event type. | ||
/// | ||
/// Do NOT instantiate new events like `CameraEvent(cameraId)` directly, | ||
/// use a specific class instead: | ||
/// | ||
/// Do `class NewEvent extend CameraEvent` when creating your own events. | ||
/// See below for examples: `CameraClosingEvent`, `CameraErrorEvent`... | ||
/// These events are more semantic and more pleasant to use than raw generics. | ||
/// They can be (and in fact, are) filtered by the `instanceof`-operator. | ||
abstract class CameraEvent { | ||
/// The ID of the Camera this event is associated to. | ||
final int cameraId; | ||
|
||
/// Build a Camera Event, that relates a `cameraId`. | ||
/// | ||
/// The `cameraId` is the ID of the camera that triggered the event. | ||
CameraEvent(this.cameraId) : assert(cameraId != null); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is CameraEvent && | ||
runtimeType == other.runtimeType && | ||
cameraId == other.cameraId; | ||
|
||
@override | ||
int get hashCode => cameraId.hashCode; | ||
} | ||
|
||
/// An event fired when the camera has finished initializing. | ||
class CameraInitializedEvent extends CameraEvent { | ||
/// The width of the preview in pixels. | ||
final double previewWidth; | ||
|
||
/// The height of the preview in pixels. | ||
final double previewHeight; | ||
|
||
/// Build a CameraInitialized event triggered from the camera represented by | ||
/// `cameraId`. | ||
/// | ||
/// The `previewWidth` represents the width of the generated preview in pixels. | ||
/// The `previewHeight` represents the height of the generated preview in pixels. | ||
CameraInitializedEvent( | ||
int cameraId, | ||
this.previewWidth, | ||
this.previewHeight, | ||
) : super(cameraId); | ||
|
||
/// Converts the supplied [Map] to an instance of the [CameraInitializedEvent] | ||
/// class. | ||
CameraInitializedEvent.fromJson(Map<String, dynamic> json) | ||
: previewWidth = json['previewWidth'], | ||
previewHeight = json['previewHeight'], | ||
super(json['cameraId']); | ||
|
||
/// Converts the [CameraInitializedEvent] instance into a [Map] instance that | ||
/// can be serialized to JSON. | ||
Map<String, dynamic> toJson() => { | ||
'cameraId': cameraId, | ||
'previewWidth': previewWidth, | ||
'previewHeight': previewHeight, | ||
}; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
super == other && | ||
other is CameraInitializedEvent && | ||
runtimeType == other.runtimeType && | ||
previewWidth == other.previewWidth && | ||
previewHeight == other.previewHeight; | ||
|
||
@override | ||
int get hashCode => | ||
super.hashCode ^ previewWidth.hashCode ^ previewHeight.hashCode; | ||
} | ||
|
||
/// An event fired when the resolution preset of the camera has changed. | ||
class CameraResolutionChangedEvent extends CameraEvent { | ||
/// The capture width in pixels. | ||
final double captureWidth; | ||
|
||
/// The capture height in pixels. | ||
final double captureHeight; | ||
|
||
/// Build a CameraResolutionChanged event triggered from the camera | ||
/// represented by `cameraId`. | ||
/// | ||
/// The `captureWidth` represents the width of the resulting image in pixels. | ||
/// The `captureHeight` represents the height of the resulting image in pixels. | ||
CameraResolutionChangedEvent( | ||
int cameraId, | ||
this.captureWidth, | ||
this.captureHeight, | ||
) : super(cameraId); | ||
|
||
/// Converts the supplied [Map] to an instance of the | ||
/// [CameraResolutionChangedEvent] class. | ||
CameraResolutionChangedEvent.fromJson(Map<String, dynamic> json) | ||
: captureWidth = json['captureWidth'], | ||
captureHeight = json['captureHeight'], | ||
super(json['cameraId']); | ||
|
||
/// Converts the [CameraResolutionChangedEvent] instance into a [Map] instance | ||
/// that can be serialized to JSON. | ||
Map<String, dynamic> toJson() => { | ||
'cameraId': cameraId, | ||
'captureWidth': captureWidth, | ||
'captureHeight': captureHeight, | ||
}; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is CameraResolutionChangedEvent && | ||
super == (other) && | ||
runtimeType == other.runtimeType && | ||
captureWidth == other.captureWidth && | ||
captureHeight == other.captureHeight; | ||
|
||
@override | ||
int get hashCode => | ||
super.hashCode ^ captureWidth.hashCode ^ captureHeight.hashCode; | ||
} | ||
|
||
/// An event fired when the camera is going to close. | ||
class CameraClosingEvent extends CameraEvent { | ||
/// Build a CameraClosing event triggered from the camera represented by | ||
/// `cameraId`. | ||
CameraClosingEvent(int cameraId) : super(cameraId); | ||
|
||
/// Converts the supplied [Map] to an instance of the [CameraClosingEvent] | ||
/// class. | ||
CameraClosingEvent.fromJson(Map<String, dynamic> json) | ||
: super(json['cameraId']); | ||
|
||
/// Converts the [CameraClosingEvent] instance into a [Map] instance that can | ||
/// be serialized to JSON. | ||
Map<String, dynamic> toJson() => { | ||
'cameraId': cameraId, | ||
}; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
super == (other) && | ||
other is CameraClosingEvent && | ||
runtimeType == other.runtimeType; | ||
|
||
@override | ||
int get hashCode => super.hashCode; | ||
} | ||
|
||
/// An event fired when an error occured while operating the camera. | ||
class CameraErrorEvent extends CameraEvent { | ||
/// Description of the error. | ||
final String description; | ||
|
||
/// Build a CameraError event triggered from the camera represented by | ||
/// `cameraId`. | ||
/// | ||
/// The `description` represents the error occured on the camera. | ||
CameraErrorEvent(int cameraId, this.description) : super(cameraId); | ||
|
||
/// Converts the supplied [Map] to an instance of the [CameraErrorEvent] | ||
/// class. | ||
CameraErrorEvent.fromJson(Map<String, dynamic> json) | ||
: description = json['description'], | ||
super(json['cameraId']); | ||
|
||
/// Converts the [CameraErrorEvent] instance into a [Map] instance that can be | ||
/// serialized to JSON. | ||
Map<String, dynamic> toJson() => { | ||
'cameraId': cameraId, | ||
'description': description, | ||
}; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
super == (other) && | ||
other is CameraErrorEvent && | ||
runtimeType == other.runtimeType && | ||
description == other.description; | ||
|
||
@override | ||
int get hashCode => super.hashCode ^ description.hashCode; | ||
} |
Oops, something went wrong.