attendence login/logout has been implemented

This commit is contained in:
Daniah Ayad Al-sultani
2026-01-15 22:35:10 +03:00
parent 3b3ed5e640
commit 56e2c0ffaa
20 changed files with 538 additions and 200 deletions

View File

@@ -4,6 +4,12 @@ import 'package:coda_project/presentation/screens/user_settings_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../widgets/settings_bar.dart';
import '../../core/di/injection_container.dart';
import '../../domain/models/attendance_login_request.dart';
import '../../domain/models/attendance_logout_request.dart';
import '../../domain/usecases/attendance_login_usecase.dart';
import '../../domain/usecases/attendance_logout_usecase.dart';
import '../../data/datasources/user_local_data_source.dart';
class AttendanceScreen extends StatelessWidget {
const AttendanceScreen({super.key});
@@ -138,12 +144,40 @@ class AttendanceScreen extends StatelessWidget {
child: _FingerButton(
icon: "assets/images/faceLogin.svg",
label: "تسجيل الدخول",
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => OvalCameraCapturePage(isLogin: true),
),
);
onTap: () async {
final employeeId =
await sl<UserLocalDataSource>().getCachedEmployeeId();
print("ATTENDANCE_SCREEN: Retrieved EmployeeId: $employeeId");
if (employeeId == null) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('خطأ: لم يتم العثور على رقم الموظف'),
),
);
}
return;
}
if (context.mounted) {
Navigator.of(context).push(
MaterialPageRoute(
builder:
(_) => OvalCameraCapturePage(
isLogin: true,
onCapture: (imageFile) async {
final loginUseCase =
sl<AttendanceLoginUsecase>();
await loginUseCase(
AttendanceLoginRequest(
employeeId: employeeId,
faceImage: imageFile,
),
);
},
),
),
);
}
},
),
),
@@ -178,12 +212,39 @@ class AttendanceScreen extends StatelessWidget {
child: _FingerButton(
icon: "assets/images/faceLogout.svg",
label: "تسجيل خروج",
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => OvalCameraCapturePage(isLogin: false),
),
);
onTap: () async {
final employeeId =
await sl<UserLocalDataSource>().getCachedEmployeeId();
if (employeeId == null) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('خطأ: لم يتم العثور على رقم الموظف'),
),
);
}
return;
}
if (context.mounted) {
Navigator.of(context).push(
MaterialPageRoute(
builder:
(_) => OvalCameraCapturePage(
isLogin: false,
onCapture: (imageFile) async {
final logoutUseCase =
sl<AttendanceLogoutUseCase>();
await logoutUseCase(
AttendanceLogoutRequest(
employeeId: employeeId,
faceImage: imageFile,
),
);
},
),
),
);
}
},
),
),

View File

@@ -2,10 +2,17 @@ import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'dart:async';
import 'dart:io';
class OvalCameraCapturePage extends StatefulWidget {
final bool isLogin;
const OvalCameraCapturePage({super.key, this.isLogin = true});
final Future<void> Function(File image) onCapture;
const OvalCameraCapturePage({
super.key,
this.isLogin = true,
required this.onCapture,
});
@override
State<OvalCameraCapturePage> createState() => _OvalCameraCapturePageState();
@@ -77,20 +84,7 @@ class _OvalCameraCapturePageState extends State<OvalCameraCapturePage> {
_errorMessage = null;
});
_timer = Timer(const Duration(seconds: 3), () {
if (mounted) {
setState(() {
_isSuccess = true;
});
// Auto-close after 2 seconds
Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
Navigator.of(context).pop();
}
});
}
});
_startScan();
} catch (e) {
if (!mounted) return;
@@ -102,6 +96,51 @@ class _OvalCameraCapturePageState extends State<OvalCameraCapturePage> {
}
}
Future<void> _startScan() async {
try {
// Simulate scanning delay
await Future.delayed(const Duration(seconds: 2));
if (!mounted ||
_cameraController == null ||
!_cameraController!.value.isInitialized) {
return;
}
final xFile = await _cameraController!.takePicture();
final file = File(xFile.path);
await widget.onCapture(file);
if (mounted) {
setState(() {
_isSuccess = true;
});
// Auto-close after 2 seconds
Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
Navigator.of(context).pop();
}
});
}
} catch (e) {
if (mounted) {
setState(() {
_errorMessage = e.toString(); // Show error to user
});
// Auto-close or let user retry? For now let's just show error.
// If we want to auto-close on error:
Future.delayed(const Duration(seconds: 3), () {
if (mounted) {
Navigator.of(context).pop();
}
});
}
}
}
@override
void dispose() {
_cameraController?.dispose();

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import '../widgets/app_background.dart';
import '../../widgets/floatingnavbar.dart';
import '../widgets/FloatingNavBar.dart';
import 'attendence_screen.dart';
import 'finance_screen.dart';
import 'holiday_screen.dart';
@@ -15,20 +15,17 @@ class MainPage extends StatefulWidget {
class _MainPageState extends State<MainPage> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.sizeOf(context).height;
// final screenHeight = MediaQuery.sizeOf(context).height;
return Scaffold(
body: Stack(
children: [
/// BACKGROUND
const AppBackground(child: SizedBox()),
/// ACTIVE SCREEN (fills entire screen - content will extend behind navbar)
///
///
Positioned.fill(
child: IndexedStack(
index: _currentIndex,

View File

@@ -5,7 +5,8 @@ import '../widgets/settings_bar.dart';
import 'about_screen.dart';
import 'auth_screen.dart';
import '../widgets/change_password_modal.dart';
import '../../core/di/injection_container.dart';
import '../../data/datasources/user_local_data_source.dart';
class UserSettingsScreen extends StatefulWidget {
const UserSettingsScreen({super.key});
@@ -143,8 +144,8 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
duration: const Duration(
milliseconds: 250,
),
width: 75,
height: 30,
width: 75,
height: 30,
padding: const EdgeInsets.symmetric(
horizontal: 4,
),
@@ -227,13 +228,18 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
_settingsRow(
label: "تسجيل خروج",
icon: "assets/images/logout2.svg",
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const AuthScreen(),
),
);
onTap: () async {
await sl<UserLocalDataSource>()
.clearCache();
if (context.mounted) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (_) => const AuthScreen(),
),
(route) => false,
);
}
},
),
],

View File

@@ -123,135 +123,143 @@ class _AuthFormState extends State<AuthForm> {
textDirection: TextDirection.rtl,
child: FocusScope(
child: Stack(
alignment: Alignment.center,
children: [
// Border container - decorative element behind the form
Container(
width: borderWidth,
constraints: BoxConstraints(
minHeight: formHeight + 40,
maxHeight:
formHeight + 80, // Allows shrinking when keyboard opens
alignment: Alignment.center,
children: [
// Border container - decorative element behind the form
Container(
width: borderWidth,
constraints: BoxConstraints(
minHeight: formHeight + 40,
maxHeight:
formHeight + 80, // Allows shrinking when keyboard opens
),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(32),
border: Border.all(color: const Color(0xDD00C28E), width: 1),
),
),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(32),
border: Border.all(color: const Color(0xDD00C28E), width: 1),
),
),
// Main form container
Container(
width: formWidth,
padding: EdgeInsets.symmetric(
horizontal: horizontalPadding,
vertical: verticalPadding,
),
decoration: BoxDecoration(
color: const Color(0xFFEEFFFA),
borderRadius: BorderRadius.circular(28),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
offset: Offset(0, 5),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
/// Title
Center(
child: Text(
"تسجيل دخول",
style: TextStyle(
fontSize: titleFontSize,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
// Main form container
Container(
width: formWidth,
padding: EdgeInsets.symmetric(
horizontal: horizontalPadding,
vertical: verticalPadding,
),
decoration: BoxDecoration(
color: const Color(0xFFEEFFFA),
borderRadius: BorderRadius.circular(28),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
offset: Offset(0, 5),
),
),
SizedBox(height: verticalSpacing),
/// Phone Number Label
Align(
alignment: Alignment.centerRight,
child: Text(
"رقم الهاتف",
style: TextStyle(
fontSize: labelFontSize,
color: Colors.black87,
),
),
),
const SizedBox(height: 8),
_buildField(
controller: _phoneNumberController,
hint: "رقم الهاتف",
obscure: false,
keyboardType: TextInputType.phone,
focusNode: _phoneNumberFocusNode,
textInputAction: TextInputAction.next,
onSubmitted: (_) {
// Move focus to password field when next is pressed
FocusScope.of(context).requestFocus(_passwordFocusNode);
},
fontSize: fieldFontSize,
),
SizedBox(height: fieldSpacing),
/// Password Label
Align(
alignment: Alignment.centerRight,
child: Text(
"كلمة المرور",
style: TextStyle(
fontSize: labelFontSize,
color: Colors.black87,
),
),
),
const SizedBox(height: 8),
_buildField(
controller: _passwordController,
hint: "كلمة المرور",
obscure: _obscure,
hasEye: true,
focusNode: _passwordFocusNode,
textInputAction: TextInputAction.done,
onSubmitted: (_) => _handleLogin(),
fontSize: fieldFontSize,
),
SizedBox(height: buttonSpacing), // Responsive spacing
BlocBuilder<LoginBloc, LoginState>(
builder: (context, state) {
final isLoading = state is LoginLoading;
return Center(
child: OnboardingButton(
text: isLoading ? "جاري تسجيل الدخول..." : "تسجيل دخول",
backgroundColor: const Color.fromARGB(239, 35, 87, 74),
onPressed: isLoading ? null : _handleLogin,
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
/// Title
Center(
child: Text(
"تسجيل دخول",
style: TextStyle(
fontSize: titleFontSize,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
);
},
),
),
),
SizedBox(height: bottomSpacing),
],
SizedBox(height: verticalSpacing),
/// Phone Number Label
Align(
alignment: Alignment.centerRight,
child: Text(
"رقم الهاتف",
style: TextStyle(
fontSize: labelFontSize,
color: Colors.black87,
),
),
),
const SizedBox(height: 8),
_buildField(
controller: _phoneNumberController,
hint: "رقم الهاتف",
obscure: false,
keyboardType: TextInputType.phone,
focusNode: _phoneNumberFocusNode,
textInputAction: TextInputAction.next,
onSubmitted: (_) {
// Move focus to password field when next is pressed
FocusScope.of(context).requestFocus(_passwordFocusNode);
},
fontSize: fieldFontSize,
),
SizedBox(height: fieldSpacing),
/// Password Label
Align(
alignment: Alignment.centerRight,
child: Text(
"كلمة المرور",
style: TextStyle(
fontSize: labelFontSize,
color: Colors.black87,
),
),
),
const SizedBox(height: 8),
_buildField(
controller: _passwordController,
hint: "كلمة المرور",
obscure: _obscure,
hasEye: true,
focusNode: _passwordFocusNode,
textInputAction: TextInputAction.done,
onSubmitted: (_) => _handleLogin(),
fontSize: fieldFontSize,
),
SizedBox(height: buttonSpacing), // Responsive spacing
BlocBuilder<LoginBloc, LoginState>(
builder: (context, state) {
final isLoading = state is LoginLoading;
return Center(
child: OnboardingButton(
text:
isLoading
? "جاري تسجيل الدخول..."
: "تسجيل دخول",
backgroundColor: const Color.fromARGB(
239,
35,
87,
74,
),
onPressed: isLoading ? null : _handleLogin,
),
);
},
),
SizedBox(height: bottomSpacing),
],
),
),
),
],
],
),
),
),
),
);
}