-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathdca_wallet_selection_screen.dart
More file actions
210 lines (204 loc) · 8.38 KB
/
Copy pathdca_wallet_selection_screen.dart
File metadata and controls
210 lines (204 loc) · 8.38 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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/scrollable_column.dart';
import 'package:bb_mobile/features/dca/domain/dca.dart';
import 'package:bb_mobile/features/dca/presentation/dca_bloc.dart';
import 'package:bb_mobile/features/dca/ui/widgets/dca_wallet_radio_list.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart';
class DcaWalletSelectionScreen extends StatefulWidget {
const DcaWalletSelectionScreen({super.key});
@override
State<DcaWalletSelectionScreen> createState() =>
_DcaWalletSelectionScreenState();
}
class _DcaWalletSelectionScreenState extends State<DcaWalletSelectionScreen> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _lightningAddressController =
TextEditingController();
DcaNetwork? _selectedNetwork;
late String? _defaultLightningAddress;
bool _useDefaultLightningAddress = false;
@override
void initState() {
super.initState();
_defaultLightningAddress = context
.read<DcaBloc>()
.state
.defaultLightningAddress;
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
appBar: AppBar(title: Text(context.loc.dcaChooseWalletTitle)),
body: SafeArea(
child: Form(
key: _formKey,
child: ScrollableColumn(
crossAxisAlignment: .start,
children: [
const Gap(24),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 48),
child: Text(
context.loc.dcaWalletSelectionDescription,
style: Theme.of(context).textTheme.bodyMedium,
textAlign: .center,
),
),
const Gap(24),
FormField<DcaNetwork>(
initialValue: _selectedNetwork,
validator: (val) => val == null
? context.loc.dcaNetworkValidationError
: null,
builder: (field) {
return DcaWalletRadioList(
selectedWallet: field.value,
onChanged: (network) {
field.reset();
setState(() => _selectedNetwork = network);
field.didChange(network);
},
errorText: field.errorText,
);
},
),
if (_selectedNetwork == DcaNetwork.lightning) ...[
const Gap(16),
Text(
context.loc.dcaEnterLightningAddressLabel,
style: Theme.of(context).textTheme.bodyMedium,
),
const Gap(4),
TextFormField(
controller: _lightningAddressController,
textAlignVertical: TextAlignVertical.center,
style: context.font.headlineSmall?.copyWith(
color: _useDefaultLightningAddress
? context.appColors.surfaceContainer
: context.appColors.onSurface,
),
enabled: !_useDefaultLightningAddress,
decoration: InputDecoration(
fillColor: _useDefaultLightningAddress
? context.appColors.secondaryFixedDim
: context.appColors.surface,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: context.appColors.secondaryFixedDim,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: context.appColors.secondaryFixedDim,
),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: context.appColors.secondaryFixedDim.withValues(
alpha: 0.5,
),
),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16.0,
),
suffixIcon: IconButton(
icon: Icon(
Icons.paste,
color: _useDefaultLightningAddress
? context.appColors.surfaceContainer
: context.appColors.onSecondary,
),
onPressed: _useDefaultLightningAddress
? null
: () {
Clipboard.getData(Clipboard.kTextPlain).then((
value,
) {
if (value?.text != null) {
_lightningAddressController.text =
value!.text!;
}
});
},
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return context.loc.dcaLightningAddressEmptyError;
}
// TODO: Add a better Lightning address regex
if (!value.contains('@') ||
value.startsWith('@') ||
value.endsWith('@')) {
return context.loc.dcaLightningAddressInvalidError;
}
return null;
},
),
const Gap(8),
if (_defaultLightningAddress != null)
CheckboxListTile(
title: Text(context.loc.dcaUseDefaultLightningAddress),
value: _useDefaultLightningAddress,
onChanged: (value) {
setState(() {
_useDefaultLightningAddress = value ?? false;
});
if (value == true) {
_lightningAddressController.text =
_defaultLightningAddress!;
}
},
tileColor: context.appColors.overlay.withValues(
alpha: 0.04,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
],
const Gap(32),
BBButton.big(
label: context.loc.dcaWalletSelectionContinueButton,
onPressed: () {
if (_formKey.currentState!.validate()) {
context.read<DcaBloc>().add(
DcaEvent.walletSelected(
network: _selectedNetwork!,
lightningAddress: _lightningAddressController.text
.trim(),
useDefaultLightningAddress:
_useDefaultLightningAddress,
),
);
}
},
bgColor: context.appColors.secondary,
textColor: context.appColors.onSecondary,
),
const Gap(16.0),
],
),
),
),
),
);
}
@override
void dispose() {
_lightningAddressController.dispose();
super.dispose();
}
}