Bläddra i källkod

修改游客状态可以进入我的界面后续进行登录

刘清 1 månad sedan
förälder
incheckning
bb60f02913

+ 1
- 6
lib/presentation/navigation/app_router.dart Visa fil

@@ -32,12 +32,7 @@ class AppRouter {
32 32
         return MaterialPageRoute(builder: (_) => const ServicesScreen());
33 33
       
34 34
       case RouteConstants.profile:
35
-        return MaterialPageRoute(
36
-          builder: (_) => ProtectedRoute(
37
-            routeName: RouteConstants.profile,
38
-            child: const ProfileScreen(),
39
-          ),
40
-        );
35
+        return MaterialPageRoute(builder: (_) => const ProfileScreen());
41 36
       
42 37
       case RouteConstants.profileDetail:
43 38
         return MaterialPageRoute(

+ 0
- 7
lib/presentation/navigation/bottom_nav_bar.dart Visa fil

@@ -25,13 +25,6 @@ class _BottomNavBarState extends State<BottomNavBar> {
25 25
   }
26 26
   
27 27
   void _onItemTapped(int index) {
28
-    final authProvider = Provider.of<AuthProvider>(context, listen: false);
29
-    
30
-    // 如果点击"我的"但未登录,跳转到登录页
31
-    if (index == 3 && !authProvider.isAuthenticated) {
32
-      Navigator.of(context).pushNamed(RouteConstants.login);
33
-      return;
34
-    }
35 28
     
36 29
     setState(() {
37 30
       _selectedIndex = index;

+ 2
- 22
lib/presentation/screens/home/home_screen.dart Visa fil

@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
2 2
 import 'package:provider/provider.dart';
3 3
 import '../../navigation/bottom_nav_bar.dart';
4 4
 import '../../providers/auth_provider.dart';
5
-import '../../widgets/common/app_button.dart';
6 5
 
7 6
 class HomeScreen extends StatelessWidget {
8 7
   const HomeScreen({super.key});
@@ -42,16 +41,6 @@ class HomeScreen extends StatelessWidget {
42 41
                     children: [
43 42
                       Row(
44 43
                         children: [
45
-                          CircleAvatar(
46
-                            radius: 30,
47
-                            backgroundColor: Colors.blue[100],
48
-                            child: Icon(
49
-                              Icons.person,
50
-                              size: 30,
51
-                              color: Colors.blue,
52
-                            ),
53
-                          ),
54
-                          const SizedBox(width: 16),
55 44
                           Expanded(
56 45
                             child: Column(
57 46
                               crossAxisAlignment: CrossAxisAlignment.start,
@@ -68,7 +57,7 @@ class HomeScreen extends StatelessWidget {
68 57
                                 const SizedBox(height: 4),
69 58
                                 Text(
70 59
                                   authProvider.isAuthenticated
71
-                                      ? '欢迎回来!'
60
+                                      ? '这里会展示一些有趣的东西!'
72 61
                                       : '请登录以使用完整功能',
73 62
                                   style: TextStyle(
74 63
                                     fontSize: 14,
@@ -80,16 +69,7 @@ class HomeScreen extends StatelessWidget {
80 69
                           ),
81 70
                         ],
82 71
                       ),
83
-                      const SizedBox(height: 20),
84
-                      if (!authProvider.isAuthenticated)
85
-                        AppButton(
86
-                          text: '立即登录',
87
-                          onPressed: () {
88
-                            Navigator.of(context).pushNamed('/login');
89
-                          },
90
-                          backgroundColor: Colors.blue,
91
-                          height: 45,
92
-                        ),
72
+                      const SizedBox(height: 100),
93 73
                     ],
94 74
                   ),
95 75
                 ),

+ 264
- 196
lib/presentation/screens/profile/profile_screen.dart Visa fil

@@ -2,8 +2,8 @@ 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 8
 
9 9
 class ProfileScreen extends StatelessWidget {
@@ -50,162 +50,229 @@ class _ProfileContentState extends State<_ProfileContent> {
50 50
       body: SingleChildScrollView(
51 51
         child: Column(
52 52
           children: [
53
-            // 用户信息卡片
54
-            Card(
55
-              margin: const EdgeInsets.all(16),
56
-              shape: RoundedRectangleBorder(
57
-                borderRadius: BorderRadius.circular(16),
58
-              ),
59
-              elevation: 2,
60
-              child: Padding(
61
-                padding: const EdgeInsets.all(20),
62
-                child: Column(
63
-                  children: [
64
-                    GestureDetector(
65
-                      onTap: () {
66
-                        // 点击头像
67
-                      },
68
-                      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(
69 68
                         children: [
70 69
                           CircleAvatar(
71
-                            radius: 50,
70
+                            radius: 30,
72 71
                             backgroundColor: Colors.blue[100],
73
-                            backgroundImage: authProvider.user?.avatar != null
74
-                                ? NetworkImage(authProvider.user!.avatar!)
75
-                                : null,
76
-                            child: authProvider.user?.avatar == null
77
-                                ? const Icon(
78
-                                    Icons.person,
79
-                                    size: 60,
80
-                                    color: Colors.blue,
81
-                                  )
82
-                                : null,
72
+                            child: Icon(
73
+                              Icons.person,
74
+                              size: 30,
75
+                              color: Colors.blue,
76
+                            ),
83 77
                           ),
84
-                          Positioned(
85
-                            bottom: 0,
86
-                            right: 0,
87
-                            child: Container(
88
-                              padding: const EdgeInsets.all(6),
89
-                              decoration: BoxDecoration(
90
-                                color: Colors.blue,
91
-                                borderRadius: BorderRadius.circular(20),
92
-                                border: Border.all(
93
-                                  color: Colors.white,
94
-                                  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
+                                  ),
95 91
                                 ),
96
-                              ),
97
-                              // child: const Icon(
98
-                              //   Icons.edit,
99
-                              //   size: 16,
100
-                              //   color: Colors.white,
101
-                              // ),
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
+                              ],
102 103
                             ),
103 104
                           ),
104 105
                         ],
105 106
                       ),
106
-                    ),
107
-                    const SizedBox(height: 16),
108
-                    Text(
109
-                      authProvider.user?.fullName ?? '用户',
110
-                      style: const TextStyle(
111
-                        fontSize: 22,
112
-                        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
+                        ),
113 171
                       ),
114
-                    ),
115
-                    const SizedBox(height: 8),
116
-                    Text(
117
-                      authProvider.user?.email ?? '',
118
-                      style: TextStyle(
119
-                        fontSize: 14,
120
-                        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
+                        ),
121 179
                       ),
122
-                    ),
123
-                    if (authProvider.user?.phone != null)
124
-                      Padding(
125
-                        padding: const EdgeInsets.only(top: 4),
126
-                        child: Text(
127
-                          authProvider.user!.phone!,
128
-                          style: TextStyle(
129
-                            fontSize: 14,
130
-                            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
+                            ),
131 197
                           ),
132 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
+                        ],
133 209
                       ),
134
-                    const SizedBox(height: 16),
135
-                    Row(
136
-                      mainAxisAlignment: MainAxisAlignment.center,
137
-                      children: [
138
-                        _buildStatItem('关注', '0'),
139
-                        _buildVerticalDivider(),
140
-                        _buildStatItem('粉丝', '0'),
141
-                        _buildVerticalDivider(),
142
-                        _buildStatItem('积分', '0'),
143
-                      ],
144
-                    ),
145
-                  ],
210
+                    ],
211
+                  ),
146 212
                 ),
147 213
               ),
148
-            ),
149
-            
214
+            ],
150 215
             // 菜单项
151 216
             Padding(
152 217
               padding: const EdgeInsets.symmetric(horizontal: 16),
153 218
               child: Column(
154 219
                 children: [
155
-                  _buildMenuCard(
156
-                    title: '账户设置',
157
-                    items: [
158
-                      _buildMenuItem(
159
-                        icon: Icons.person_outline,
160
-                        title: '个人信息',
161
-                        subtitle: '查看和编辑个人信息',
162
-                        onTap: () {
163
-                          Navigator.of(context).push(
164
-                            MaterialPageRoute(
165
-                              builder: (_) => const ProfileDetailScreen(),
166
-                            ),
167
-                          );
168
-                        },
169
-                      ),
170
-                      _buildMenuItem(
171
-                        icon: Icons.lock_outline,
172
-                        title: '账号安全',
173
-                        subtitle: '修改密码和安全设置',
174
-                        onTap: () {},
175
-                      ),
176
-                      _buildMenuItem(
177
-                        icon: Icons.notifications_none,
178
-                        title: '消息通知',
179
-                        subtitle: '管理通知偏好设置',
180
-                        onTap: () {},
181
-                      ),
182
-                    ],
183
-                  ),
184
-                  const SizedBox(height: 16),
185
-                  _buildMenuCard(
186
-                    title: '我的内容',
187
-                    items: [
188
-                      _buildMenuItem(
189
-                        icon: Icons.bookmark_border,
190
-                        title: '我的收藏',
191
-                        subtitle: '查看收藏的内容',
192
-                        onTap: () {},
193
-                      ),
194
-                      _buildMenuItem(
195
-                        icon: Icons.history,
196
-                        title: '浏览历史',
197
-                        subtitle: '查看最近浏览记录',
198
-                        onTap: () {},
199
-                      ),
200
-                      _buildMenuItem(
201
-                        icon: Icons.download,
202
-                        title: '我的下载',
203
-                        subtitle: '管理下载的文件',
204
-                        onTap: () {},
205
-                      ),
206
-                    ],
207
-                  ),
208
-                  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
+                  ],
209 276
                   _buildMenuCard(
210 277
                     title: '其他',
211 278
                     items: [
@@ -221,72 +288,73 @@ class _ProfileContentState extends State<_ProfileContent> {
221 288
                         subtitle: '了解应用信息',
222 289
                         onTap: () {},
223 290
                       ),
224
-                      _buildMenuItem(
225
-                        icon: Icons.logout,
226
-                        title: '退出登录',
227
-                        subtitle: '安全退出当前账号',
228
-                        onTap: () async {
229
-                          // 防止重复点击
230
-                          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;
231 299
 
232
-                          final shouldLogout = await showDialog<bool>(
233
-                            context: context,
234
-                            builder: (context) {
235
-                              final isIOS = Theme.of(context).platform == TargetPlatform.iOS;
236
-                              
237
-                              if (isIOS) {
238
-                                // iOS风格:确定在右边,取消在左边
239
-                                return AlertDialog(
240
-                                  title: const Text('确认退出'),
241
-                                  content: const Text('确定要退出登录吗?'),
242
-                                  actionsAlignment: MainAxisAlignment.spaceBetween,
243
-                                  actions: [
244
-                                    TextButton(
245
-                                      onPressed: () => Navigator.of(context).pop(true),
246
-                                      child: const Text('确定'),
247
-                                    ),
248
-                                    TextButton(
249
-                                      onPressed: () => Navigator.of(context).pop(false),
250
-                                      child: const Text('取消'),
251
-                                    ),
252
-                                  ],
253
-                                );
254
-                              } else {
255
-                                // Android/Material风格:取消在左边,确定在右边
256
-                                return AlertDialog(
257
-                                  title: const Text('确认退出'),
258
-                                  content: const Text('确定要退出登录吗?'),
259
-                                  actionsAlignment: MainAxisAlignment.spaceBetween,
260
-                                  actions: [
261
-                                    TextButton(
262
-                                      onPressed: () => Navigator.of(context).pop(false),
263
-                                      child: const Text('取消'),
264
-                                    ),
265
-                                    TextButton(
266
-                                      onPressed: () => Navigator.of(context).pop(true),
267
-                                      child: const Text('确定'),
268
-                                    ),
269
-                                  ],
270
-                                );
271
-                              }
272
-                            },
273
-                          );
274
-                          
275
-                          if (shouldLogout == true) {
276
-                            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();
277 345
 
278
-                            // 登出后,确保在组件仍然存在时进行导航
279
-                            if (mounted) {
280
-                              // 使用pushReplacementNamed清空导航栈
281
-                              Navigator.of(context).pushReplacementNamed(RouteConstants.home);
346
+                              // 登出后,确保在组件仍然存在时进行导航
347
+                              if (mounted) {
348
+                                // 使用pushReplacementNamed清空导航栈
349
+                                Navigator.of(context).pushReplacementNamed(RouteConstants.home);
350
+                              }
282 351
                             }
283
-                          }
284
-                        },
285
-                      ),
352
+                          },
353
+                        ),
354
+                      ],
286 355
                     ],
287 356
                   ),
288 357
                   const SizedBox(height: 20),
289
-                  
290 358
                   // 版本信息
291 359
                   Padding(
292 360
                     padding: const EdgeInsets.symmetric(vertical: 20),