fix node QR Code URI parsing (#1916)

* fix:node QR Code URI parsing * optionally include user data * fix for qr scaner

Serhii committed Jan 24, 2025 at 20:05 UTC 4fe2be3c92de781d9583bfd57519e714aaf040ec
3 files changed +19 -16
lib/entities/qr_scanner.dart
+2 -4
@@ -23,7 +23,7 @@ Future<String> presentQRScanner(BuildContext context) async {
23 ),
24 );
25 isQrScannerShown = false;
26 - return result??'';
26 + return result!;
27 } catch (e) {
28 isQrScannerShown = false;
29 rethrow;
@@ -95,9 +95,7 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
95 setState(() {
96 popped = true;
97 });
98 - SchedulerBinding.instance.addPostFrameCallback((_) {
99 - Navigator.of(context).pop(_barcode?.rawValue ?? "");
100 - });
98 + Navigator.of(context).pop(_barcode!.rawValue ?? _barcode!.rawBytes);
99 }
100 }
101 }
lib/src/screens/nodes/widgets/node_form.dart
+6
@@ -58,6 +58,12 @@ class NodeForm extends StatelessWidget {
58 }
59 });
60
61 + reaction((_) => nodeViewModel.path, (String path) {
62 + if (path != _pathController.text) {
63 + _pathController.text = path;
64 + }
65 + });
66 +
67 _addressController.addListener(() => nodeViewModel.address = _addressController.text);
68 _pathController.addListener(() => nodeViewModel.path = _pathController.text);
69 _portController.addListener(() => nodeViewModel.port = _portController.text);
lib/view_model/node_list/node_create_or_edit_view_model.dart
+11 -12
@@ -219,23 +219,22 @@ abstract class NodeCreateOrEditViewModelBase with Store {
219 throw Exception('Unexpected scan QR code value: value is empty');
220 }
221
222 - final uri = Uri.tryParse(code);
223 -
224 - if (uri == null) {
225 - throw Exception('Unexpected scan QR code value: Value is invalid');
226 - }
222 + if (!code.contains('://')) code = 'tcp://$code';
223
228 - final userInfo = uri.userInfo.split(':');
229 -
230 - if (userInfo.length < 2) {
231 - throw Exception('Unexpected scan QR code value: Value is invalid');
224 + final uri = Uri.tryParse(code);
225 + if (uri == null || uri.host.isEmpty) {
226 + throw Exception('Invalid QR code: Unable to parse or missing host.');
227 }
228
234 - final rpcUser = userInfo[0];
235 - final rpcPassword = userInfo[1];
229 + final userInfo = uri.userInfo;
230 final ipAddress = uri.host;
237 - final port = uri.port.toString();
231 + final port = uri.hasPort ? uri.port.toString() : '';
232 final path = uri.path;
233 + final queryParams = uri.queryParameters; // Currently not used
234 + final rpcUser = userInfo.split(':').first;
235 + final rpcPassword = userInfo.split(':').length > 1 ? userInfo.split(':')[1] : '';
236 +
237 + await Future.delayed(Duration(milliseconds: 345));
238
239 setAddress(ipAddress);
240 setPath(path);