Skip to content

Commit 2f630ea

Browse files
committed
Handle empty resolution list for camera device
1 parent 58844e0 commit 2f630ea

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/pages/computer_vision/live_inference.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class _LiveInferenceState extends State<LiveInference> {
8484
});
8585
}
8686

87+
void closeCamera() {
88+
setState(() {
89+
mode = LiveInferenceMode.image;
90+
cameraDevice = null;
91+
});
92+
}
93+
8794
@override
8895
Widget build(BuildContext context) {
8996
final theme = FluentTheme.of(context);
@@ -148,10 +155,7 @@ class _LiveInferenceState extends State<LiveInference> {
148155
},
149156
items: [
150157
MenuFlyoutItem(text: const Text("None"), onPressed: () {
151-
setState(() {
152-
mode = LiveInferenceMode.image;
153-
cameraDevice = null;
154-
});
158+
closeCamera();
155159
}),
156160

157161
for (final device in devices)

lib/pages/computer_vision/widgets/camera_view.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ class CameraOptions extends StatefulWidget {
167167

168168
class _CameraOptionsState extends State<CameraOptions> {
169169

170-
late Resolution resolution;
170+
Resolution? resolution;
171171

172172
@override
173173
void initState() {
174174
super.initState();
175-
resolution = widget.device.resolutions.first;
175+
resolution = widget.device.resolutions.firstOrNull;
176176
}
177177

178178
void setResolution(Resolution res, ImageInferenceProvider inferenceProvider) {
@@ -197,13 +197,16 @@ class _CameraOptionsState extends State<CameraOptions> {
197197
),
198198
Builder(
199199
builder: (context) {
200+
if (widget.device.resolutions.isEmpty) {
201+
return Container();
202+
}
200203
return DropDownButton(
201204
buttonBuilder: (context, callback) {
202205
return NoOutlineButton(
203206
onPressed: callback,
204207
child: Row(
205208
children: [
206-
Text("Resolution: ${resolution.width} x ${resolution.height}"),
209+
Text("Resolution: ${resolution!.width} x ${resolution!.height}"),
207210
const Padding(
208211
padding: EdgeInsets.only(left: 8),
209212
child: Icon(FluentIcons.chevron_down, size: 12),

0 commit comments

Comments
 (0)