-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathrequest_identifier_screen.dart
More file actions
178 lines (164 loc) · 5.64 KB
/
Copy pathrequest_identifier_screen.dart
File metadata and controls
178 lines (164 loc) · 5.64 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/widgets/buttons/button.dart';
import 'package:bb_mobile/core/widgets/inputs/text_input.dart';
import 'package:bb_mobile/core/widgets/navbar/top_bar.dart';
import 'package:bb_mobile/core/widgets/qr_scanner_widget.dart';
import 'package:bb_mobile/core/widgets/text/text.dart';
import 'package:bb_mobile/features/send/request_identifier/request_identifier_cubit.dart';
import 'package:bb_mobile/features/send/request_identifier/request_identifier_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
class RequestIdentifierScreen extends StatelessWidget {
const RequestIdentifierScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: context.appColors.secondaryFixedDim,
appBar: AppBar(
forceMaterialTransparency: true,
automaticallyImplyLeading: false,
flexibleSpace: TopBar(
title: context.loc.sendTitle,
color: context.appColors.secondaryFixedDim,
onBack: () => context.pop(),
),
),
body: BlocConsumer<RequestIdentifierCubit, RequestIdentifierState>(
listener: (context, state) {
if (state.redirect != null) {
// switch (state.redirect) {
// case RequestIdentifierRedirect.toSend:
// context.go('/send');
// break;
// case RequestIdentifierRedirect.toNostr:
// context.go('/send');
// break;
// }
}
},
builder: (context, state) {
final cubit = context.read<RequestIdentifierCubit>();
return Stack(
fit: .expand,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.5,
child: QrScannerWidget(onScanned: cubit.onScanned),
),
Positioned(
left: 0,
right: 0,
bottom: 0,
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
color: context.appColors.surface,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
),
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: .stretch,
mainAxisSize: .min,
children: [
const Gap(32),
BBText(
context.loc.sendRecipientAddressOrInvoice,
style: context.font.bodyMedium,
),
const Gap(16),
const PasteRequestWidget(),
const Gap(16),
const RequestErrorWidget(),
const Gap(16),
const ContinueButtonWidget(),
const Gap(42),
],
),
),
),
),
],
);
},
),
);
}
}
class PasteRequestWidget extends StatelessWidget {
const PasteRequestWidget({super.key});
@override
Widget build(BuildContext context) {
final address = context.select<RequestIdentifierCubit, String>(
(cubit) => cubit.state.rawRequest,
);
final cubit = context.read<RequestIdentifierCubit>();
return BBInputText(
onlyPaste: true,
onChanged: cubit.updateRawRequest,
value: address,
hint: context.loc.sendPasteAddressOrInvoice,
hintStyle: context.font.bodyLarge?.copyWith(
color: context.appColors.surfaceContainer,
),
maxLines: 1,
rightIcon: Icon(
Icons.paste_sharp,
color: context.appColors.secondary,
size: 20,
),
onRightTap: () {
Clipboard.getData(Clipboard.kTextPlain).then((value) {
final clipboard = value?.text;
if (clipboard == null) return;
cubit.updateRawRequest(clipboard);
});
},
);
}
}
class RequestErrorWidget extends StatelessWidget {
const RequestErrorWidget({super.key});
@override
Widget build(BuildContext context) {
final error = context.select(
(RequestIdentifierCubit cubit) => cubit.state.error,
);
if (error.isNotEmpty) {
return BBText(
error,
style: context.font.bodyMedium,
color: context.appColors.error,
textAlign: .center,
maxLines: 2,
);
}
return const SizedBox(height: 21);
}
}
class ContinueButtonWidget extends StatelessWidget {
const ContinueButtonWidget({super.key});
@override
Widget build(BuildContext context) {
final hasRequest = context.select(
(RequestIdentifierCubit cubit) => cubit.state.rawRequest.isNotEmpty,
);
final hasError = context.select(
(RequestIdentifierCubit cubit) => cubit.state.error.isNotEmpty,
);
final cubit = context.read<RequestIdentifierCubit>();
return BBButton.big(
label: context.loc.sendContinue,
onPressed: cubit.validatePaymentRequest,
disabled: !hasRequest || hasError,
bgColor: context.appColors.secondary,
textColor: context.appColors.onSecondary,
);
}
}