purchase_view.dart
12.5 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
import 'package:doublefeel_flutter/app/utils/assets_helper.dart';
import 'package:doublefeel_flutter/app/widget/payment_confirmation_bottom_sheet.dart';
import 'package:doublefeel_flutter/app/widget/premium_benefit_list_view.dart';
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:doublefeel_flutter/l10n/l10n_extensions.dart';
import 'package:doublefeel_flutter/r.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import '../controllers/purchase_controller.dart';
import '../purchase_route_args.dart';
import '../widgets/purchase_bottom_bar.dart';
import '../widgets/purchase_colors.dart';
import '../widgets/purchase_plan_card.dart';
class PurchaseView extends GetView<PurchaseController> {
const PurchaseView({super.key});
@override
Widget build(BuildContext context) {
return PopScope(
canPop: !controller.isFromOnboard,
onPopInvokedWithResult: (didPop, _) {
if (!didPop) controller.onBackPressed();
},
child: AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.light,
systemNavigationBarColor: PurchaseColors.background,
systemNavigationBarIconBrightness: Brightness.dark,
),
child: Scaffold(
backgroundColor: PurchaseColors.background,
body: Stack(
children: [
Positioned.fill(
child: SingleChildScrollView(
controller: controller.scrollController,
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.only(
bottom: 170 + MediaQuery.paddingOf(context).bottom,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const _HeroHeader(),
Padding(
padding: EdgeInsets.only(left: 18, top: 9.h),
child: Text(
context.l10n.purchaseHeroTitle,
style: const TextStyle(
color: Colors.black,
fontSize: 24,
fontWeight: FontWeight.w600,
height: 1.2,
),
),
),
const SizedBox(height: 26),
_PlanScroller(controller: controller),
const SizedBox(height: 22),
_SectionTitle(context.l10n.purchaseBenefitsTitle),
const SizedBox(height: 14),
const PremiumBenefitListView(),
const SizedBox(height: 24),
_LegalNotes(controller: controller),
],
),
),
),
Positioned(
left: 0,
right: 0,
top: 0,
child: _PurchaseNavigationBar(controller: controller),
),
Positioned(
left: 0,
right: 0,
bottom: 0,
child: Obx(
() => PurchaseBottomBar(
label: context.l10n.purchaseUnlockNow,
loading: controller.isUnlocking.value,
onPressed: () {
if (controller.isOhos) {
final plan = controller.selectedPlan;
if (plan == null) {
controller.unlock();
return;
}
showPaymentConfirmationBottomSheet(
amount: plan.price,
productName: plan.title.isEmpty
? 'DoubleFeel终身会员'
: plan.title,
paymentMethod: const PaymentMethod(
name: '支付宝支付',
iconAsset:
'assets/images/premium/ic_payment_alipay.png',
),
onPay: controller.unlock,
);
return;
}
controller.unlock();
},
onTermsTap: controller.openUserTerms,
onPrivacyTap: controller.openPrivacyPolicy,
),
),
),
],
),
),
));
}
}
class _HeroHeader extends StatelessWidget {
const _HeroHeader();
@override
Widget build(BuildContext context) {
return SizedBox(
height: 320.h,
width: double.infinity,
child: Image.asset(
assetCompatPath('assets/images/premium/bg_purchase_top.webp'),
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
),
);
}
}
class _PlanScroller extends StatelessWidget {
const _PlanScroller({required this.controller});
final PurchaseController controller;
@override
Widget build(BuildContext context) {
return SizedBox(
height: 123,
child: Obx(
() {
if (controller.isLoadingProducts.value && controller.plans.isEmpty) {
return const Center(
child: CircularProgressIndicator(strokeWidth: 2),
);
}
final selectedIndex = controller.selectedIndex.value;
return ListView.separated(
controller: controller.planScrollController,
padding: const EdgeInsets.symmetric(horizontal: 18),
scrollDirection: Axis.horizontal,
physics: const ClampingScrollPhysics(),
itemCount: controller.plans.length,
separatorBuilder: (_, __) => const SizedBox(width: 12),
itemBuilder: (context, index) {
final plan = controller.plans[index];
return PurchasePlanCard(
plan: plan,
selected: selectedIndex == index,
onTap: () => controller.selectPlan(index),
);
},
);
},
),
);
}
}
class _SectionTitle extends StatelessWidget {
const _SectionTitle(this.text);
final String text;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
text,
style: const TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w600,
height: 1.2,
),
),
);
}
}
class _PurchaseNavigationBar extends StatelessWidget {
const _PurchaseNavigationBar({required this.controller});
final PurchaseController controller;
@override
Widget build(BuildContext context) {
final topInset = MediaQuery.paddingOf(context).top;
final arguments = Get.arguments;
final showCloseButton = arguments is Map &&
arguments[PurchaseRouteArgs.showCloseButton] == true;
return Obx(
() => AnimatedContainer(
duration: const Duration(milliseconds: 160),
height: topInset + 44,
padding: EdgeInsets.only(top: topInset),
color: controller.isScrolled.value ? Colors.white : Colors.transparent,
child: Row(
children: [
const SizedBox(width: 4),
IconButton(
onPressed: controller.onBackPressed,
icon: Image.asset(
showCloseButton
? R.assetsImagesCloseIcon
: R.assetsImagesNavBackIcon,
width: 24,
height: 24,
),
),
const Spacer(),
/*
TextButton(
onPressed: controller.isRestoring.value
? null
: controller.restorePurchase,
style: TextButton.styleFrom(
foregroundColor: PurchaseColors.title,
padding: const EdgeInsets.symmetric(horizontal: 16),
textStyle: const TextStyle(fontSize: 14, height: 1.2),
),
child: controller.isRestoring.value
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Text(context.l10n.purchaseRestore),
),
*/
],
),
),
);
}
}
class _LegalNotes extends StatelessWidget {
const _LegalNotes({required this.controller});
final PurchaseController controller;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.l10n.purchaseNotesTitle,
style: const TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w600,
height: 1.2,
),
),
const SizedBox(height: 24),
_LegalText(
prefix: '1. ',
text: context.l10n.purchaseNoteSubscription,
linkText: context.l10n.purchaseLinkLearnMore,
linkSuffix: '。',
onLinkTap: controller.openRefundExplanation,
),
const SizedBox(height: 12),
/*
_LegalText(
prefix: '3. ',
text: context.l10n.purchaseNoteRestore,
linkText: context.l10n.purchaseRestore,
linkSuffix: '。',
onLinkTap: controller.restorePurchase,
),
const SizedBox(height: 12),
*/
_LegalText(
prefix: '2. ',
text: context.l10n.purchaseNoteContact,
linkText: context.l10n.purchaseLinkContactUs,
linkSuffix: '。',
onLinkTap: controller.openContactUs,
),
],
),
);
}
}
class _LegalText extends StatefulWidget {
const _LegalText({
required this.prefix,
required this.text,
this.linkText,
this.linkSuffix,
this.onLinkTap,
});
final String prefix;
final String text;
final String? linkText;
final String? linkSuffix;
final VoidCallback? onLinkTap;
@override
State<_LegalText> createState() => _LegalTextState();
}
class _LegalTextState extends State<_LegalText> {
late final TapGestureRecognizer _linkRecognizer;
@override
void initState() {
super.initState();
_linkRecognizer = TapGestureRecognizer()..onTap = widget.onLinkTap;
}
@override
void didUpdateWidget(covariant _LegalText oldWidget) {
super.didUpdateWidget(oldWidget);
_linkRecognizer.onTap = widget.onLinkTap;
}
@override
void dispose() {
_linkRecognizer.dispose();
super.dispose();
}
static const _baseStyle = TextStyle(
color: PurchaseColors.subtitle,
fontSize: 12,
height: 1.4,
);
static const _linkStyle = TextStyle(
color: Color(0xFF845EEE),
fontWeight: FontWeight.w500,
decoration: TextDecoration.underline,
decorationColor: Color(0xFF845EEE),
);
TextSpan _buildTextSpan() => TextSpan(
style: _baseStyle,
children: [
TextSpan(text: widget.text),
if (widget.linkText case final linkText?)
TextSpan(
text: linkText,
style: _linkStyle,
recognizer: widget.onLinkTap == null ? null : _linkRecognizer,
),
if (widget.linkSuffix case final linkSuffix?)
TextSpan(text: linkSuffix),
],
);
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.prefix,
style: const TextStyle(
color: PurchaseColors.subtitle,
fontSize: 12,
height: 1.4,
),
),
Expanded(
child: Text.rich(
_buildTextSpan(),
textScaler: MediaQuery.textScalerOf(context),
),
),
],
);
}
}