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> cacheEmployeeId(String id);
Future<String?> getCachedEmployeeId();
Future<void> cacheFullName(String name);
Future<String?> 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<void> clearCache() async {
await sharedPreferences.remove(_tokenKey);
await sharedPreferences.remove(_employeeIdKey);
Future<void> cacheFullName(String name) async {
await sharedPreferences.setString(_fullNameKey, name);
}
@override
Future<String?> getCachedFullName() async {
return sharedPreferences.getString(_fullNameKey);
}
@override
@@ -40,4 +47,11 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
Future<String?> getCachedEmployeeId() async {
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) {
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!");
}

View File

@@ -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<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
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,

View File

@@ -17,6 +17,22 @@ class UserSettingsScreen extends StatefulWidget {
class _UserSettingsScreenState extends State<UserSettingsScreen> {
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
Widget build(BuildContext context) {
@@ -84,8 +100,8 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
const SizedBox(height: 10),
/// -------------------- USER NAME --------------------
const Text(
"اسم الموظف",
Text(
_userName,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,