location has been enabled in addition to sending the domain
This commit is contained in:
16
lib/core/config/app_urls.dart
Normal file
16
lib/core/config/app_urls.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
class AppUrls {
|
||||
static const String themeLogoBase = 'https://hrm.go.iq/Images/';
|
||||
|
||||
static String buildThemeLogoUrl(String logoFileName) {
|
||||
if (logoFileName.isEmpty) return '';
|
||||
|
||||
// If backend ever returns a full URL, keep it
|
||||
final lower = logoFileName.toLowerCase();
|
||||
if (lower.startsWith('http://') || lower.startsWith('https://')) {
|
||||
return logoFileName;
|
||||
}
|
||||
|
||||
// Encode spaces/special chars (important!)
|
||||
return themeLogoBase + Uri.encodeComponent(logoFileName);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,12 @@ import '../../domain/usecases/get_salary_summary_usecase.dart';
|
||||
import '../../domain/usecases/change_password_usecase.dart';
|
||||
import '../../presentation/blocs/login/login_bloc.dart';
|
||||
import '../../presentation/blocs/change_password/change_password_bloc.dart';
|
||||
import '../../data/datasources/theme_remote_data_source.dart';
|
||||
import '../../data/repositories/theme_repository_impl.dart';
|
||||
import '../../domain/repositories/theme_repository.dart';
|
||||
import '../../domain/usecases/get_theme_usecase.dart';
|
||||
import '../../presentation/blocs/theme/theme_cubit.dart';
|
||||
import '../location/location_service.dart';
|
||||
|
||||
final sl = GetIt.instance;
|
||||
|
||||
@@ -124,4 +130,18 @@ Future<void> initializeDependencies() async {
|
||||
|
||||
sl.registerLazySingleton(() => CreateAdvanceUseCase(repository: sl()));
|
||||
sl.registerLazySingleton(() => GetAdvancesUseCase(repository: sl()));
|
||||
|
||||
// Theme
|
||||
sl.registerLazySingleton<ThemeRemoteDataSource>(
|
||||
() => ThemeRemoteDataSourceImpl(apiClient: sl()),
|
||||
);
|
||||
|
||||
sl.registerLazySingleton<ThemeRepository>(
|
||||
() => ThemeRepositoryImpl(remote: sl()),
|
||||
);
|
||||
|
||||
sl.registerLazySingleton(() => GetThemeUseCase(sl()));
|
||||
sl.registerFactory(() => ThemeCubit(getThemeUseCase: sl()));
|
||||
|
||||
sl.registerLazySingleton<LocationService>(() => LocationService());
|
||||
}
|
||||
|
||||
24
lib/core/location/location_service.dart
Normal file
24
lib/core/location/location_service.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
class LocationService {
|
||||
Future<Position?> getCurrentPosition() async {
|
||||
// 1) service enabled?
|
||||
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) return null;
|
||||
|
||||
// 2) permission
|
||||
var permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3) get location (geolocator v13+ API)
|
||||
return Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(accuracy: LocationAccuracy.high),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,16 @@ abstract class AttendanceRemoteDataSource {
|
||||
required String employeeId,
|
||||
required File faceImage,
|
||||
bool localAuth = false,
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
});
|
||||
|
||||
Future<AttendanceResponseDto> logout({
|
||||
required String employeeId,
|
||||
required File faceImage,
|
||||
bool localAuth = false,
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
});
|
||||
|
||||
Future<List<AttendanceRecordDto>> getAttendanceRecords({
|
||||
@@ -46,12 +50,17 @@ class AttendanceRemoteDataSourceImpl implements AttendanceRemoteDataSource {
|
||||
required String employeeId,
|
||||
required File faceImage,
|
||||
bool localAuth = false,
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
}) async {
|
||||
try {
|
||||
final formData = FormData.fromMap({
|
||||
'EmployeeId': employeeId,
|
||||
'FaceImage': await MultipartFile.fromFile(faceImage.path),
|
||||
'IsAuth': localAuth.toString(),
|
||||
'Domain': 'hrm.go.iq',
|
||||
if (latitude != null) 'Latitude': latitude,
|
||||
if (longitude != null) 'Longitude': longitude,
|
||||
});
|
||||
|
||||
final response = await apiClient.post(
|
||||
@@ -112,12 +121,16 @@ class AttendanceRemoteDataSourceImpl implements AttendanceRemoteDataSource {
|
||||
required String employeeId,
|
||||
required File faceImage,
|
||||
bool localAuth = false,
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
}) async {
|
||||
try {
|
||||
final formData = FormData.fromMap({
|
||||
'EmployeeId': employeeId,
|
||||
'FaceImage': await MultipartFile.fromFile(faceImage.path),
|
||||
'IsAuth': localAuth.toString(),
|
||||
if (latitude != null) 'Latitude': latitude,
|
||||
if (longitude != null) 'Longitude': longitude,
|
||||
});
|
||||
|
||||
final response = await apiClient.post(
|
||||
|
||||
@@ -19,6 +19,8 @@ class AttendanceRepositoryImpl implements AttendanceRepository {
|
||||
employeeId: request.employeeId,
|
||||
faceImage: request.faceImage,
|
||||
localAuth: request.localAuth,
|
||||
latitude: request.latitude,
|
||||
longitude: request.longitude,
|
||||
);
|
||||
|
||||
return AttendanceResponseModel(
|
||||
@@ -36,6 +38,8 @@ class AttendanceRepositoryImpl implements AttendanceRepository {
|
||||
employeeId: request.employeeId,
|
||||
faceImage: request.faceImage,
|
||||
localAuth: request.localAuth,
|
||||
latitude: request.latitude,
|
||||
longitude: request.longitude,
|
||||
);
|
||||
|
||||
return AttendanceResponseModel(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../core/config/app_urls.dart';
|
||||
import '../../core/error/failures.dart';
|
||||
import '../../core/error/exceptions.dart';
|
||||
import '../../domain/models/theme_model.dart';
|
||||
@@ -14,7 +15,14 @@ class ThemeRepositoryImpl implements ThemeRepository {
|
||||
Future<Either<Failure, ThemeModel>> getTheme() async {
|
||||
try {
|
||||
final dto = await remote.getTheme();
|
||||
return Right(ThemeModel(name: dto.name, logo: dto.logo));
|
||||
|
||||
return Right(
|
||||
ThemeModel(
|
||||
name: dto.name,
|
||||
logo: dto.logo,
|
||||
logoUrl: AppUrls.buildThemeLogoUrl(dto.logo),
|
||||
),
|
||||
);
|
||||
} on ServerException catch (e) {
|
||||
return Left(ServerFailure(e.message));
|
||||
} catch (e) {
|
||||
|
||||
@@ -5,9 +5,15 @@ class AttendanceLoginRequest {
|
||||
final File faceImage;
|
||||
final bool localAuth;
|
||||
|
||||
// ✅ NEW
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
|
||||
AttendanceLoginRequest({
|
||||
required this.employeeId,
|
||||
required this.faceImage,
|
||||
this.localAuth = false,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,9 +5,15 @@ class AttendanceLogoutRequest {
|
||||
final File faceImage;
|
||||
final bool localAuth;
|
||||
|
||||
// ✅ NEW
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
|
||||
AttendanceLogoutRequest({
|
||||
required this.employeeId,
|
||||
required this.faceImage,
|
||||
this.localAuth = false,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
});
|
||||
}
|
||||
|
||||
8
lib/domain/models/location_payload.dart
Normal file
8
lib/domain/models/location_payload.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
class LocationPayload {
|
||||
final double lat;
|
||||
final double lng;
|
||||
|
||||
const LocationPayload({required this.lat, required this.lng});
|
||||
|
||||
Map<String, dynamic> toJson() => {'latitude': lat, 'longitude': lng};
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
class ThemeModel {
|
||||
final String name;
|
||||
final String logo; // filename or url
|
||||
final String logo;
|
||||
final String logoUrl;
|
||||
|
||||
const ThemeModel({required this.name, required this.logo});
|
||||
const ThemeModel({
|
||||
required this.name,
|
||||
required this.logo,
|
||||
required this.logoUrl,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||
|
||||
import 'core/di/injection_container.dart';
|
||||
import 'presentation/blocs/theme/theme_cubit.dart';
|
||||
import 'presentation/screens/splash_screen.dart';
|
||||
|
||||
void main() async {
|
||||
@@ -12,7 +14,12 @@ void main() async {
|
||||
// Initialize dependency injection
|
||||
await initializeDependencies();
|
||||
|
||||
runApp(const CodaApp());
|
||||
runApp(
|
||||
BlocProvider(
|
||||
create: (_) => sl<ThemeCubit>()..loadTheme(),
|
||||
child: const CodaApp(),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('CRITICAL INITIALIZATION ERROR: $e');
|
||||
// If initialization fails, show a simple error screen instead of a broken app
|
||||
|
||||
@@ -855,6 +855,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import '../widgets/settings_bar.dart';
|
||||
|
||||
import '../../core/di/injection_container.dart';
|
||||
import '../../core/location/location_service.dart';
|
||||
import '../../domain/models/attendance_login_request.dart';
|
||||
import '../../domain/models/attendance_logout_request.dart';
|
||||
import '../../domain/usecases/attendance_login_usecase.dart';
|
||||
@@ -1061,6 +1062,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
// Fetch device location
|
||||
final position =
|
||||
await sl<LocationService>().getCurrentPosition();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
final result = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
@@ -1077,6 +1084,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
|
||||
employeeId: employeeId,
|
||||
faceImage: imageFile,
|
||||
localAuth: localAuth, // ✅
|
||||
latitude: position?.latitude,
|
||||
longitude: position?.longitude,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -1170,6 +1179,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
// Fetch device location
|
||||
final position =
|
||||
await sl<LocationService>().getCurrentPosition();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
final result = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
@@ -1187,6 +1202,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> {
|
||||
employeeId: employeeId,
|
||||
faceImage: imageFile,
|
||||
localAuth: localAuth, // ✅
|
||||
latitude: position?.latitude,
|
||||
longitude: position?.longitude,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../blocs/theme/theme_cubit.dart';
|
||||
import '../blocs/theme/theme_state.dart';
|
||||
import '../widgets/app_background.dart';
|
||||
import '../widgets/auth_form.dart';
|
||||
import '../../core/di/injection_container.dart';
|
||||
@@ -19,17 +21,30 @@ class AuthScreen extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 60),
|
||||
// Logo
|
||||
// Center(child: Image.asset("assets/images/logo2.png", width: 200)),
|
||||
const Center(
|
||||
child: Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
// Dynamic Logo from backend
|
||||
Center(
|
||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThemeLoaded) {
|
||||
return Image.network(
|
||||
state.logoUrl,
|
||||
width: 62,
|
||||
height: 62,
|
||||
errorBuilder:
|
||||
(_, __, ___) =>
|
||||
const Icon(Icons.image_not_supported),
|
||||
);
|
||||
}
|
||||
return const Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 15),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'package:coda_project/presentation/screens/auth_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../blocs/theme/theme_cubit.dart';
|
||||
import '../blocs/theme/theme_state.dart';
|
||||
import '../widgets/onboarding_page.dart';
|
||||
import '../widgets/onboarding_button.dart';
|
||||
|
||||
@@ -88,15 +91,28 @@ class _OnboardingScreenState extends State<OnboardingScreen> {
|
||||
Column(
|
||||
children: [
|
||||
const SizedBox(height: 70),
|
||||
// Image.asset("assets/images/logo2.png", width: 200),
|
||||
const Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
// Dynamic Logo from backend
|
||||
BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThemeLoaded) {
|
||||
return Image.network(
|
||||
state.logoUrl,
|
||||
width: 62,
|
||||
height: 62,
|
||||
errorBuilder:
|
||||
(_, __, ___) => const Icon(Icons.image_not_supported),
|
||||
);
|
||||
}
|
||||
return const Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
/// PAGEVIEW (SVG + TEXT ONLY)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||||
import '../blocs/theme/theme_cubit.dart';
|
||||
import '../blocs/theme/theme_state.dart';
|
||||
import 'onboarding_screen.dart';
|
||||
import 'main_screen.dart';
|
||||
import '../../core/di/injection_container.dart';
|
||||
@@ -65,16 +68,28 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
// child: Center(child: Image.asset("assets/images/logo.png", width: 200)),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
child: Center(
|
||||
child: BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThemeLoaded) {
|
||||
return Image.network(
|
||||
state.logoUrl,
|
||||
width: 62,
|
||||
height: 62,
|
||||
errorBuilder:
|
||||
(_, __, ___) => const Icon(Icons.image_not_supported),
|
||||
);
|
||||
}
|
||||
return const Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import '../blocs/theme/theme_cubit.dart';
|
||||
import '../blocs/theme/theme_state.dart';
|
||||
|
||||
class SettingsBar extends StatelessWidget {
|
||||
final int selectedIndex;
|
||||
@@ -25,15 +28,28 @@ class SettingsBar extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Text Logo
|
||||
const Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
// Dynamic Logo from backend
|
||||
BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, state) {
|
||||
if (state is ThemeLoaded) {
|
||||
return Image.network(
|
||||
state.logoUrl,
|
||||
width: 62,
|
||||
height: 62,
|
||||
errorBuilder:
|
||||
(_, __, ___) => const Icon(Icons.image_not_supported),
|
||||
);
|
||||
}
|
||||
return const Text(
|
||||
'LOGO',
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 2,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user