account_apple_page_v2.dart
6.97 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
import 'package:appframe/bloc/setting/account_apple_cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class AccountApplePageV2 extends StatelessWidget {
const AccountApplePageV2({super.key});
@override
Widget build(BuildContext context) {
final Map<String, dynamic>? extraData = GoRouterState.of(context).extra as Map<String, dynamic>?;
var appleId = extraData?['appleId'] ?? '';
return BlocProvider(
create: (context) => AccountAppleCubit(AccountAppleState(appleId: appleId)),
child: BlocConsumer<AccountAppleCubit, AccountAppleState>(
builder: (context, state) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text(
'Apple账号',
style: TextStyle(
color: Color(0xFF333333),
fontSize: 16,
fontWeight: FontWeight.bold,
height: 20 / 16,
),
),
centerTitle: true,
backgroundColor: Colors.white,
elevation: 0,
iconTheme: const IconThemeData(color: Colors.black),
),
body: (state.appleId != '' && !state.allowBind)
? _buildBound(context, state)
: _buildPlaceholder(context, state),
);
},
listener: (context, state) {},
),
);
}
// 已绑定状态视图
Widget _buildBound(BuildContext context, AccountAppleState state) {
return Column(
children: [
const SizedBox(height: 80),
const Text(
'已绑定Apple账号',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.normal,
letterSpacing: 0,
color: Color(0xFF333333),
),
),
const SizedBox(height: 15),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Text(
state.appleId,
style: const TextStyle(
fontSize: 21,
fontWeight: FontWeight.bold,
color: Color(0xFF333333),
),
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15, bottom: 15),
child: SizedBox(
width: double.infinity,
height: 44,
child: ElevatedButton(
onPressed: () {
context.read<AccountAppleCubit>().change();
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF7691FA),
foregroundColor: Colors.white,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(22),
),
),
child: const Text(
'更换绑定Apple账号',
style: TextStyle(
fontSize: 16,
height: 20 / 16,
color: Colors.white,
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15, bottom: 40),
child: SizedBox(
width: double.infinity,
height: 44,
child: OutlinedButton(
onPressed: () => _showUnbindDialog(context),
style: OutlinedButton.styleFrom(
foregroundColor: const Color(0xFF333333),
side: const BorderSide(color: Color(0xFFE5E5E5), width: 0.5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(26),
),
),
child: const Text(
'解绑',
style: TextStyle(
fontSize: 16,
height: 20 / 16,
color: Color(0xFF333333),
),
),
),
),
),
],
);
}
void _showUnbindDialog(BuildContext context) {
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext ctx) {
return AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
),
title: const Text(
'提示',
style: TextStyle(
fontSize: 17,
color: Color(0xFF000000),
),
textAlign: TextAlign.center,
),
content: const Text.rich(
TextSpan(
text: '解绑后将无法继续使用Apple账号登录该班小二账号',
style: TextStyle(color: Color(0xFF666666), fontSize: 14),
),
),
actions: [
Table(
children: [
TableRow(
children: [
TableCell(
child: TextButton(
onPressed: () {
Navigator.of(ctx).pop();
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xFF333333),
textStyle: const TextStyle(fontSize: 17),
minimumSize: const Size.fromHeight(40),
padding: EdgeInsets.zero,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
child: const Text('取消'),
),
),
TableCell(
child: TextButton(
onPressed: () {
Navigator.of(ctx).pop();
context.read<AccountAppleCubit>().unbindApple();
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xFF7691FA),
textStyle: const TextStyle(fontSize: 17),
minimumSize: const Size.fromHeight(40),
padding: EdgeInsets.zero,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
child: const Text('确定'),
),
),
],
),
],
),
],
);
},
);
}
// 未绑定/更换绑定占位视图
Widget _buildPlaceholder(BuildContext context, AccountAppleState state) {
return const Center(
child: Text(
'未绑定Apple账号',
style: TextStyle(
fontSize: 16,
color: Color(0xFF999999),
),
),
);
}
}