dev
dart 158 lines 5.26 KB
Raw
1 import 'package:cake_wallet/anonpay/anonpay_info_base.dart';
2 import 'package:cake_wallet/anonpay/anonpay_invoice_info.dart';
3 import 'package:cake_wallet/entities/qr_view_data.dart';
4 import 'package:cw_core/receive_page_option.dart';
5 import 'package:cake_wallet/generated/i18n.dart';
6 import 'package:cake_wallet/routes.dart';
7 import 'package:cake_wallet/src/screens/base_page.dart';
8 import 'package:cake_wallet/src/widgets/gradient_background.dart';
9 import 'package:cake_wallet/src/screens/receive/widgets/anonpay_status_section.dart';
10 import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
11 import 'package:cake_wallet/src/screens/receive/widgets/copy_link_item.dart';
12 import 'package:cake_wallet/utils/brightness_util.dart';
13 import 'package:flutter/material.dart';
14 import 'package:qr_flutter/qr_flutter.dart' as qr;
15
16 class AnonPayReceivePageArgs {
17 final AnonpayInfoBase invoiceInfo;
18 final String? qrImage;
19
20 AnonPayReceivePageArgs({required this.invoiceInfo, this.qrImage});
21 }
22
23 class AnonPayReceivePage extends BasePage {
24 AnonPayReceivePage({required this.args}) : invoiceInfo = args.invoiceInfo;
25
26 final AnonPayReceivePageArgs args;
27 final AnonpayInfoBase invoiceInfo;
28
29 @override
30 String get title => S.current.receive;
31
32 @override
33 bool get gradientBackground => true;
34
35 @override
36 bool get resizeToAvoidBottomInset => false;
37
38 @override
39 void onClose(BuildContext context) => Navigator.popUntil(context, (route) => route.isFirst);
40
41 @override
42 Widget middle(BuildContext context) {
43 return Column(
44 children: [
45 Text(
46 title,
47 style: Theme.of(context).textTheme.bodyLarge!.copyWith(
48 fontSize: 18.0,
49 fontWeight: FontWeight.bold,
50 color: Theme.of(context).colorScheme.onSurfaceVariant,
51 ),
52 ),
53 Text(
54 invoiceInfo is AnonpayInvoiceInfo
55 ? ReceivePageOption.anonPayInvoice.toString()
56 : ReceivePageOption.anonPayDonationLink.toString(),
57 style: Theme.of(context).textTheme.bodySmall!.copyWith(
58 fontSize: 10.0,
59 fontWeight: FontWeight.w500,
60 color: Theme.of(context).colorScheme.onSurfaceVariant,
61 ),
62 )
63 ],
64 );
65 }
66
67 @override
68 Widget? trailing(BuildContext context) {
69 if (invoiceInfo is AnonpayInvoiceInfo) {
70 return null;
71 }
72
73 return Material(
74 color: Colors.transparent,
75 child: IconButton(
76 onPressed: () => Navigator.popAndPushNamed(
77 context,
78 Routes.anonPayInvoicePage,
79 arguments: [invoiceInfo.address, ReceivePageOption.anonPayDonationLink],
80 ),
81 icon: Icon(
82 Icons.edit,
83 color: pageIconColor(context),
84 size: 22.0,
85 ),
86 ),
87 );
88 }
89
90 @override
91 Widget Function(BuildContext, Widget) get rootWrapper =>
92 (BuildContext context, Widget scaffold) => GradientBackground(scaffold: scaffold);
93
94 @override
95 Widget body(BuildContext context) {
96 return SingleChildScrollView(
97 child: Column(
98 children: <Widget>[
99 SizedBox(height: 24),
100 if (invoiceInfo is AnonpayInvoiceInfo)
101 AnonInvoiceStatusSection(invoiceInfo: invoiceInfo as AnonpayInvoiceInfo),
102 Padding(
103 padding: EdgeInsets.fromLTRB(24, 50, 24, 24),
104 child: ConstrainedBox(
105 constraints: BoxConstraints(
106 maxWidth: MediaQuery.of(context).size.width * 0.5,
107 ),
108 child: GestureDetector(
109 onTap: () async {
110 BrightnessUtil.changeBrightnessForFunction(() async {
111 await Navigator.pushNamed(context, Routes.fullscreenQR,
112 arguments: QrViewData(
113 data: invoiceInfo.clearnetUrl,
114 version: qr.QrVersions.auto,
115 embeddedImagePath: args.qrImage,
116 ));
117 });
118 },
119 child: Hero(
120 tag: Key(invoiceInfo.clearnetUrl),
121 child: Center(
122 child: AspectRatio(
123 aspectRatio: 1.0,
124 child: Container(
125 padding: EdgeInsets.all(5),
126 decoration: BoxDecoration(
127 border: Border.all(
128 width: 3,
129 color: Theme.of(context).colorScheme.onSurfaceVariant,
130 ),
131 ),
132 child: QrImage(
133 data: invoiceInfo.clearnetUrl,
134 version: qr.QrVersions.auto,
135 embeddedImagePath: args.qrImage,
136 size: 230,
137 ),
138 ),
139 ),
140 ),
141 ),
142 ),
143 ),
144 ),
145 SizedBox(height: 24),
146 Column(
147 children: [
148 CopyLinkItem(url: invoiceInfo.clearnetUrl, title: S.of(context).clearnet_link),
149 SizedBox(height: 16),
150 CopyLinkItem(url: invoiceInfo.onionUrl, title: S.of(context).onion_link),
151 ],
152 ),
153 SizedBox(height: 100),
154 ],
155 ),
156 );
157 }
158 }