-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from powersync-ja/handle-missing-camera
Handle missing camera in demo
- Loading branch information
Showing
4 changed files
with
67 additions
and
40 deletions.
There are no files selected for viewing
17 changes: 11 additions & 6 deletions
17
demos/supabase-todolist/lib/attachments/camera_helpers.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import 'package:camera/camera.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
late final CameraDescription? camera; | ||
import 'package:powersync_flutter_demo/powersync.dart'; | ||
|
||
Future<CameraDescription?> setupCamera() async { | ||
// Ensure that plugin services are initialized so that `availableCameras()` | ||
// can be called before `runApp()` | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
// Obtain a list of the available cameras on the device. | ||
final cameras = await availableCameras(); | ||
// Get a specific camera from the list of available cameras. | ||
final camera = cameras.isNotEmpty ? cameras.first : null; | ||
return camera; | ||
try { | ||
final cameras = await availableCameras(); | ||
// Get a specific camera from the list of available cameras. | ||
final camera = cameras.isNotEmpty ? cameras.first : null; | ||
return camera; | ||
} catch (e) { | ||
// Camera is not supported on all platforms | ||
log.warning('Failed to setup camera: $e'); | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters