Skip to content

Commit 11bf223

Browse files
[camera] Remove deprecated feature from Windows example (#10380)
The Windows camera example was showing usage of `maxVideoDuration`, but the parameter is deprecated and ignored, so shouldn't be part of the example. Also makes a minor improvement to type safety of some code interacting with Pigeon, since the Pigeon definition had already been changed to non-nullable. Fixes flutter/flutter#166605 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 4b04fd7 commit 11bf223

File tree

4 files changed

+20
-67
lines changed

4 files changed

+20
-67
lines changed

packages/camera/camera_windows/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.6+4
2+
3+
* Removes usage of the deprecated and ignored `maxVideoDuration` in the example.
4+
15
## 0.2.6+3
26

37
* Updates to Pigeon 26.

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

Lines changed: 12 additions & 60 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(
@@ -147,7 +146,6 @@ class _MyAppState extends State<MyApp> {
147146
_cameraIndex = 0;
148147
_previewSize = null;
149148
_recording = false;
150-
_recordingTimed = false;
151149
_cameraInfo =
152150
'Failed to initialize camera: ${e.code}: ${e.description}';
153151
});
@@ -166,7 +164,6 @@ class _MyAppState extends State<MyApp> {
166164
_cameraId = -1;
167165
_previewSize = null;
168166
_recording = false;
169-
_recordingTimed = false;
170167
_previewPaused = false;
171168
_cameraInfo = 'Camera disposed';
172169
});
@@ -191,56 +188,22 @@ class _MyAppState extends State<MyApp> {
191188
_showInSnackBar('Picture captured to: ${file.path}');
192189
}
193190

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

236-
_showInSnackBar('Video captured to: ${file.path}');
237-
}
200+
_showInSnackBar('Video captured to: ${file.path}');
201+
}
238202

239-
if (mounted) {
240-
setState(() {
241-
_recording = !_recording;
242-
});
243-
}
203+
if (mounted) {
204+
setState(() {
205+
_recording = !_recording;
206+
});
244207
}
245208
}
246209
}
@@ -407,18 +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: (_initialized && !_recording && !_recordingTimed)
419-
? () => _recordTimed(5)
420-
: null,
421-
child: const Text('Record 5 seconds'),
373+
child: Text(_recording ? 'Stop recording' : 'Record Video'),
422374
),
423375
if (_cameras.length > 1) ...<Widget>[
424376
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+3
5+
version: 0.2.6+4
66

77
environment:
88
sdk: ^3.8.0

0 commit comments

Comments
 (0)