|
|
@@ -2,10 +2,9 @@ import 'package:flutter/material.dart';
|
|
2
|
2
|
import 'package:provider/provider.dart';
|
|
3
|
3
|
import '../../../core/constants/route_constants.dart';
|
|
4
|
4
|
import '../../providers/auth_provider.dart';
|
|
5
|
|
-import '../../providers/user_provider.dart';
|
|
6
|
5
|
import '../../navigation/bottom_nav_bar.dart';
|
|
|
6
|
+import '../../widgets/common/app_button.dart';
|
|
7
|
7
|
import 'profile_detail_screen.dart';
|
|
8
|
|
-import '../../widgets/custom/protected_widget.dart';
|
|
9
|
8
|
|
|
10
|
9
|
class ProfileScreen extends StatelessWidget {
|
|
11
|
10
|
const ProfileScreen({super.key});
|
|
|
@@ -23,19 +22,18 @@ class _ProfileContent extends StatefulWidget {
|
|
23
|
22
|
}
|
|
24
|
23
|
|
|
25
|
24
|
class _ProfileContentState extends State<_ProfileContent> {
|
|
26
|
|
- @override
|
|
27
|
|
- void initState() {
|
|
28
|
|
- super.initState();
|
|
29
|
|
- WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
30
|
|
- final userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
31
|
|
- userProvider.loadUserProfile();
|
|
32
|
|
- });
|
|
33
|
|
- }
|
|
|
25
|
+ // @override
|
|
|
26
|
+ // void initState() {
|
|
|
27
|
+ // super.initState();
|
|
|
28
|
+ // WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
29
|
+ // final userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
30
|
+ // userProvider.loadUserProfile();
|
|
|
31
|
+ // });
|
|
|
32
|
+ // }
|
|
34
|
33
|
|
|
35
|
34
|
@override
|
|
36
|
35
|
Widget build(BuildContext context) {
|
|
37
|
36
|
final authProvider = Provider.of<AuthProvider>(context);
|
|
38
|
|
- // final userProvider = Provider.of<UserProvider>(context);
|
|
39
|
37
|
|
|
40
|
38
|
return Scaffold(
|
|
41
|
39
|
appBar: AppBar(
|
|
|
@@ -52,162 +50,229 @@ class _ProfileContentState extends State<_ProfileContent> {
|
|
52
|
50
|
body: SingleChildScrollView(
|
|
53
|
51
|
child: Column(
|
|
54
|
52
|
children: [
|
|
55
|
|
- // 用户信息卡片
|
|
56
|
|
- Card(
|
|
57
|
|
- margin: const EdgeInsets.all(16),
|
|
58
|
|
- shape: RoundedRectangleBorder(
|
|
59
|
|
- borderRadius: BorderRadius.circular(16),
|
|
60
|
|
- ),
|
|
61
|
|
- elevation: 2,
|
|
62
|
|
- child: Padding(
|
|
63
|
|
- padding: const EdgeInsets.all(20),
|
|
64
|
|
- child: Column(
|
|
65
|
|
- children: [
|
|
66
|
|
- GestureDetector(
|
|
67
|
|
- onTap: () {
|
|
68
|
|
- // 点击头像
|
|
69
|
|
- },
|
|
70
|
|
- child: Stack(
|
|
|
53
|
+ if (!authProvider.isAuthenticated) ...[
|
|
|
54
|
+ // 欢迎区域
|
|
|
55
|
+ Card(
|
|
|
56
|
+ margin: const EdgeInsets.all(16),
|
|
|
57
|
+ shape: RoundedRectangleBorder(
|
|
|
58
|
+ borderRadius: BorderRadius.circular(16),
|
|
|
59
|
+ ),
|
|
|
60
|
+ // color: Colors.blue[50],
|
|
|
61
|
+ elevation: 2,
|
|
|
62
|
+ child: Padding(
|
|
|
63
|
+ padding: const EdgeInsets.all(20),
|
|
|
64
|
+ child: Column(
|
|
|
65
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
66
|
+ children: [
|
|
|
67
|
+ Row(
|
|
71
|
68
|
children: [
|
|
72
|
69
|
CircleAvatar(
|
|
73
|
|
- radius: 50,
|
|
|
70
|
+ radius: 30,
|
|
74
|
71
|
backgroundColor: Colors.blue[100],
|
|
75
|
|
- backgroundImage: authProvider.user?.avatar != null
|
|
76
|
|
- ? NetworkImage(authProvider.user!.avatar!)
|
|
77
|
|
- : null,
|
|
78
|
|
- child: authProvider.user?.avatar == null
|
|
79
|
|
- ? const Icon(
|
|
80
|
|
- Icons.person,
|
|
81
|
|
- size: 60,
|
|
82
|
|
- color: Colors.blue,
|
|
83
|
|
- )
|
|
84
|
|
- : null,
|
|
|
72
|
+ child: Icon(
|
|
|
73
|
+ Icons.person,
|
|
|
74
|
+ size: 30,
|
|
|
75
|
+ color: Colors.blue,
|
|
|
76
|
+ ),
|
|
85
|
77
|
),
|
|
86
|
|
- Positioned(
|
|
87
|
|
- bottom: 0,
|
|
88
|
|
- right: 0,
|
|
89
|
|
- child: Container(
|
|
90
|
|
- padding: const EdgeInsets.all(6),
|
|
91
|
|
- decoration: BoxDecoration(
|
|
92
|
|
- color: Colors.blue,
|
|
93
|
|
- borderRadius: BorderRadius.circular(20),
|
|
94
|
|
- border: Border.all(
|
|
95
|
|
- color: Colors.white,
|
|
96
|
|
- width: 2,
|
|
|
78
|
+ const SizedBox(width: 16),
|
|
|
79
|
+ Expanded(
|
|
|
80
|
+ child: Column(
|
|
|
81
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
82
|
+ children: [
|
|
|
83
|
+ Text(
|
|
|
84
|
+ authProvider.isAuthenticated
|
|
|
85
|
+ ? '您好,${authProvider.user?.fullName}'
|
|
|
86
|
+ : '您好,游客',
|
|
|
87
|
+ style: const TextStyle(
|
|
|
88
|
+ fontSize: 18,
|
|
|
89
|
+ fontWeight: FontWeight.bold,
|
|
|
90
|
+ ),
|
|
97
|
91
|
),
|
|
98
|
|
- ),
|
|
99
|
|
- child: const Icon(
|
|
100
|
|
- Icons.edit,
|
|
101
|
|
- size: 16,
|
|
102
|
|
- color: Colors.white,
|
|
103
|
|
- ),
|
|
|
92
|
+ const SizedBox(height: 4),
|
|
|
93
|
+ Text(
|
|
|
94
|
+ authProvider.isAuthenticated
|
|
|
95
|
+ ? '欢迎回来!'
|
|
|
96
|
+ : '请登录以使用完整功能',
|
|
|
97
|
+ style: TextStyle(
|
|
|
98
|
+ fontSize: 14,
|
|
|
99
|
+ color: Colors.grey[600],
|
|
|
100
|
+ ),
|
|
|
101
|
+ ),
|
|
|
102
|
+ ],
|
|
104
|
103
|
),
|
|
105
|
104
|
),
|
|
106
|
105
|
],
|
|
107
|
106
|
),
|
|
108
|
|
- ),
|
|
109
|
|
- const SizedBox(height: 16),
|
|
110
|
|
- Text(
|
|
111
|
|
- authProvider.user?.fullName ?? '用户',
|
|
112
|
|
- style: const TextStyle(
|
|
113
|
|
- fontSize: 22,
|
|
114
|
|
- fontWeight: FontWeight.bold,
|
|
|
107
|
+ const SizedBox(height: 20),
|
|
|
108
|
+ if (!authProvider.isAuthenticated)
|
|
|
109
|
+ AppButton(
|
|
|
110
|
+ text: '立即登录',
|
|
|
111
|
+ onPressed: () {
|
|
|
112
|
+ Navigator.of(context).pushNamed('/login');
|
|
|
113
|
+ },
|
|
|
114
|
+ backgroundColor: Colors.blue,
|
|
|
115
|
+ height: 45,
|
|
|
116
|
+ ),
|
|
|
117
|
+ ],
|
|
|
118
|
+ ),
|
|
|
119
|
+ ),
|
|
|
120
|
+ ),
|
|
|
121
|
+ ] else ...[
|
|
|
122
|
+ // 用户信息卡片
|
|
|
123
|
+ Card(
|
|
|
124
|
+ margin: const EdgeInsets.all(16),
|
|
|
125
|
+ shape: RoundedRectangleBorder(
|
|
|
126
|
+ borderRadius: BorderRadius.circular(16),
|
|
|
127
|
+ ),
|
|
|
128
|
+ // color: Colors.blue[50],
|
|
|
129
|
+ elevation: 2,
|
|
|
130
|
+ child: Padding(
|
|
|
131
|
+ padding: const EdgeInsets.all(20),
|
|
|
132
|
+ child: Column(
|
|
|
133
|
+ children: [
|
|
|
134
|
+ GestureDetector(
|
|
|
135
|
+ onTap: () {
|
|
|
136
|
+ // 点击头像
|
|
|
137
|
+ },
|
|
|
138
|
+ child: Stack(
|
|
|
139
|
+ children: [
|
|
|
140
|
+ CircleAvatar(
|
|
|
141
|
+ radius: 50,
|
|
|
142
|
+ backgroundColor: Colors.blue[100],
|
|
|
143
|
+ backgroundImage: authProvider.user?.avatar != null
|
|
|
144
|
+ ? NetworkImage(authProvider.user!.avatar!)
|
|
|
145
|
+ : null,
|
|
|
146
|
+ child: authProvider.user?.avatar == null
|
|
|
147
|
+ ? const Icon(
|
|
|
148
|
+ Icons.person,
|
|
|
149
|
+ size: 60,
|
|
|
150
|
+ color: Colors.blue,
|
|
|
151
|
+ )
|
|
|
152
|
+ : null,
|
|
|
153
|
+ ),
|
|
|
154
|
+ Positioned(
|
|
|
155
|
+ bottom: 0,
|
|
|
156
|
+ right: 0,
|
|
|
157
|
+ child: Container(
|
|
|
158
|
+ padding: const EdgeInsets.all(6),
|
|
|
159
|
+ decoration: BoxDecoration(
|
|
|
160
|
+ color: Colors.blue,
|
|
|
161
|
+ borderRadius: BorderRadius.circular(20),
|
|
|
162
|
+ border: Border.all(
|
|
|
163
|
+ color: Colors.white,
|
|
|
164
|
+ width: 2,
|
|
|
165
|
+ ),
|
|
|
166
|
+ ),
|
|
|
167
|
+ ),
|
|
|
168
|
+ ),
|
|
|
169
|
+ ],
|
|
|
170
|
+ ),
|
|
115
|
171
|
),
|
|
116
|
|
- ),
|
|
117
|
|
- const SizedBox(height: 8),
|
|
118
|
|
- Text(
|
|
119
|
|
- authProvider.user?.email ?? '',
|
|
120
|
|
- style: TextStyle(
|
|
121
|
|
- fontSize: 14,
|
|
122
|
|
- color: Colors.grey[600],
|
|
|
172
|
+ const SizedBox(height: 16),
|
|
|
173
|
+ Text(
|
|
|
174
|
+ authProvider.user?.fullName ?? '用户',
|
|
|
175
|
+ style: const TextStyle(
|
|
|
176
|
+ fontSize: 22,
|
|
|
177
|
+ fontWeight: FontWeight.bold,
|
|
|
178
|
+ ),
|
|
123
|
179
|
),
|
|
124
|
|
- ),
|
|
125
|
|
- if (authProvider.user?.phone != null)
|
|
126
|
|
- Padding(
|
|
127
|
|
- padding: const EdgeInsets.only(top: 4),
|
|
128
|
|
- child: Text(
|
|
129
|
|
- authProvider.user!.phone!,
|
|
130
|
|
- style: TextStyle(
|
|
131
|
|
- fontSize: 14,
|
|
132
|
|
- color: Colors.grey[600],
|
|
|
180
|
+ const SizedBox(height: 8),
|
|
|
181
|
+ Text(
|
|
|
182
|
+ authProvider.user?.email ?? '',
|
|
|
183
|
+ style: TextStyle(
|
|
|
184
|
+ fontSize: 14,
|
|
|
185
|
+ color: Colors.grey[600],
|
|
|
186
|
+ ),
|
|
|
187
|
+ ),
|
|
|
188
|
+ if (authProvider.user?.phone != null)
|
|
|
189
|
+ Padding(
|
|
|
190
|
+ padding: const EdgeInsets.only(top: 4),
|
|
|
191
|
+ child: Text(
|
|
|
192
|
+ authProvider.user!.phone!,
|
|
|
193
|
+ style: TextStyle(
|
|
|
194
|
+ fontSize: 14,
|
|
|
195
|
+ color: Colors.grey[600],
|
|
|
196
|
+ ),
|
|
133
|
197
|
),
|
|
134
|
198
|
),
|
|
|
199
|
+ const SizedBox(height: 16),
|
|
|
200
|
+ Row(
|
|
|
201
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
202
|
+ children: [
|
|
|
203
|
+ _buildStatItem('关注', '0'),
|
|
|
204
|
+ _buildVerticalDivider(),
|
|
|
205
|
+ _buildStatItem('粉丝', '0'),
|
|
|
206
|
+ _buildVerticalDivider(),
|
|
|
207
|
+ _buildStatItem('积分', '0'),
|
|
|
208
|
+ ],
|
|
135
|
209
|
),
|
|
136
|
|
- const SizedBox(height: 16),
|
|
137
|
|
- Row(
|
|
138
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
|
139
|
|
- children: [
|
|
140
|
|
- _buildStatItem('关注', '128'),
|
|
141
|
|
- _buildVerticalDivider(),
|
|
142
|
|
- _buildStatItem('粉丝', '256'),
|
|
143
|
|
- _buildVerticalDivider(),
|
|
144
|
|
- _buildStatItem('积分', '1024'),
|
|
145
|
|
- ],
|
|
146
|
|
- ),
|
|
147
|
|
- ],
|
|
|
210
|
+ ],
|
|
|
211
|
+ ),
|
|
148
|
212
|
),
|
|
149
|
213
|
),
|
|
150
|
|
- ),
|
|
151
|
|
-
|
|
|
214
|
+ ],
|
|
152
|
215
|
// 菜单项
|
|
153
|
216
|
Padding(
|
|
154
|
217
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
155
|
218
|
child: Column(
|
|
156
|
219
|
children: [
|
|
157
|
|
- _buildMenuCard(
|
|
158
|
|
- title: '账户设置',
|
|
159
|
|
- items: [
|
|
160
|
|
- _buildMenuItem(
|
|
161
|
|
- icon: Icons.person_outline,
|
|
162
|
|
- title: '个人信息',
|
|
163
|
|
- subtitle: '查看和编辑个人信息',
|
|
164
|
|
- onTap: () {
|
|
165
|
|
- Navigator.of(context).push(
|
|
166
|
|
- MaterialPageRoute(
|
|
167
|
|
- builder: (_) => const ProfileDetailScreen(),
|
|
168
|
|
- ),
|
|
169
|
|
- );
|
|
170
|
|
- },
|
|
171
|
|
- ),
|
|
172
|
|
- _buildMenuItem(
|
|
173
|
|
- icon: Icons.lock_outline,
|
|
174
|
|
- title: '账号安全',
|
|
175
|
|
- subtitle: '修改密码和安全设置',
|
|
176
|
|
- onTap: () {},
|
|
177
|
|
- ),
|
|
178
|
|
- _buildMenuItem(
|
|
179
|
|
- icon: Icons.notifications_none,
|
|
180
|
|
- title: '消息通知',
|
|
181
|
|
- subtitle: '管理通知偏好设置',
|
|
182
|
|
- onTap: () {},
|
|
183
|
|
- ),
|
|
184
|
|
- ],
|
|
185
|
|
- ),
|
|
186
|
|
- const SizedBox(height: 16),
|
|
187
|
|
- _buildMenuCard(
|
|
188
|
|
- title: '我的内容',
|
|
189
|
|
- items: [
|
|
190
|
|
- _buildMenuItem(
|
|
191
|
|
- icon: Icons.bookmark_border,
|
|
192
|
|
- title: '我的收藏',
|
|
193
|
|
- subtitle: '查看收藏的内容',
|
|
194
|
|
- onTap: () {},
|
|
195
|
|
- ),
|
|
196
|
|
- _buildMenuItem(
|
|
197
|
|
- icon: Icons.history,
|
|
198
|
|
- title: '浏览历史',
|
|
199
|
|
- subtitle: '查看最近浏览记录',
|
|
200
|
|
- onTap: () {},
|
|
201
|
|
- ),
|
|
202
|
|
- _buildMenuItem(
|
|
203
|
|
- icon: Icons.download,
|
|
204
|
|
- title: '我的下载',
|
|
205
|
|
- subtitle: '管理下载的文件',
|
|
206
|
|
- onTap: () {},
|
|
207
|
|
- ),
|
|
208
|
|
- ],
|
|
209
|
|
- ),
|
|
210
|
|
- const SizedBox(height: 16),
|
|
|
220
|
+ if (authProvider.isAuthenticated) ... [
|
|
|
221
|
+ _buildMenuCard(
|
|
|
222
|
+ title: '账户设置',
|
|
|
223
|
+ items: [
|
|
|
224
|
+ _buildMenuItem(
|
|
|
225
|
+ icon: Icons.person_outline,
|
|
|
226
|
+ title: '个人信息',
|
|
|
227
|
+ subtitle: '查看和编辑个人信息',
|
|
|
228
|
+ onTap: () {
|
|
|
229
|
+ Navigator.of(context).push(
|
|
|
230
|
+ MaterialPageRoute(
|
|
|
231
|
+ builder: (_) => const ProfileDetailScreen(),
|
|
|
232
|
+ ),
|
|
|
233
|
+ );
|
|
|
234
|
+ },
|
|
|
235
|
+ ),
|
|
|
236
|
+ _buildMenuItem(
|
|
|
237
|
+ icon: Icons.lock_outline,
|
|
|
238
|
+ title: '账号安全',
|
|
|
239
|
+ subtitle: '修改密码和安全设置',
|
|
|
240
|
+ onTap: () {},
|
|
|
241
|
+ ),
|
|
|
242
|
+ _buildMenuItem(
|
|
|
243
|
+ icon: Icons.notifications_none,
|
|
|
244
|
+ title: '消息通知',
|
|
|
245
|
+ subtitle: '管理通知偏好设置',
|
|
|
246
|
+ onTap: () {},
|
|
|
247
|
+ ),
|
|
|
248
|
+ ],
|
|
|
249
|
+ ),
|
|
|
250
|
+ const SizedBox(height: 16),
|
|
|
251
|
+ _buildMenuCard(
|
|
|
252
|
+ title: '我的内容',
|
|
|
253
|
+ items: [
|
|
|
254
|
+ _buildMenuItem(
|
|
|
255
|
+ icon: Icons.bookmark_border,
|
|
|
256
|
+ title: '我的收藏',
|
|
|
257
|
+ subtitle: '查看收藏的内容',
|
|
|
258
|
+ onTap: () {},
|
|
|
259
|
+ ),
|
|
|
260
|
+ _buildMenuItem(
|
|
|
261
|
+ icon: Icons.history,
|
|
|
262
|
+ title: '浏览历史',
|
|
|
263
|
+ subtitle: '查看最近浏览记录',
|
|
|
264
|
+ onTap: () {},
|
|
|
265
|
+ ),
|
|
|
266
|
+ _buildMenuItem(
|
|
|
267
|
+ icon: Icons.download,
|
|
|
268
|
+ title: '我的下载',
|
|
|
269
|
+ subtitle: '管理下载的文件',
|
|
|
270
|
+ onTap: () {},
|
|
|
271
|
+ ),
|
|
|
272
|
+ ],
|
|
|
273
|
+ ),
|
|
|
274
|
+ const SizedBox(height: 16),
|
|
|
275
|
+ ],
|
|
211
|
276
|
_buildMenuCard(
|
|
212
|
277
|
title: '其他',
|
|
213
|
278
|
items: [
|
|
|
@@ -223,72 +288,73 @@ class _ProfileContentState extends State<_ProfileContent> {
|
|
223
|
288
|
subtitle: '了解应用信息',
|
|
224
|
289
|
onTap: () {},
|
|
225
|
290
|
),
|
|
226
|
|
- _buildMenuItem(
|
|
227
|
|
- icon: Icons.logout,
|
|
228
|
|
- title: '退出登录',
|
|
229
|
|
- subtitle: '安全退出当前账号',
|
|
230
|
|
- onTap: () async {
|
|
231
|
|
- // 防止重复点击
|
|
232
|
|
- if (authProvider.isLoading) return;
|
|
|
291
|
+ if (authProvider.isAuthenticated) ... [
|
|
|
292
|
+ _buildMenuItem(
|
|
|
293
|
+ icon: Icons.logout,
|
|
|
294
|
+ title: '退出登录',
|
|
|
295
|
+ subtitle: '安全退出当前账号',
|
|
|
296
|
+ onTap: () async {
|
|
|
297
|
+ // 防止重复点击
|
|
|
298
|
+ if (authProvider.isLoading) return;
|
|
233
|
299
|
|
|
234
|
|
- final shouldLogout = await showDialog<bool>(
|
|
235
|
|
- context: context,
|
|
236
|
|
- builder: (context) {
|
|
237
|
|
- final isIOS = Theme.of(context).platform == TargetPlatform.iOS;
|
|
238
|
|
-
|
|
239
|
|
- if (isIOS) {
|
|
240
|
|
- // iOS风格:确定在右边,取消在左边
|
|
241
|
|
- return AlertDialog(
|
|
242
|
|
- title: const Text('确认退出'),
|
|
243
|
|
- content: const Text('确定要退出登录吗?'),
|
|
244
|
|
- actionsAlignment: MainAxisAlignment.spaceBetween,
|
|
245
|
|
- actions: [
|
|
246
|
|
- TextButton(
|
|
247
|
|
- onPressed: () => Navigator.of(context).pop(true),
|
|
248
|
|
- child: const Text('确定'),
|
|
249
|
|
- ),
|
|
250
|
|
- TextButton(
|
|
251
|
|
- onPressed: () => Navigator.of(context).pop(false),
|
|
252
|
|
- child: const Text('取消'),
|
|
253
|
|
- ),
|
|
254
|
|
- ],
|
|
255
|
|
- );
|
|
256
|
|
- } else {
|
|
257
|
|
- // Android/Material风格:取消在左边,确定在右边
|
|
258
|
|
- return AlertDialog(
|
|
259
|
|
- title: const Text('确认退出'),
|
|
260
|
|
- content: const Text('确定要退出登录吗?'),
|
|
261
|
|
- actionsAlignment: MainAxisAlignment.spaceBetween,
|
|
262
|
|
- actions: [
|
|
263
|
|
- TextButton(
|
|
264
|
|
- onPressed: () => Navigator.of(context).pop(false),
|
|
265
|
|
- child: const Text('取消'),
|
|
266
|
|
- ),
|
|
267
|
|
- TextButton(
|
|
268
|
|
- onPressed: () => Navigator.of(context).pop(true),
|
|
269
|
|
- child: const Text('确定'),
|
|
270
|
|
- ),
|
|
271
|
|
- ],
|
|
272
|
|
- );
|
|
273
|
|
- }
|
|
274
|
|
- },
|
|
275
|
|
- );
|
|
276
|
|
-
|
|
277
|
|
- if (shouldLogout == true) {
|
|
278
|
|
- await authProvider.logout();
|
|
|
300
|
+ final shouldLogout = await showDialog<bool>(
|
|
|
301
|
+ context: context,
|
|
|
302
|
+ builder: (context) {
|
|
|
303
|
+ final isIOS = Theme.of(context).platform == TargetPlatform.iOS;
|
|
|
304
|
+
|
|
|
305
|
+ if (isIOS) {
|
|
|
306
|
+ // iOS风格:确定在右边,取消在左边
|
|
|
307
|
+ return AlertDialog(
|
|
|
308
|
+ title: const Text('确认退出'),
|
|
|
309
|
+ content: const Text('确定要退出登录吗?'),
|
|
|
310
|
+ actionsAlignment: MainAxisAlignment.spaceBetween,
|
|
|
311
|
+ actions: [
|
|
|
312
|
+ TextButton(
|
|
|
313
|
+ onPressed: () => Navigator.of(context).pop(true),
|
|
|
314
|
+ child: const Text('确定'),
|
|
|
315
|
+ ),
|
|
|
316
|
+ TextButton(
|
|
|
317
|
+ onPressed: () => Navigator.of(context).pop(false),
|
|
|
318
|
+ child: const Text('取消'),
|
|
|
319
|
+ ),
|
|
|
320
|
+ ],
|
|
|
321
|
+ );
|
|
|
322
|
+ } else {
|
|
|
323
|
+ // Android/Material风格:取消在左边,确定在右边
|
|
|
324
|
+ return AlertDialog(
|
|
|
325
|
+ title: const Text('确认退出'),
|
|
|
326
|
+ content: const Text('确定要退出登录吗?'),
|
|
|
327
|
+ actionsAlignment: MainAxisAlignment.spaceBetween,
|
|
|
328
|
+ actions: [
|
|
|
329
|
+ TextButton(
|
|
|
330
|
+ onPressed: () => Navigator.of(context).pop(false),
|
|
|
331
|
+ child: const Text('取消'),
|
|
|
332
|
+ ),
|
|
|
333
|
+ TextButton(
|
|
|
334
|
+ onPressed: () => Navigator.of(context).pop(true),
|
|
|
335
|
+ child: const Text('确定'),
|
|
|
336
|
+ ),
|
|
|
337
|
+ ],
|
|
|
338
|
+ );
|
|
|
339
|
+ }
|
|
|
340
|
+ },
|
|
|
341
|
+ );
|
|
|
342
|
+
|
|
|
343
|
+ if (shouldLogout == true) {
|
|
|
344
|
+ await authProvider.logout();
|
|
279
|
345
|
|
|
280
|
|
- // 登出后,确保在组件仍然存在时进行导航
|
|
281
|
|
- if (mounted) {
|
|
282
|
|
- // 使用pushReplacementNamed清空导航栈
|
|
283
|
|
- Navigator.of(context).pushReplacementNamed(RouteConstants.home);
|
|
|
346
|
+ // 登出后,确保在组件仍然存在时进行导航
|
|
|
347
|
+ if (mounted) {
|
|
|
348
|
+ // 使用pushReplacementNamed清空导航栈
|
|
|
349
|
+ Navigator.of(context).pushReplacementNamed(RouteConstants.home);
|
|
|
350
|
+ }
|
|
284
|
351
|
}
|
|
285
|
|
- }
|
|
286
|
|
- },
|
|
287
|
|
- ),
|
|
|
352
|
+ },
|
|
|
353
|
+ ),
|
|
|
354
|
+ ],
|
|
288
|
355
|
],
|
|
289
|
356
|
),
|
|
290
|
357
|
const SizedBox(height: 20),
|
|
291
|
|
-
|
|
292
|
358
|
// 版本信息
|
|
293
|
359
|
Padding(
|
|
294
|
360
|
padding: const EdgeInsets.symmetric(vertical: 20),
|