mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Handle condition where camera controller fails to initialize
This commit is contained in:
parent
d25c47ccc3
commit
6690f10118
3 changed files with 30 additions and 1 deletions
|
|
@ -1,10 +1,14 @@
|
||||||
import "dart:math";
|
import "dart:math";
|
||||||
import "dart:typed_data";
|
import "dart:typed_data";
|
||||||
|
|
||||||
|
import "package:camera/camera.dart";
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
|
import "package:inventree/inventree/sentry.dart";
|
||||||
import "package:inventree/preferences.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:wakelock_plus/wakelock_plus.dart";
|
||||||
import "package:flutter_zxing/flutter_zxing.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,
|
tryInverted: true,
|
||||||
tryRotate: true,
|
tryRotate: true,
|
||||||
showGallery: false,
|
showGallery: false,
|
||||||
|
onControllerCreated: onControllerCreated,
|
||||||
scanDelay: Duration(milliseconds: scan_delay),
|
scanDelay: Duration(milliseconds: scan_delay),
|
||||||
resolution: ResolutionPreset.high,
|
resolution: ResolutionPreset.high,
|
||||||
lensDirection: CameraLensDirection.back,
|
lensDirection: CameraLensDirection.back,
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,9 @@
|
||||||
"building": "Building",
|
"building": "Building",
|
||||||
"@building": {},
|
"@building": {},
|
||||||
|
|
||||||
|
"cameraCreationError": "Could not open camera controller",
|
||||||
|
"@cameraCreationError": {},
|
||||||
|
|
||||||
"cameraInternal": "Internal Camera",
|
"cameraInternal": "Internal Camera",
|
||||||
"@cameraInternal": {},
|
"@cameraInternal": {},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? suc
|
||||||
onAction();
|
onAction();
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
duration: Duration(seconds: onAction == null ? 1 : 2),
|
duration: Duration(seconds: onAction == null ? 5 : 10),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue