camera: update for 1st-party camera v0.10.5+3 (#77)

Signed-off-by: Hidenori Matsubayashi <Hidenori.Matsubayashi@gmail.com>
This commit is contained in:
Hidenori Matsubayashi
2023-08-17 05:43:10 +00:00
committed by GitHub
parent 871ed935e8
commit 1746fd0633
7 changed files with 41 additions and 69 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ The plugins for elinux are basically designed to be API compatible with the offi
| Package for eLinux | Frontend package | | Package for eLinux | Frontend package |
| ------------------ | ---------------- | | ------------------ | ---------------- |
| [video_player_elinux](packages/video_player) | [video_player](https://github.com/flutter/plugins/tree/master/packages/video_player) | | [video_player_elinux](packages/video_player) | [video_player](https://github.com/flutter/plugins/tree/master/packages/video_player) |
| [camera_elinux](packages/camera) | [camera](https://github.com/flutter/plugins/tree/master/packages/camera) | | [camera_elinux](packages/camera) | [camera](https://github.com/flutter/packages/tree/main/packages/camera/camera) |
| [path_provider_elinux](packages/path_provider) | [path_provider](https://github.com/flutter/packages/tree/main/packages/path_provider) | | [path_provider_elinux](packages/path_provider) | [path_provider](https://github.com/flutter/packages/tree/main/packages/path_provider) |
| [shared_preferences_elinux](packages/shared_preferences) | [shared_preferences](https://github.com/flutter/packages/tree/main/packages/shared_preferences) | | [shared_preferences_elinux](packages/shared_preferences) | [shared_preferences](https://github.com/flutter/packages/tree/main/packages/shared_preferences) |
| [joystick](packages/joystick) | - | | [joystick](packages/joystick) | - |
+3
View File
@@ -1,3 +1,6 @@
## 0.3.1
* Update for flutter official camera plugin v0.10.5+3
## 0.3.0 ## 0.3.0
* Add TakePicture API * Add TakePicture API
* Enable stream image APIs * Enable stream image APIs
+1 -1
View File
@@ -19,7 +19,7 @@ $ sudo apt install libgstreamer-plugins-base1.0-dev \
### pubspec.yaml ### pubspec.yaml
```yaml ```yaml
dependencies: dependencies:
camera: ^0.10.0+1 camera: ^0.10.5+3
camera_elinux: camera_elinux:
git: git:
url: https://github.com/sony/flutter-elinux-plugins.git url: https://github.com/sony/flutter-elinux-plugins.git
@@ -1,12 +0,0 @@
//
// Generated file. Do not edit.
//
// @dart=2.12
import 'package:camera_example/main.dart' as entrypoint;
import 'generated_plugin_registrant.dart';
Future<void> main() async {
registerPlugins();
entrypoint.main();
}
+30 -49
View File
@@ -14,7 +14,7 @@ import 'package:video_player/video_player.dart';
/// Camera example home widget. /// Camera example home widget.
class CameraExampleHome extends StatefulWidget { class CameraExampleHome extends StatefulWidget {
/// Default Constructor /// Default Constructor
const CameraExampleHome({Key? key}) : super(key: key); const CameraExampleHome({super.key});
@override @override
State<CameraExampleHome> createState() { State<CameraExampleHome> createState() {
@@ -31,17 +31,16 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
return Icons.camera_front; return Icons.camera_front;
case CameraLensDirection.external: case CameraLensDirection.external:
return Icons.camera; return Icons.camera;
default:
throw ArgumentError('Unknown lens direction');
} }
// This enum is from a different package, so a new value could be added at
// any time. The example should keep working if that happens.
// ignore: dead_code
return Icons.camera;
} }
void _logError(String code, String? message) { void _logError(String code, String? message) {
if (message != null) { // ignore: avoid_print
print('Error: $code\nError Message: $message'); print('Error: $code${message == null ? '' : '\nError Message: $message'}');
} else {
print('Error: $code');
}
} }
class _CameraExampleHomeState extends State<CameraExampleHome> class _CameraExampleHomeState extends State<CameraExampleHome>
@@ -72,7 +71,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_ambiguate(WidgetsBinding.instance)?.addObserver(this); WidgetsBinding.instance.addObserver(this);
_flashModeControlRowAnimationController = AnimationController( _flashModeControlRowAnimationController = AnimationController(
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
@@ -102,7 +101,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
@override @override
void dispose() { void dispose() {
_ambiguate(WidgetsBinding.instance)?.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
_flashModeControlRowAnimationController.dispose(); _flashModeControlRowAnimationController.dispose();
_exposureModeControlRowAnimationController.dispose(); _exposureModeControlRowAnimationController.dispose();
super.dispose(); super.dispose();
@@ -121,7 +120,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
if (state == AppLifecycleState.inactive) { if (state == AppLifecycleState.inactive) {
cameraController.dispose(); cameraController.dispose();
} else if (state == AppLifecycleState.resumed) { } else if (state == AppLifecycleState.resumed) {
onNewCameraSelected(cameraController.description); _initializeCameraController(cameraController.description);
} }
} }
// #enddocregion AppLifecycle // #enddocregion AppLifecycle
@@ -251,9 +250,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
child: Center( child: Center(
child: AspectRatio( child: AspectRatio(
aspectRatio: aspectRatio:
localVideoController.value.size != null localVideoController.value.aspectRatio,
? localVideoController.value.aspectRatio
: 1.0,
child: VideoPlayer(localVideoController)), child: VideoPlayer(localVideoController)),
), ),
), ),
@@ -368,16 +365,12 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
Widget _exposureModeControlRowWidget() { Widget _exposureModeControlRowWidget() {
final ButtonStyle styleAuto = TextButton.styleFrom( final ButtonStyle styleAuto = TextButton.styleFrom(
// TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 foregroundColor: controller?.value.exposureMode == ExposureMode.auto
// ignore: deprecated_member_use
primary: controller?.value.exposureMode == ExposureMode.auto
? Colors.orange ? Colors.orange
: Colors.blue, : Colors.blue,
); );
final ButtonStyle styleLocked = TextButton.styleFrom( final ButtonStyle styleLocked = TextButton.styleFrom(
// TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 foregroundColor: controller?.value.exposureMode == ExposureMode.locked
// ignore: deprecated_member_use
primary: controller?.value.exposureMode == ExposureMode.locked
? Colors.orange ? Colors.orange
: Colors.blue, : Colors.blue,
); );
@@ -455,16 +448,12 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
Widget _focusModeControlRowWidget() { Widget _focusModeControlRowWidget() {
final ButtonStyle styleAuto = TextButton.styleFrom( final ButtonStyle styleAuto = TextButton.styleFrom(
// TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 foregroundColor: controller?.value.focusMode == FocusMode.auto
// ignore: deprecated_member_use
primary: controller?.value.focusMode == FocusMode.auto
? Colors.orange ? Colors.orange
: Colors.blue, : Colors.blue,
); );
final ButtonStyle styleLocked = TextButton.styleFrom( final ButtonStyle styleLocked = TextButton.styleFrom(
// TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 foregroundColor: controller?.value.focusMode == FocusMode.locked
// ignore: deprecated_member_use
primary: controller?.value.focusMode == FocusMode.locked
? Colors.orange ? Colors.orange
: Colors.blue, : Colors.blue,
); );
@@ -585,7 +574,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
if (_cameras.isEmpty) { if (_cameras.isEmpty) {
_ambiguate(SchedulerBinding.instance)?.addPostFrameCallback((_) async { SchedulerBinding.instance.addPostFrameCallback((_) async {
showInSnackBar('No camera found.'); showInSnackBar('No camera found.');
}); });
return const Text('None'); return const Text('None');
@@ -598,10 +587,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
title: Icon(getCameraLensIcon(cameraDescription.lensDirection)), title: Icon(getCameraLensIcon(cameraDescription.lensDirection)),
groupValue: controller?.description, groupValue: controller?.description,
value: cameraDescription, value: cameraDescription,
onChanged: onChanged: onChanged,
controller != null && controller!.value.isRecordingVideo
? null
: onChanged,
), ),
), ),
); );
@@ -634,17 +620,15 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
Future<void> onNewCameraSelected(CameraDescription cameraDescription) async { Future<void> onNewCameraSelected(CameraDescription cameraDescription) async {
final CameraController? oldController = controller; if (controller != null) {
if (oldController != null) { return controller!.setDescription(cameraDescription);
// `controller` needs to be set to null before getting disposed, } else {
// to avoid a race condition when we use the controller that is being return _initializeCameraController(cameraDescription);
// disposed. This happens when camera permission dialog shows up,
// which triggers `didChangeAppLifecycleState`, which disposes and
// re-creates the controller.
controller = null;
await oldController.dispose();
} }
}
Future<void> _initializeCameraController(
CameraDescription cameraDescription) async {
final CameraController cameraController = CameraController( final CameraController cameraController = CameraController(
cameraDescription, cameraDescription,
kIsWeb ? ResolutionPreset.max : ResolutionPreset.medium, kIsWeb ? ResolutionPreset.max : ResolutionPreset.medium,
@@ -1002,11 +986,15 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
} }
final VideoPlayerController vController = kIsWeb final VideoPlayerController vController = kIsWeb
// TODO(gabrielokura): remove the ignore once the following line can migrate to
// use VideoPlayerController.networkUrl after the issue is resolved.
// https://github.com/flutter/flutter/issues/121927
// ignore: deprecated_member_use
? VideoPlayerController.network(videoFile!.path) ? VideoPlayerController.network(videoFile!.path)
: VideoPlayerController.file(File(videoFile!.path)); : VideoPlayerController.file(File(videoFile!.path));
videoPlayerListener = () { videoPlayerListener = () {
if (videoController != null && videoController!.value.size != null) { if (videoController != null) {
// Refreshing the state to update video player with the correct ratio. // Refreshing the state to update video player with the correct ratio.
if (mounted) { if (mounted) {
setState(() {}); setState(() {});
@@ -1057,7 +1045,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
/// CameraApp is the Main Application. /// CameraApp is the Main Application.
class CameraApp extends StatelessWidget { class CameraApp extends StatelessWidget {
/// Default Constructor /// Default Constructor
const CameraApp({Key? key}) : super(key: key); const CameraApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -1079,10 +1067,3 @@ Future<void> main() async {
} }
runApp(const CameraApp()); runApp(const CameraApp());
} }
/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
// TODO(ianh): Remove this once we roll stable in late 2021.
T? _ambiguate<T>(T? value) => value;
+3 -3
View File
@@ -3,11 +3,11 @@ description: Demonstrates how to use the camera plugin.
publish_to: none publish_to: none
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.18.0 <4.0.0"
flutter: ">=2.10.0" flutter: ">=3.3.0"
dependencies: dependencies:
camera: ^0.10.0+1 camera: ^0.10.5+3
camera_elinux: camera_elinux:
path: ../ path: ../
flutter: flutter:
+3 -3
View File
@@ -2,13 +2,13 @@ name: camera_elinux
description: A Flutter plugin for getting information about and controlling the description: A Flutter plugin for getting information about and controlling the
camera on eLinux. Supports previewing the camera feed, capturing images, capturing video, camera on eLinux. Supports previewing the camera feed, capturing images, capturing video,
and streaming image buffers to dart. and streaming image buffers to dart.
version: 0.3.0 version: 0.3.1
homepage: https://github.com/sony/flutter-elinux-plugins homepage: https://github.com/sony/flutter-elinux-plugins
repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/camera repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/camera
environment: environment:
sdk: ">=2.12.0 <3.0.0" sdk: ">=2.18.0 <4.0.0"
flutter: ">=2.10.0" flutter: ">=3.3.0"
dependencies: dependencies:
flutter: flutter: