diff --git a/README.md b/README.md index 70fc964..553ff8c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The plugins for elinux are basically designed to be API compatible with the offi | Package for eLinux | Frontend package | | ------------------ | ---------------- | | [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) | | [shared_preferences_elinux](packages/shared_preferences) | [shared_preferences](https://github.com/flutter/packages/tree/main/packages/shared_preferences) | | [joystick](packages/joystick) | - | diff --git a/packages/camera/CHANGELOG.md b/packages/camera/CHANGELOG.md index fcb6f77..620bdb4 100644 --- a/packages/camera/CHANGELOG.md +++ b/packages/camera/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.3.1 +* Update for flutter official camera plugin v0.10.5+3 + ## 0.3.0 * Add TakePicture API * Enable stream image APIs diff --git a/packages/camera/README.md b/packages/camera/README.md index 9bc2bfb..314ac4a 100644 --- a/packages/camera/README.md +++ b/packages/camera/README.md @@ -19,7 +19,7 @@ $ sudo apt install libgstreamer-plugins-base1.0-dev \ ### pubspec.yaml ```yaml dependencies: - camera: ^0.10.0+1 + camera: ^0.10.5+3 camera_elinux: git: url: https://github.com/sony/flutter-elinux-plugins.git diff --git a/packages/camera/example/elinux/flutter/main.dart b/packages/camera/example/elinux/flutter/main.dart deleted file mode 100644 index 31a7a2e..0000000 --- a/packages/camera/example/elinux/flutter/main.dart +++ /dev/null @@ -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 main() async { - registerPlugins(); - entrypoint.main(); -} diff --git a/packages/camera/example/lib/main.dart b/packages/camera/example/lib/main.dart index c5804e7..c187e72 100644 --- a/packages/camera/example/lib/main.dart +++ b/packages/camera/example/lib/main.dart @@ -14,7 +14,7 @@ import 'package:video_player/video_player.dart'; /// Camera example home widget. class CameraExampleHome extends StatefulWidget { /// Default Constructor - const CameraExampleHome({Key? key}) : super(key: key); + const CameraExampleHome({super.key}); @override State createState() { @@ -31,17 +31,16 @@ IconData getCameraLensIcon(CameraLensDirection direction) { return Icons.camera_front; case CameraLensDirection.external: 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) { - if (message != null) { - print('Error: $code\nError Message: $message'); - } else { - print('Error: $code'); - } + // ignore: avoid_print + print('Error: $code${message == null ? '' : '\nError Message: $message'}'); } class _CameraExampleHomeState extends State @@ -72,7 +71,7 @@ class _CameraExampleHomeState extends State @override void initState() { super.initState(); - _ambiguate(WidgetsBinding.instance)?.addObserver(this); + WidgetsBinding.instance.addObserver(this); _flashModeControlRowAnimationController = AnimationController( duration: const Duration(milliseconds: 300), @@ -102,7 +101,7 @@ class _CameraExampleHomeState extends State @override void dispose() { - _ambiguate(WidgetsBinding.instance)?.removeObserver(this); + WidgetsBinding.instance.removeObserver(this); _flashModeControlRowAnimationController.dispose(); _exposureModeControlRowAnimationController.dispose(); super.dispose(); @@ -121,7 +120,7 @@ class _CameraExampleHomeState extends State if (state == AppLifecycleState.inactive) { cameraController.dispose(); } else if (state == AppLifecycleState.resumed) { - onNewCameraSelected(cameraController.description); + _initializeCameraController(cameraController.description); } } // #enddocregion AppLifecycle @@ -251,9 +250,7 @@ class _CameraExampleHomeState extends State child: Center( child: AspectRatio( aspectRatio: - localVideoController.value.size != null - ? localVideoController.value.aspectRatio - : 1.0, + localVideoController.value.aspectRatio, child: VideoPlayer(localVideoController)), ), ), @@ -368,16 +365,12 @@ class _CameraExampleHomeState extends State Widget _exposureModeControlRowWidget() { final ButtonStyle styleAuto = TextButton.styleFrom( - // TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 - // ignore: deprecated_member_use - primary: controller?.value.exposureMode == ExposureMode.auto + foregroundColor: controller?.value.exposureMode == ExposureMode.auto ? Colors.orange : Colors.blue, ); final ButtonStyle styleLocked = TextButton.styleFrom( - // TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 - // ignore: deprecated_member_use - primary: controller?.value.exposureMode == ExposureMode.locked + foregroundColor: controller?.value.exposureMode == ExposureMode.locked ? Colors.orange : Colors.blue, ); @@ -455,16 +448,12 @@ class _CameraExampleHomeState extends State Widget _focusModeControlRowWidget() { final ButtonStyle styleAuto = TextButton.styleFrom( - // TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 - // ignore: deprecated_member_use - primary: controller?.value.focusMode == FocusMode.auto + foregroundColor: controller?.value.focusMode == FocusMode.auto ? Colors.orange : Colors.blue, ); final ButtonStyle styleLocked = TextButton.styleFrom( - // TODO(darrenaustin): Migrate to new API once it lands in stable: https://github.com/flutter/flutter/issues/105724 - // ignore: deprecated_member_use - primary: controller?.value.focusMode == FocusMode.locked + foregroundColor: controller?.value.focusMode == FocusMode.locked ? Colors.orange : Colors.blue, ); @@ -585,7 +574,7 @@ class _CameraExampleHomeState extends State } if (_cameras.isEmpty) { - _ambiguate(SchedulerBinding.instance)?.addPostFrameCallback((_) async { + SchedulerBinding.instance.addPostFrameCallback((_) async { showInSnackBar('No camera found.'); }); return const Text('None'); @@ -598,10 +587,7 @@ class _CameraExampleHomeState extends State title: Icon(getCameraLensIcon(cameraDescription.lensDirection)), groupValue: controller?.description, value: cameraDescription, - onChanged: - controller != null && controller!.value.isRecordingVideo - ? null - : onChanged, + onChanged: onChanged, ), ), ); @@ -634,17 +620,15 @@ class _CameraExampleHomeState extends State } Future onNewCameraSelected(CameraDescription cameraDescription) async { - final CameraController? oldController = controller; - if (oldController != null) { - // `controller` needs to be set to null before getting disposed, - // to avoid a race condition when we use the controller that is being - // disposed. This happens when camera permission dialog shows up, - // which triggers `didChangeAppLifecycleState`, which disposes and - // re-creates the controller. - controller = null; - await oldController.dispose(); + if (controller != null) { + return controller!.setDescription(cameraDescription); + } else { + return _initializeCameraController(cameraDescription); } + } + Future _initializeCameraController( + CameraDescription cameraDescription) async { final CameraController cameraController = CameraController( cameraDescription, kIsWeb ? ResolutionPreset.max : ResolutionPreset.medium, @@ -1002,11 +986,15 @@ class _CameraExampleHomeState extends State } 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.file(File(videoFile!.path)); videoPlayerListener = () { - if (videoController != null && videoController!.value.size != null) { + if (videoController != null) { // Refreshing the state to update video player with the correct ratio. if (mounted) { setState(() {}); @@ -1057,7 +1045,7 @@ class _CameraExampleHomeState extends State /// CameraApp is the Main Application. class CameraApp extends StatelessWidget { /// Default Constructor - const CameraApp({Key? key}) : super(key: key); + const CameraApp({super.key}); @override Widget build(BuildContext context) { @@ -1079,10 +1067,3 @@ Future main() async { } 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? value) => value; diff --git a/packages/camera/example/pubspec.yaml b/packages/camera/example/pubspec.yaml index 901cc31..5d742b7 100644 --- a/packages/camera/example/pubspec.yaml +++ b/packages/camera/example/pubspec.yaml @@ -3,11 +3,11 @@ description: Demonstrates how to use the camera plugin. publish_to: none environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=2.10.0" + sdk: ">=2.18.0 <4.0.0" + flutter: ">=3.3.0" dependencies: - camera: ^0.10.0+1 + camera: ^0.10.5+3 camera_elinux: path: ../ flutter: diff --git a/packages/camera/pubspec.yaml b/packages/camera/pubspec.yaml index 1cb66af..a99c52b 100644 --- a/packages/camera/pubspec.yaml +++ b/packages/camera/pubspec.yaml @@ -2,13 +2,13 @@ name: camera_elinux description: A Flutter plugin for getting information about and controlling the camera on eLinux. Supports previewing the camera feed, capturing images, capturing video, and streaming image buffers to dart. -version: 0.3.0 +version: 0.3.1 homepage: https://github.com/sony/flutter-elinux-plugins repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/camera environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=2.10.0" + sdk: ">=2.18.0 <4.0.0" + flutter: ">=3.3.0" dependencies: flutter: