Skip to content

Commit 6e0a068

Browse files
committed
Handle missing camera, e.g. on desktop.
1 parent 0778b06 commit 6e0a068

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:camera/camera.dart';
22
import 'package:flutter/widgets.dart';
3+
import 'package:powersync_flutter_demo/powersync.dart';
34

45
late final CameraDescription? camera;
56

@@ -8,8 +9,14 @@ Future<CameraDescription?> setupCamera() async {
89
// can be called before `runApp()`
910
WidgetsFlutterBinding.ensureInitialized();
1011
// Obtain a list of the available cameras on the device.
11-
final cameras = await availableCameras();
12-
// Get a specific camera from the list of available cameras.
13-
final camera = cameras.isNotEmpty ? cameras.first : null;
14-
return camera;
12+
try {
13+
final cameras = await availableCameras();
14+
// Get a specific camera from the list of available cameras.
15+
final camera = cameras.isNotEmpty ? cameras.first : null;
16+
return camera;
17+
} catch (e) {
18+
// Camera is not supported on all platforms
19+
log.warning('Failed to setup camera: $e');
20+
return null;
21+
}
1522
}

demos/supabase-todolist/lib/widgets/todo_item_widget.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:powersync_flutter_demo/app_config.dart';
3+
import 'package:powersync_flutter_demo/attachments/camera_helpers.dart';
34
import 'package:powersync_flutter_demo/attachments/photo_widget.dart';
45
import 'package:powersync_flutter_demo/attachments/queue.dart';
56

@@ -53,7 +54,7 @@ class TodoItemWidget extends StatelessWidget {
5354
onPressed: () async => await deleteTodo(todo),
5455
tooltip: 'Delete Item',
5556
),
56-
AppConfig.supabaseStorageBucket.isEmpty
57+
AppConfig.supabaseStorageBucket.isEmpty || camera == null
5758
? Container()
5859
: PhotoWidget(todo: todo),
5960
],

0 commit comments

Comments
 (0)