mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 05:15:42 +00:00 
			
		
		
		
	Handle condition where camera controller fails to initialize
This commit is contained in:
		| @@ -1,10 +1,14 @@ | ||||
| import "dart:math"; | ||||
| import "dart:typed_data"; | ||||
|  | ||||
| import "package:camera/camera.dart"; | ||||
| import "package:flutter/material.dart"; | ||||
| import "package:flutter_tabler_icons/flutter_tabler_icons.dart"; | ||||
| import "package:inventree/app_colors.dart"; | ||||
| import "package:inventree/inventree/sentry.dart"; | ||||
| import "package:inventree/preferences.dart"; | ||||
| import "package:inventree/widget/snacks.dart"; | ||||
| import "package:one_context/one_context.dart"; | ||||
| import "package:wakelock_plus/wakelock_plus.dart"; | ||||
| import "package:flutter_zxing/flutter_zxing.dart"; | ||||
|  | ||||
| @@ -133,7 +137,28 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState { | ||||
|         } | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   void onControllerCreated(CameraController? controller, Exception? error) { | ||||
|     if (error != null) { | ||||
|       sentryReportError( | ||||
|         "CameraBarcodeController.onControllerCreated", | ||||
|         error, | ||||
|         null | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     if (controller == null) { | ||||
|       showSnackIcon( | ||||
|         L10().cameraCreationError, | ||||
|         icon: TablerIcons.camera_x, | ||||
|         success: false | ||||
|       ); | ||||
|  | ||||
|       if (OneContext.hasContext) { | ||||
|         Navigator.pop(OneContext().context!); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /* | ||||
| @@ -167,6 +192,7 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState { | ||||
|       tryInverted: true, | ||||
|       tryRotate: true, | ||||
|       showGallery: false, | ||||
|       onControllerCreated: onControllerCreated, | ||||
|       scanDelay: Duration(milliseconds: scan_delay), | ||||
|       resolution: ResolutionPreset.high, | ||||
|       lensDirection: CameraLensDirection.back, | ||||
|   | ||||
| @@ -202,6 +202,9 @@ | ||||
|   "building": "Building", | ||||
|   "@building": {}, | ||||
|  | ||||
|   "cameraCreationError": "Could not open camera controller", | ||||
|   "@cameraCreationError": {}, | ||||
|  | ||||
|   "cameraInternal": "Internal Camera", | ||||
|   "@cameraInternal": {}, | ||||
|  | ||||
|   | ||||
| @@ -72,7 +72,7 @@ void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? suc | ||||
|         onAction(); | ||||
|       } | ||||
|     ), | ||||
|     duration: Duration(seconds: onAction == null ? 1 : 2), | ||||
|     duration: Duration(seconds: onAction == null ? 5 : 10), | ||||
|     ) | ||||
|   ); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user