the user name of the employee is being displayed

This commit is contained in:
Daniah Ayad Al-sultani
2026-02-17 16:51:13 +03:00
parent bb6f3931ce
commit 5117fbdabe
4 changed files with 63 additions and 8 deletions

View File

@@ -6,12 +6,15 @@ abstract class UserLocalDataSource {
Future<void> clearCache(); Future<void> clearCache();
Future<void> cacheEmployeeId(String id); Future<void> cacheEmployeeId(String id);
Future<String?> getCachedEmployeeId(); Future<String?> getCachedEmployeeId();
Future<void> cacheFullName(String name);
Future<String?> getCachedFullName();
} }
class UserLocalDataSourceImpl implements UserLocalDataSource { class UserLocalDataSourceImpl implements UserLocalDataSource {
final SharedPreferences sharedPreferences; final SharedPreferences sharedPreferences;
static const String _tokenKey = 'user_token'; static const String _tokenKey = 'user_token';
static const String _employeeIdKey = 'employee_id'; static const String _employeeIdKey = 'employee_id';
static const String _fullNameKey = 'full_name';
UserLocalDataSourceImpl({required this.sharedPreferences}); UserLocalDataSourceImpl({required this.sharedPreferences});
@@ -26,9 +29,13 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
} }
@override @override
Future<void> clearCache() async { Future<void> cacheFullName(String name) async {
await sharedPreferences.remove(_tokenKey); await sharedPreferences.setString(_fullNameKey, name);
await sharedPreferences.remove(_employeeIdKey); }
@override
Future<String?> getCachedFullName() async {
return sharedPreferences.getString(_fullNameKey);
} }
@override @override
@@ -40,4 +47,11 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
Future<String?> getCachedEmployeeId() async { Future<String?> getCachedEmployeeId() async {
return sharedPreferences.getString(_employeeIdKey); return sharedPreferences.getString(_employeeIdKey);
} }
@override
Future<void> clearCache() async {
await sharedPreferences.remove(_tokenKey);
await sharedPreferences.remove(_employeeIdKey);
await sharedPreferences.remove(_fullNameKey);
}
} }

View File

@@ -41,6 +41,9 @@ class AuthRepositoryImpl implements AuthRepository {
if (responseDto.data?.employeeId != null) { if (responseDto.data?.employeeId != null) {
print("AUTH_REPO: Caching EmployeeId: ${responseDto.data!.employeeId}"); print("AUTH_REPO: Caching EmployeeId: ${responseDto.data!.employeeId}");
await localDataSource.cacheEmployeeId(responseDto.data!.employeeId!); await localDataSource.cacheEmployeeId(responseDto.data!.employeeId!);
if (responseDto.data!.fullName != null) {
await localDataSource.cacheFullName(responseDto.data!.fullName!);
}
} else { } else {
print("AUTH_REPO: EmployeeId is NULL in response!"); print("AUTH_REPO: EmployeeId is NULL in response!");
} }

View File

@@ -401,9 +401,31 @@ import '../../domain/usecases/attendance_logout_usecase.dart';
import '../../data/datasources/user_local_data_source.dart'; import '../../data/datasources/user_local_data_source.dart';
import '../../data/datasources/attendance_remote_data_source.dart'; import '../../data/datasources/attendance_remote_data_source.dart';
class AttendanceScreen extends StatelessWidget { class AttendanceScreen extends StatefulWidget {
const AttendanceScreen({super.key}); const AttendanceScreen({super.key});
@override
State<AttendanceScreen> createState() => _AttendanceScreenState();
}
class _AttendanceScreenState extends State<AttendanceScreen> {
String _userName = '';
@override
void initState() {
super.initState();
_loadUserName();
}
Future<void> _loadUserName() async {
final name = await sl<UserLocalDataSource>().getCachedFullName();
if (mounted) {
setState(() {
_userName = name ?? 'مستخدم';
});
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenWidth = MediaQuery.sizeOf(context).width; final screenWidth = MediaQuery.sizeOf(context).width;
@@ -449,9 +471,9 @@ class AttendanceScreen extends StatelessWidget {
top: screenHeight * 0.14, top: screenHeight * 0.14,
left: 0, left: 0,
right: 0, right: 0,
child: const Center( child: Center(
child: Text( child: Text(
"صباح الخير, محمد", "صباح الخير $_userName",
style: TextStyle( style: TextStyle(
fontSize: 24, fontSize: 24,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,

View File

@@ -17,6 +17,22 @@ class UserSettingsScreen extends StatefulWidget {
class _UserSettingsScreenState extends State<UserSettingsScreen> { class _UserSettingsScreenState extends State<UserSettingsScreen> {
bool _notificationsOn = false; bool _notificationsOn = false;
String _userName = 'اسم الموظف';
@override
void initState() {
super.initState();
_loadUserName();
}
Future<void> _loadUserName() async {
final name = await sl<UserLocalDataSource>().getCachedFullName();
if (mounted) {
setState(() {
_userName = name ?? 'اسم الموظف';
});
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -84,8 +100,8 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
const SizedBox(height: 10), const SizedBox(height: 10),
/// -------------------- USER NAME -------------------- /// -------------------- USER NAME --------------------
const Text( Text(
"اسم الموظف", _userName,
style: TextStyle( style: TextStyle(
fontSize: 25, fontSize: 25,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,