Skip to content

Commit 88d86e1

Browse files
[camera] Remove deprecated feature from Windows example
The Windows camera example was showing usage of `maxVideoDuration`, but the parameter is deprecated and ignored, so shouldn't be part of the example.
1 parent b4decd8 commit 88d86e1

File tree

4 files changed

+18
-69
lines changed

4 files changed

+18
-69
lines changed

packages/camera/camera_windows/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 0.2.6+3
22

3+
* Removes usage of the deprecated and ignored `maxVideoDuration` in the example.
34
* Updates minimum supported SDK version to Flutter 3.29/Dart 3.7.
45

56
## 0.2.6+2

packages/camera/camera_windows/example/lib/main.dart

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class _MyAppState extends State<MyApp> {
2828
int _cameraId = -1;
2929
bool _initialized = false;
3030
bool _recording = false;
31-
bool _recordingTimed = false;
3231
bool _previewPaused = false;
3332
Size? _previewSize;
3433
MediaSettings _mediaSettings = const MediaSettings(
@@ -146,7 +145,6 @@ class _MyAppState extends State<MyApp> {
146145
_cameraIndex = 0;
147146
_previewSize = null;
148147
_recording = false;
149-
_recordingTimed = false;
150148
_cameraInfo =
151149
'Failed to initialize camera: ${e.code}: ${e.description}';
152150
});
@@ -165,7 +163,6 @@ class _MyAppState extends State<MyApp> {
165163
_cameraId = -1;
166164
_previewSize = null;
167165
_recording = false;
168-
_recordingTimed = false;
169166
_previewPaused = false;
170167
_cameraInfo = 'Camera disposed';
171168
});
@@ -190,56 +187,22 @@ class _MyAppState extends State<MyApp> {
190187
_showInSnackBar('Picture captured to: ${file.path}');
191188
}
192189

193-
Future<void> _recordTimed(int seconds) async {
194-
if (_initialized && _cameraId > 0 && !_recordingTimed) {
195-
unawaited(
196-
CameraPlatform.instance.onVideoRecordedEvent(_cameraId).first.then((
197-
VideoRecordedEvent event,
198-
) async {
199-
if (mounted) {
200-
setState(() {
201-
_recordingTimed = false;
202-
});
203-
204-
_showInSnackBar('Video captured to: ${event.file.path}');
205-
}
206-
}),
207-
);
208-
209-
await CameraPlatform.instance.startVideoRecording(
210-
_cameraId,
211-
maxVideoDuration: Duration(seconds: seconds),
212-
);
213-
214-
if (mounted) {
215-
setState(() {
216-
_recordingTimed = true;
217-
});
218-
}
219-
}
220-
}
221-
222190
Future<void> _toggleRecord() async {
223191
if (_initialized && _cameraId > 0) {
224-
if (_recordingTimed) {
225-
/// Request to stop timed recording short.
226-
await CameraPlatform.instance.stopVideoRecording(_cameraId);
192+
if (!_recording) {
193+
await CameraPlatform.instance.startVideoRecording(_cameraId);
227194
} else {
228-
if (!_recording) {
229-
await CameraPlatform.instance.startVideoRecording(_cameraId);
230-
} else {
231-
final XFile file = await CameraPlatform.instance.stopVideoRecording(
232-
_cameraId,
233-
);
195+
final XFile file = await CameraPlatform.instance.stopVideoRecording(
196+
_cameraId,
197+
);
234198

235-
_showInSnackBar('Video captured to: ${file.path}');
236-
}
199+
_showInSnackBar('Video captured to: ${file.path}');
200+
}
237201

238-
if (mounted) {
239-
setState(() {
240-
_recording = !_recording;
241-
});
242-
}
202+
if (mounted) {
203+
setState(() {
204+
_recording = !_recording;
205+
});
243206
}
244207
}
245208
}
@@ -407,19 +370,7 @@ class _MyAppState extends State<MyApp> {
407370
const SizedBox(width: 5),
408371
ElevatedButton(
409372
onPressed: _initialized ? _toggleRecord : null,
410-
child: Text(
411-
(_recording || _recordingTimed)
412-
? 'Stop recording'
413-
: 'Record Video',
414-
),
415-
),
416-
const SizedBox(width: 5),
417-
ElevatedButton(
418-
onPressed:
419-
(_initialized && !_recording && !_recordingTimed)
420-
? () => _recordTimed(5)
421-
: null,
422-
child: const Text('Record 5 seconds'),
373+
child: Text(_recording ? 'Stop recording' : 'Record Video'),
423374
),
424375
if (_cameras.length > 1) ...<Widget>[
425376
const SizedBox(width: 5),

packages/camera/camera_windows/lib/camera_windows.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,11 @@ class CameraWindows extends CameraPlatform {
5050
@override
5151
Future<List<CameraDescription>> availableCameras() async {
5252
try {
53-
final List<String?> cameras = await _hostApi.getAvailableCameras();
53+
final List<String> cameras = await _hostApi.getAvailableCameras();
5454

55-
return cameras.map((String? cameraName) {
55+
return cameras.map((String cameraName) {
5656
return CameraDescription(
57-
// This type is only nullable due to Pigeon limitations, see
58-
// https://github.com/flutter/flutter/issues/97848. The native code
59-
// will never return null.
60-
name: cameraName!,
57+
name: cameraName,
6158
// TODO(stuartmorgan): Implement these; see
6259
// https://github.com/flutter/flutter/issues/97540.
6360
lensDirection: CameraLensDirection.front,

packages/camera/camera_windows/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_windows
22
description: A Flutter plugin for getting information about and controlling the camera on Windows.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_windows
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.2.6+2
5+
version: 0.2.6+3
66

77
environment:
88
sdk: ^3.7.0

0 commit comments

Comments
 (0)