From 5117fbdabe8bb9212843be829d51348b5d31a418 Mon Sep 17 00:00:00 2001 From: Daniah Ayad Al-sultani <148902945+Cactuskiller@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:51:13 +0300 Subject: [PATCH] the user name of the employee is being displayed --- .../datasources/user_local_data_source.dart | 20 +++++++++++-- .../repositories/auth_repository_impl.dart | 3 ++ .../screens/attendence_screen.dart | 28 +++++++++++++++++-- .../screens/user_settings_screen.dart | 20 +++++++++++-- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/lib/data/datasources/user_local_data_source.dart b/lib/data/datasources/user_local_data_source.dart index 652cc69..41356c2 100644 --- a/lib/data/datasources/user_local_data_source.dart +++ b/lib/data/datasources/user_local_data_source.dart @@ -6,12 +6,15 @@ abstract class UserLocalDataSource { Future clearCache(); Future cacheEmployeeId(String id); Future getCachedEmployeeId(); + Future cacheFullName(String name); + Future getCachedFullName(); } class UserLocalDataSourceImpl implements UserLocalDataSource { final SharedPreferences sharedPreferences; static const String _tokenKey = 'user_token'; static const String _employeeIdKey = 'employee_id'; + static const String _fullNameKey = 'full_name'; UserLocalDataSourceImpl({required this.sharedPreferences}); @@ -26,9 +29,13 @@ class UserLocalDataSourceImpl implements UserLocalDataSource { } @override - Future clearCache() async { - await sharedPreferences.remove(_tokenKey); - await sharedPreferences.remove(_employeeIdKey); + Future cacheFullName(String name) async { + await sharedPreferences.setString(_fullNameKey, name); + } + + @override + Future getCachedFullName() async { + return sharedPreferences.getString(_fullNameKey); } @override @@ -40,4 +47,11 @@ class UserLocalDataSourceImpl implements UserLocalDataSource { Future getCachedEmployeeId() async { return sharedPreferences.getString(_employeeIdKey); } + + @override + Future clearCache() async { + await sharedPreferences.remove(_tokenKey); + await sharedPreferences.remove(_employeeIdKey); + await sharedPreferences.remove(_fullNameKey); + } } diff --git a/lib/data/repositories/auth_repository_impl.dart b/lib/data/repositories/auth_repository_impl.dart index 3e2e659..f5e3a6e 100644 --- a/lib/data/repositories/auth_repository_impl.dart +++ b/lib/data/repositories/auth_repository_impl.dart @@ -41,6 +41,9 @@ class AuthRepositoryImpl implements AuthRepository { if (responseDto.data?.employeeId != null) { print("AUTH_REPO: Caching EmployeeId: ${responseDto.data!.employeeId}"); await localDataSource.cacheEmployeeId(responseDto.data!.employeeId!); + if (responseDto.data!.fullName != null) { + await localDataSource.cacheFullName(responseDto.data!.fullName!); + } } else { print("AUTH_REPO: EmployeeId is NULL in response!"); } diff --git a/lib/presentation/screens/attendence_screen.dart b/lib/presentation/screens/attendence_screen.dart index 1f1e45a..a4366bb 100644 --- a/lib/presentation/screens/attendence_screen.dart +++ b/lib/presentation/screens/attendence_screen.dart @@ -401,9 +401,31 @@ import '../../domain/usecases/attendance_logout_usecase.dart'; import '../../data/datasources/user_local_data_source.dart'; import '../../data/datasources/attendance_remote_data_source.dart'; -class AttendanceScreen extends StatelessWidget { +class AttendanceScreen extends StatefulWidget { const AttendanceScreen({super.key}); + @override + State createState() => _AttendanceScreenState(); +} + +class _AttendanceScreenState extends State { + String _userName = ''; + + @override + void initState() { + super.initState(); + _loadUserName(); + } + + Future _loadUserName() async { + final name = await sl().getCachedFullName(); + if (mounted) { + setState(() { + _userName = name ?? 'مستخدم'; + }); + } + } + @override Widget build(BuildContext context) { final screenWidth = MediaQuery.sizeOf(context).width; @@ -449,9 +471,9 @@ class AttendanceScreen extends StatelessWidget { top: screenHeight * 0.14, left: 0, right: 0, - child: const Center( + child: Center( child: Text( - "صباح الخير, محمد", + "صباح الخير $_userName", style: TextStyle( fontSize: 24, fontWeight: FontWeight.w600, diff --git a/lib/presentation/screens/user_settings_screen.dart b/lib/presentation/screens/user_settings_screen.dart index 9054fef..46ae724 100644 --- a/lib/presentation/screens/user_settings_screen.dart +++ b/lib/presentation/screens/user_settings_screen.dart @@ -17,6 +17,22 @@ class UserSettingsScreen extends StatefulWidget { class _UserSettingsScreenState extends State { bool _notificationsOn = false; + String _userName = 'اسم الموظف'; + + @override + void initState() { + super.initState(); + _loadUserName(); + } + + Future _loadUserName() async { + final name = await sl().getCachedFullName(); + if (mounted) { + setState(() { + _userName = name ?? 'اسم الموظف'; + }); + } + } @override Widget build(BuildContext context) { @@ -84,8 +100,8 @@ class _UserSettingsScreenState extends State { const SizedBox(height: 10), /// -------------------- USER NAME -------------------- - const Text( - "اسم الموظف", + Text( + _userName, style: TextStyle( fontSize: 25, fontWeight: FontWeight.bold,