remove onSnackbarMessage, do not show error on regular scans, only files

This commit is contained in:
sneurlax 2024-07-31 17:41:24 -05:00 committed by julian-CStack
parent 810f8bb3c5
commit 2145334152

View file

@ -169,24 +169,6 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
level: LogLevel.Error); level: LogLevel.Error);
} }
}, },
onSnackbar: (message) async {
// TODO [prio=low]: Implement snackbar messages.
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// content: Text(message),
// ),
// );
if (context.mounted) {
return await showDialog<void>(
context: context,
builder: (_) => StackOkDialog(
title: "Error scanning QR code",
message: message,
),
);
}
},
); );
}, },
); );
@ -1990,12 +1972,10 @@ String formatAddress(String epicAddress) {
class QrCodeScannerDialog extends StatefulWidget { class QrCodeScannerDialog extends StatefulWidget {
final String walletId; final String walletId;
final Function(String) onQrCodeDetected; final Function(String) onQrCodeDetected;
final Function(String) onSnackbar; // This isn't really a snackbar currently.
QrCodeScannerDialog({ QrCodeScannerDialog({
required this.walletId, required this.walletId,
required this.onQrCodeDetected, required this.onQrCodeDetected,
required this.onSnackbar,
}); });
@override @override
@ -2088,7 +2068,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
Logging.instance Logging.instance
.log("Failed to initialize camera: $e\n$s", level: LogLevel.Error); .log("Failed to initialize camera: $e\n$s", level: LogLevel.Error);
if (mounted) { if (mounted) {
widget.onSnackbar("Failed to initialize camera. Please try again."); // widget.onSnackbar("Failed to initialize camera. Please try again.");
setState(() { setState(() {
_isScanning = false; _isScanning = false;
}); });
@ -2207,10 +2187,11 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
} catch (e, s) { } catch (e, s) {
// Logging.instance.log("Failed to capture and scan image: $e\n$s", level: LogLevel.Error); // Logging.instance.log("Failed to capture and scan image: $e\n$s", level: LogLevel.Error);
// Spammy. // Spammy.
if (mounted) {
widget.onSnackbar( // if (mounted) {
"Error capturing or scanning the image. Please try again."); // widget.onSnackbar(
} // "Error capturing or scanning the image. Please try again.");
// }
} }
} }
} }
@ -2292,17 +2273,38 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
); );
if (result == null || result.files.single.path == null) { if (result == null || result.files.single.path == null) {
widget.onSnackbar("No file selected."); await showDialog<void>(
context: context,
builder: (_) => const StackOkDialog(
title: "Error scanning QR code",
message: "No file selected.",
),
);
return; return;
} }
final filePath = result.files.single.path!; final filePath = result?.files.single.path!;
if (filePath == null) {
await showDialog<void>(
context: context,
builder: (_) => const StackOkDialog(
title: "Error scanning QR code",
message: "Error selecting file.",
),
);
return;
}
try { try {
final img.Image? image = final img.Image? image =
img.decodeImage(File(filePath).readAsBytesSync()); img.decodeImage(File(filePath!).readAsBytesSync());
if (image == null) { if (image == null) {
widget.onSnackbar( await showDialog<void>(
"Failed to decode image. Please select a valid image file."); context: context,
builder: (_) => const StackOkDialog(
title: "Error scanning QR code",
message: "Failed to decode image.",
),
);
return; return;
} }
@ -2311,13 +2313,25 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
widget.onQrCodeDetected(scanResult); widget.onQrCodeDetected(scanResult);
Navigator.of(context).pop(); Navigator.of(context).pop();
} else { } else {
widget.onSnackbar("No QR code found in the image."); await showDialog<void>(
context: context,
builder: (_) => const StackOkDialog(
title: "Error scanning QR code",
message: "No QR code found in the image.",
),
);
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log("Failed to decode image: $e\n$s", Logging.instance.log("Failed to decode image: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
widget.onSnackbar( await showDialog<void>(
"Error processing the image. Please try again."); context: context,
builder: (_) => const StackOkDialog(
title: "Error scanning QR code",
message:
"Error processing the image. Please try again.",
),
);
} }
}, },
), ),