attendence login/logout has been implemented
This commit is contained in:
@@ -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,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user