mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 06:38:52 +00:00
chore: satisfy linter
This commit is contained in:
parent
cdf2dd8819
commit
e749c62ccd
1 changed files with 83 additions and 66 deletions
|
@ -23,14 +23,15 @@ import 'primary_button.dart';
|
||||||
import 'secondary_button.dart';
|
import 'secondary_button.dart';
|
||||||
|
|
||||||
class QrCodeScannerDialog extends StatefulWidget {
|
class QrCodeScannerDialog extends StatefulWidget {
|
||||||
final Function(String) onQrCodeDetected;
|
final void Function(String) onQrCodeDetected;
|
||||||
|
|
||||||
QrCodeScannerDialog({
|
const QrCodeScannerDialog({
|
||||||
|
super.key,
|
||||||
required this.onQrCodeDetected,
|
required this.onQrCodeDetected,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_QrCodeScannerDialogState createState() => _QrCodeScannerDialogState();
|
State<QrCodeScannerDialog> createState() => _QrCodeScannerDialogState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
|
@ -66,16 +67,16 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (Platform.isLinux && _cameraLinuxPlugin != null) {
|
if (Platform.isLinux && _cameraLinuxPlugin != null) {
|
||||||
await _cameraLinuxPlugin!.initializeCamera();
|
await _cameraLinuxPlugin.initializeCamera();
|
||||||
Logging.instance.log("Linux Camera initialized", level: LogLevel.Info);
|
Logging.instance.log("Linux Camera initialized", level: LogLevel.Info);
|
||||||
} else if (Platform.isWindows && _cameraWindowsPlugin != null) {
|
} else if (Platform.isWindows && _cameraWindowsPlugin != null) {
|
||||||
final List<CameraDescription> cameras =
|
final List<CameraDescription> cameras =
|
||||||
await _cameraWindowsPlugin!.availableCameras();
|
await _cameraWindowsPlugin.availableCameras();
|
||||||
if (cameras.isEmpty) {
|
if (cameras.isEmpty) {
|
||||||
throw CameraException('No cameras available', 'No cameras found.');
|
throw CameraException('No cameras available', 'No cameras found.');
|
||||||
}
|
}
|
||||||
final CameraDescription camera = cameras[0]; // Could be user-selected.
|
final CameraDescription camera = cameras[0]; // Could be user-selected.
|
||||||
_cameraId = await _cameraWindowsPlugin!.createCameraWithSettings(
|
_cameraId = await _cameraWindowsPlugin.createCameraWithSettings(
|
||||||
camera,
|
camera,
|
||||||
const MediaSettings(
|
const MediaSettings(
|
||||||
resolutionPreset: ResolutionPreset.low,
|
resolutionPreset: ResolutionPreset.low,
|
||||||
|
@ -84,11 +85,13 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
enableAudio: false,
|
enableAudio: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
await _cameraWindowsPlugin!.initializeCamera(_cameraId);
|
await _cameraWindowsPlugin.initializeCamera(_cameraId);
|
||||||
// await _cameraWindowsPlugin!.onCameraInitialized(_cameraId).first;
|
// await _cameraWindowsPlugin!.onCameraInitialized(_cameraId).first;
|
||||||
// TODO [prio=low]: Make this work. ^^^
|
// TODO [prio=low]: Make this work. ^^^
|
||||||
Logging.instance.log("Windows Camera initialized with ID: $_cameraId",
|
Logging.instance.log(
|
||||||
level: LogLevel.Info);
|
"Windows Camera initialized with ID: $_cameraId",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
} else if (Platform.isMacOS) {
|
} else if (Platform.isMacOS) {
|
||||||
final List<CameraMacOSDevice> videoDevices = await CameraMacOS.instance
|
final List<CameraMacOSDevice> videoDevices = await CameraMacOS.instance
|
||||||
.listDevices(deviceType: CameraMacOSDeviceType.video);
|
.listDevices(deviceType: CameraMacOSDeviceType.video);
|
||||||
|
@ -105,7 +108,8 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
|
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"macOS Camera initialized with ID: $_macOSDeviceId",
|
"macOS Camera initialized with ID: $_macOSDeviceId",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -129,13 +133,15 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
Future<void> _stopCamera() async {
|
Future<void> _stopCamera() async {
|
||||||
try {
|
try {
|
||||||
if (Platform.isLinux && _cameraLinuxPlugin != null) {
|
if (Platform.isLinux && _cameraLinuxPlugin != null) {
|
||||||
_cameraLinuxPlugin!.stopCamera();
|
_cameraLinuxPlugin.stopCamera();
|
||||||
Logging.instance.log("Linux Camera stopped", level: LogLevel.Info);
|
Logging.instance.log("Linux Camera stopped", level: LogLevel.Info);
|
||||||
} else if (Platform.isWindows && _cameraWindowsPlugin != null) {
|
} else if (Platform.isWindows && _cameraWindowsPlugin != null) {
|
||||||
// if (_cameraId >= 0) {
|
// if (_cameraId >= 0) {
|
||||||
await _cameraWindowsPlugin!.dispose(_cameraId);
|
await _cameraWindowsPlugin.dispose(_cameraId);
|
||||||
Logging.instance.log("Windows Camera stopped with ID: $_cameraId",
|
Logging.instance.log(
|
||||||
level: LogLevel.Info);
|
"Windows Camera stopped with ID: $_cameraId",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
// } else {
|
// } else {
|
||||||
// Logging.instance.log("Windows Camera ID is null. Cannot dispose.",
|
// Logging.instance.log("Windows Camera ID is null. Cannot dispose.",
|
||||||
// level: LogLevel.Error);
|
// level: LogLevel.Error);
|
||||||
|
@ -143,8 +149,10 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
} else if (Platform.isMacOS) {
|
} else if (Platform.isMacOS) {
|
||||||
// if (_macOSDeviceId != null) {
|
// if (_macOSDeviceId != null) {
|
||||||
await CameraMacOS.instance.stopImageStream();
|
await CameraMacOS.instance.stopImageStream();
|
||||||
Logging.instance.log("macOS Camera stopped with ID: $_macOSDeviceId",
|
Logging.instance.log(
|
||||||
level: LogLevel.Info);
|
"macOS Camera stopped with ID: $_macOSDeviceId",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
// } else {
|
// } else {
|
||||||
// Logging.instance.log("macOS Camera ID is null. Cannot stop.",
|
// Logging.instance.log("macOS Camera ID is null. Cannot stop.",
|
||||||
// level: LogLevel.Error);
|
// level: LogLevel.Error);
|
||||||
|
@ -168,7 +176,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
try {
|
try {
|
||||||
String? base64Image;
|
String? base64Image;
|
||||||
if (Platform.isLinux && _cameraLinuxPlugin != null) {
|
if (Platform.isLinux && _cameraLinuxPlugin != null) {
|
||||||
base64Image = await _cameraLinuxPlugin!.captureImage();
|
base64Image = await _cameraLinuxPlugin.captureImage();
|
||||||
} else if (Platform.isWindows) {
|
} else if (Platform.isWindows) {
|
||||||
final XFile xfile =
|
final XFile xfile =
|
||||||
await _cameraWindowsPlugin!.takePicture(_cameraId);
|
await _cameraWindowsPlugin!.takePicture(_cameraId);
|
||||||
|
@ -180,14 +188,14 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
if (macOSimg == null) {
|
if (macOSimg == null) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("Failed to capture image", level: LogLevel.Error);
|
.log("Failed to capture image", level: LogLevel.Error);
|
||||||
await Future.delayed(Duration(milliseconds: _imageDelayInMs));
|
await Future<void>.delayed(Duration(milliseconds: _imageDelayInMs));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final img.Image? image = img.decodeImage(macOSimg.bytes!);
|
final img.Image? image = img.decodeImage(macOSimg.bytes!);
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("Failed to capture image", level: LogLevel.Error);
|
.log("Failed to capture image", level: LogLevel.Error);
|
||||||
await Future.delayed(Duration(milliseconds: _imageDelayInMs));
|
await Future<void>.delayed(Duration(milliseconds: _imageDelayInMs));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
base64Image = base64Encode(img.encodePng(image));
|
base64Image = base64Encode(img.encodePng(image));
|
||||||
|
@ -196,7 +204,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
// Logging.instance
|
// Logging.instance
|
||||||
// .log("Failed to capture image", level: LogLevel.Error);
|
// .log("Failed to capture image", level: LogLevel.Error);
|
||||||
// Spammy.
|
// Spammy.
|
||||||
await Future.delayed(Duration(milliseconds: _imageDelayInMs));
|
await Future<void>.delayed(Duration(milliseconds: _imageDelayInMs));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final img.Image? image = img.decodeImage(base64Decode(base64Image));
|
final img.Image? image = img.decodeImage(base64Decode(base64Image));
|
||||||
|
@ -205,7 +213,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
// > decoders, it is much slower than using an explicit decoder
|
// > decoders, it is much slower than using an explicit decoder
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
Logging.instance.log("Failed to decode image", level: LogLevel.Error);
|
Logging.instance.log("Failed to decode image", level: LogLevel.Error);
|
||||||
await Future.delayed(Duration(milliseconds: _imageDelayInMs));
|
await Future<void>.delayed(Duration(milliseconds: _imageDelayInMs));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,8 +241,8 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
// Spammy.
|
// Spammy.
|
||||||
}
|
}
|
||||||
|
|
||||||
await Future.delayed(Duration(milliseconds: _imageDelayInMs));
|
await Future<void>.delayed(Duration(milliseconds: _imageDelayInMs));
|
||||||
} catch (e, s) {
|
} catch (e) {
|
||||||
// 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.
|
||||||
|
|
||||||
|
@ -266,7 +274,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return qrDecode.text;
|
return qrDecode.text;
|
||||||
} catch (e, s) {
|
} catch (e) {
|
||||||
// Logging.instance.log("Failed to decode QR code: $e\n$s", level: LogLevel.Error);
|
// Logging.instance.log("Failed to decode QR code: $e\n$s", level: LogLevel.Error);
|
||||||
// Spammy.
|
// Spammy.
|
||||||
return null;
|
return null;
|
||||||
|
@ -322,6 +330,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
allowedExtensions: ["png", "jpg", "jpeg"],
|
allowedExtensions: ["png", "jpg", "jpeg"],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
if (result == null || result.files.single.path == null) {
|
if (result == null || result.files.single.path == null) {
|
||||||
await showFloatingFlushBar(
|
await showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
|
@ -332,7 +341,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final filePath = result?.files.single.path!;
|
final filePath = result.files.single.path;
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
await showFloatingFlushBar(
|
await showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
|
@ -342,9 +351,10 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
);
|
);
|
||||||
return;
|
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) {
|
||||||
await showFloatingFlushBar(
|
await showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
|
@ -356,6 +366,7 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String? scanResult = await _scanImage(image);
|
final String? scanResult = await _scanImage(image);
|
||||||
|
if (context.mounted) {
|
||||||
if (scanResult != null && scanResult.isNotEmpty) {
|
if (scanResult != null && scanResult.isNotEmpty) {
|
||||||
widget.onQrCodeDetected(scanResult);
|
widget.onQrCodeDetected(scanResult);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
@ -367,9 +378,13 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
context: context,
|
context: context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("Failed to decode image: $e\n$s",
|
Logging.instance.log(
|
||||||
level: LogLevel.Error);
|
"Failed to decode image: $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
if (context.mounted) {
|
||||||
await showFloatingFlushBar(
|
await showFloatingFlushBar(
|
||||||
type: FlushBarType.info,
|
type: FlushBarType.info,
|
||||||
message:
|
message:
|
||||||
|
@ -378,6 +393,8 @@ class _QrCodeScannerDialogState extends State<QrCodeScannerDialog> {
|
||||||
context: context,
|
context: context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
|
|
Loading…
Reference in a new issue