-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathfull_screen_scanner_page.dart
More file actions
88 lines (79 loc) · 2.69 KB
/
Copy pathfull_screen_scanner_page.dart
File metadata and controls
88 lines (79 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/payment_request.dart';
import 'package:bb_mobile/core/widgets/buttons/button.dart';
import 'package:bb_mobile/core/widgets/qr_scanner_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
/// Callback for when a payment request is detected from a QR code
typedef OnScannedPaymentRequestCallback =
void Function((String, PaymentRequest?) data);
class FullScreenScannerPage extends StatefulWidget {
final OnScannedPaymentRequestCallback onScannedPaymentRequest;
const FullScreenScannerPage({
super.key,
required this.onScannedPaymentRequest,
});
@override
State<FullScreenScannerPage> createState() => _FullScreenScannerState();
}
class _FullScreenScannerState extends State<FullScreenScannerPage> {
(String, PaymentRequest?) data = ('', null);
Future<void> _onScanned(String qr) async {
if (!mounted) return;
try {
final pr = await PaymentRequest.parse(qr);
data = (qr, pr);
widget.onScannedPaymentRequest(data);
if (mounted) context.pop();
} catch (e) {
data = (qr, null);
widget.onScannedPaymentRequest(data);
if (mounted) context.pop();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: context.appColors.secondaryFixedDim,
body: Stack(
fit: .expand,
children: [
QrScannerWidget(onScanned: _onScanned),
if (data.$1.isNotEmpty)
Positioned(
bottom: MediaQuery.of(context).size.height * 0.25,
left: 24,
right: 24,
child: BBButton.big(
iconData: Icons.check_circle,
textStyle: context.font.labelMedium,
textColor: context.appColors.onPrimary,
onPressed: () {},
label:
data.$1.length > 30
? '${data.$1.substring(0, 10)}…${data.$1.substring(data.$1.length - 10)}'
: data.$1,
bgColor: context.appColors.transparent,
),
),
Positioned(
bottom: MediaQuery.of(context).size.height * 0.02,
left: 0,
right: 0,
child: Center(
child: IconButton(
onPressed: context.mounted ? () => context.pop() : null,
icon: Icon(
CupertinoIcons.xmark_circle,
color: context.appColors.onPrimary,
size: 64,
),
),
),
),
],
),
);
}
}