cancel_subscription_dialog.dart
4.62 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
import 'package:doublefeel_flutter/core/util/size_extensions.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
/// Confirmation dialog for cancelling an OHOS auto-renewing subscription.
class CancelSubscriptionDialog extends StatefulWidget {
const CancelSubscriptionDialog({
super.key,
required this.onConfirm,
});
final Future<bool> Function() onConfirm;
@override
State<CancelSubscriptionDialog> createState() =>
_CancelSubscriptionDialogState();
}
class _CancelSubscriptionDialogState extends State<CancelSubscriptionDialog> {
bool _isSubmitting = false;
@override
Widget build(BuildContext context) {
return PopScope(
canPop: !_isSubmitting,
child: Dialog(
backgroundColor: Colors.transparent,
insetPadding: EdgeInsets.zero,
child: Container(
width: 300.dp,
padding: EdgeInsets.fromLTRB(24.dp, 24.dp, 24.dp, 20.dp),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24.dp),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
'assets/images/common/ic_warning.png',
width: 60.dp,
height: 60.dp,
),
SizedBox(height: 20.dp),
Column(
children: [
SizedBox(
width: 220.dp,
child: const Text(
'确认取消自动续费?',
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF141414),
fontSize: 18,
fontWeight: FontWeight.w600,
height: 1.2,
),
),
),
SizedBox(height: 16.dp),
const Text(
'取消后,DoubleFeel Pro 会员权益仍可使用至当前订阅周期结束,之后将不再自动续费或扣款。',
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF6E6D80),
fontSize: 15,
fontWeight: FontWeight.w400,
height: 1.35,
),
),
],
),
SizedBox(height: 20.dp),
_DialogButton(
label: '确定',
backgroundColor: const Color(0xFF845EEE),
foregroundColor: Colors.white,
loading: _isSubmitting,
onTap: _isSubmitting ? null : _confirm,
),
SizedBox(height: 4.dp),
_DialogButton(
label: '取消',
foregroundColor: const Color(0xFF6E6D80),
onTap: _isSubmitting ? null : Get.back,
),
],
),
),
),
);
}
Future<void> _confirm() async {
if (_isSubmitting) return;
setState(() => _isSubmitting = true);
try {
final shouldClose = await widget.onConfirm();
if (shouldClose && mounted && Get.isDialogOpen == true) {
Get.back<void>();
}
} finally {
if (mounted) setState(() => _isSubmitting = false);
}
}
}
class _DialogButton extends StatelessWidget {
const _DialogButton({
required this.label,
required this.foregroundColor,
required this.onTap,
this.backgroundColor,
this.loading = false,
});
final String label;
final Color foregroundColor;
final Color? backgroundColor;
final VoidCallback? onTap;
final bool loading;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: Container(
width: 220.dp,
height: 48.dp,
alignment: Alignment.center,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular(24.dp),
),
child: loading
? SizedBox(
width: 18.dp,
height: 18.dp,
child: const CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
)
: Text(
label,
style: TextStyle(
color: foregroundColor,
fontSize: 14,
fontWeight: FontWeight.w500,
height: 1.2,
),
),
),
);
}
}