diff --git a/lib/views/import_tokens_view/pages/import_start_page.dart b/lib/views/import_tokens_view/pages/import_start_page.dart index d53879944..c993a764f 100644 --- a/lib/views/import_tokens_view/pages/import_start_page.dart +++ b/lib/views/import_tokens_view/pages/import_start_page.dart @@ -27,10 +27,15 @@ import 'import_plain_tokens_page.dart'; void _decodeQrFileIsolate(List args) async { final sendPort = args[0] as SendPort; final XFile file = args[1] as XFile; - final image = img.decodeImage(await file.readAsBytes()); + final bool isSecondTry = args.length > 2 ? args[2] as bool : false; + var image = img.decodeImage(await file.readAsBytes()); if (image == null) { Isolate.exit(sendPort, null); } + // Rotate image by 90 degrees + if (isSecondTry) { + image = img.copyRotate(image, angle: 90); + } LuminanceSource source = RGBLuminanceSource( image.width, @@ -236,8 +241,12 @@ class _ImportStartPageState extends State { try { qrResult = await _startDecodeQrFile(file); } on FormatReaderException catch (_) { - setState(() => _errorText = localizations.qrFileDecodeError); - return; + try { + qrResult = await _startDecodeQrFile(file, isSecondTry: true); + } on FormatReaderException catch (_) { + setState(() => _errorText = localizations.qrFileDecodeError); + return; + } } catch (e) { setState(() => _errorText = localizations.invalidQrFile(widget.appName)); return; @@ -268,10 +277,10 @@ class _ImportStartPageState extends State { _routeImportPlainTokensPage(importResults: processorResults); } - Future _startDecodeQrFile(XFile file) async { + Future _startDecodeQrFile(XFile file, {bool isSecondTry = false}) async { final receivePort = ReceivePort(); try { - await Isolate.spawn(_decodeQrFileIsolate, [receivePort.sendPort, file]); + await Isolate.spawn(_decodeQrFileIsolate, [receivePort.sendPort, file, isSecondTry]); } catch (_) { receivePort.close(); rethrow;