Skip to content

Commit 5b5b300

Browse files
authored
Fix QR code scanner of purchases (strictly) (#600)
* [x] Fix `onScan` argument type to actually pass the scanned secret downstream down to the request to Hyperion * [x] replace "validate" button with "next"
1 parent b5a3aeb commit 5b5b300

File tree

2 files changed

+58
-59
lines changed

2 files changed

+58
-59
lines changed

lib/purchases/ui/pages/scan_page/qr_code_scanner.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class QRCodeScannerScreen extends StatefulWidget {
1010
required this.scanner,
1111
});
1212

13-
final Function onScan;
13+
final Function(String) onScan;
1414
final AsyncValue<Ticket> scanner;
1515

1616
@override
@@ -46,10 +46,13 @@ class QRCodeScannerScreenState extends State<QRCodeScannerScreen> {
4646
);
4747
},
4848
onDetect: (BarcodeCapture capture) async {
49+
final rawValue = capture.barcodes.firstOrNull?.rawValue;
4950
setState(() {
50-
qrCode = capture.barcodes.first.rawValue;
51+
qrCode = rawValue;
5152
});
52-
widget.onScan(qrCode!);
53+
if (rawValue != null) {
54+
widget.onScan(rawValue);
55+
}
5356
},
5457
);
5558
}

lib/purchases/ui/pages/scan_page/scan_dialog.dart

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -195,72 +195,68 @@ class ScanDialog extends HookConsumerWidget {
195195
),
196196
),
197197
const SizedBox(height: 30),
198-
Padding(
199-
padding: const EdgeInsets.symmetric(horizontal: 20),
200-
child: Row(
201-
children: [
202-
GestureDetector(
203-
onTap: () {
204-
scannerNotifier.reset();
205-
},
206-
child: const SizedBox(
207-
width: 100,
208-
child: AddEditButtonLayout(
209-
color: Colors.red,
210-
child: Text(
211-
"Annuler",
212-
style: TextStyle(
213-
color: Colors.white,
214-
fontWeight: FontWeight.bold,
215-
fontSize: 20,
198+
if (data.qrCodeSecret != "")
199+
Padding(
200+
padding: const EdgeInsets.symmetric(
201+
horizontal: 20,
202+
),
203+
child: Row(
204+
children: [
205+
GestureDetector(
206+
onTap: () {
207+
scannerNotifier.reset();
208+
},
209+
child: const SizedBox(
210+
width: 100,
211+
child: AddEditButtonLayout(
212+
color: Colors.red,
213+
child: Text(
214+
"Annuler",
215+
style: TextStyle(
216+
color: Colors.white,
217+
fontWeight: FontWeight.bold,
218+
fontSize: 20,
219+
),
216220
),
217221
),
218222
),
219223
),
220-
),
221-
const Spacer(),
222-
GestureDetector(
223-
onTap: () async {
224-
await tokenExpireWrapper(ref, () async {
225-
final value = await ticketListNotifier
226-
.consumeTicket(
227-
sellerId,
228-
data,
229-
ticket.id,
230-
tag,
224+
const Spacer(),
225+
GestureDetector(
226+
onTap: () async {
227+
await tokenExpireWrapper(ref, () async {
228+
await (ticketListNotifier.consumeTicket(
229+
sellerId,
230+
data,
231+
ticket.id,
232+
tag == "" ? "no tag" : tag,
233+
)).then((_) {
234+
displayToastWithContext(
235+
TypeMsg.msg,
236+
"Scan validé",
231237
);
232-
if (value) {
233-
displayToastWithContext(
234-
TypeMsg.msg,
235-
"Scan validé",
236-
);
237-
scannerNotifier.reset();
238-
} else {
239-
displayToastWithContext(
240-
TypeMsg.error,
241-
"Erreur lors de la validation",
242-
);
243-
}
244-
});
245-
},
246-
child: const SizedBox(
247-
width: 100,
248-
child: AddEditButtonLayout(
249-
color: Colors.green,
250-
child: Text(
251-
"Valider",
252-
style: TextStyle(
253-
color: Colors.white,
254-
fontWeight: FontWeight.bold,
255-
fontSize: 20,
238+
scannerNotifier.reset();
239+
});
240+
});
241+
},
242+
child: const SizedBox(
243+
width: 100,
244+
child: AddEditButtonLayout(
245+
color: Colors.green,
246+
child: Text(
247+
"Suivant",
248+
style: TextStyle(
249+
color: Colors.white,
250+
fontWeight: FontWeight.bold,
251+
fontSize: 20,
252+
),
256253
),
257254
),
258255
),
259256
),
260-
),
261-
],
257+
],
258+
),
262259
),
263-
),
264260
],
265261
);
266262
},

0 commit comments

Comments
 (0)