@@ -7,6 +7,7 @@ import '../../../configs/constants/app_images.dart';
7
7
import '../../../configs/theme/app_theme.dart' ;
8
8
import '../../../configs/routes/routes_name.dart' ;
9
9
import '../../services/shared_prefs_service.dart' ;
10
+ import '../../providers/chat_provider.dart' ;
10
11
11
12
class ProfileScreen extends ConsumerStatefulWidget {
12
13
const ProfileScreen ({super .key});
@@ -18,6 +19,16 @@ class ProfileScreen extends ConsumerStatefulWidget {
18
19
class _ProfileScreenState extends ConsumerState <ProfileScreen > {
19
20
@override
20
21
Widget build (BuildContext context) {
22
+ final chats = ref.watch (chatProvider); // Get chats from provider
23
+
24
+ // Calculate stats
25
+ final totalChats = chats.length;
26
+ final totalMessages = chats.fold <int >(
27
+ 0 ,
28
+ (sum, chat) => sum + chat.messages.length,
29
+ );
30
+ final totalImages = 0 ; // TODO: Implement image tracking
31
+
21
32
return Scaffold (
22
33
extendBodyBehindAppBar: true ,
23
34
appBar: AppBar (
@@ -124,9 +135,9 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
124
135
Row (
125
136
mainAxisAlignment: MainAxisAlignment .spaceEvenly,
126
137
children: [
127
- _buildStatItem ('Chats' , '23' ),
128
- _buildStatItem ('Messages' , '142' ),
129
- _buildStatItem ('Images' , '15' ),
138
+ _buildStatItem ('Chats' , totalChats. toString () ),
139
+ _buildStatItem ('Messages' , totalMessages. toString () ),
140
+ _buildStatItem ('Images' , totalImages. toString () ),
130
141
],
131
142
),
132
143
const SizedBox (height: 32 ),
@@ -219,13 +230,16 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
219
230
child: const Text ('Cancel' ),
220
231
),
221
232
TextButton (
222
- onPressed: () {
223
- // TODO: Implement clear chat history
224
- Navigator .pop (context);
225
- Utils .flushBarSuccessMessage (
226
- 'Chat history cleared' ,
227
- context,
228
- );
233
+ onPressed: () async {
234
+ // Clear all chats
235
+ await ref.read (chatProvider.notifier).clearAllChats ();
236
+ if (mounted) {
237
+ Navigator .pop (context);
238
+ Utils .flushBarSuccessMessage (
239
+ 'Chat history cleared' ,
240
+ context,
241
+ );
242
+ }
229
243
},
230
244
child: const Text ('Clear' ),
231
245
),
@@ -249,12 +263,21 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
249
263
child: const Text ('Cancel' ),
250
264
),
251
265
TextButton (
252
- onPressed: () {
253
- Navigator .pushNamedAndRemoveUntil (
254
- context,
255
- RoutesName .login,
256
- (route) => false ,
257
- );
266
+ onPressed: () async {
267
+ // Clear saved user data
268
+ final currentUser = await SharedPrefsService .getSavedUsers ().then ((users) => users.firstOrNull);
269
+ if (currentUser != null ) {
270
+ await SharedPrefsService .removeSavedUser (currentUser.email);
271
+ }
272
+ // Clear chat history
273
+ await ref.read (chatProvider.notifier).clearAllChats ();
274
+ if (mounted) {
275
+ Navigator .pushNamedAndRemoveUntil (
276
+ context,
277
+ RoutesName .login,
278
+ (route) => false ,
279
+ );
280
+ }
258
281
},
259
282
child: const Text ('Logout' ),
260
283
),
@@ -326,15 +349,22 @@ class _SavedUsersSheet extends StatelessWidget {
326
349
final user = snapshot.data! [index];
327
350
return ListTile (
328
351
leading: const CircleAvatar (
329
- child: Icon (Icons .person),
352
+ backgroundColor: AppTheme .primaryColor,
353
+ child: Icon (Icons .person, color: Colors .white),
330
354
),
331
355
title: Text (user.email),
332
356
subtitle: Text (user.name ?? '' ),
333
357
trailing: IconButton (
334
358
icon: const Icon (Icons .delete),
335
359
onPressed: () async {
336
360
await SharedPrefsService .removeSavedUser (user.email);
337
- Navigator .pop (context);
361
+ if (context.mounted) {
362
+ Navigator .pop (context);
363
+ Utils .flushBarSuccessMessage (
364
+ 'User removed' ,
365
+ context,
366
+ );
367
+ }
338
368
},
339
369
),
340
370
);
0 commit comments