feat: Refactor code structure and optimize performance across multiple modules

This commit is contained in:
Achintha Isuru
2025-11-17 23:29:28 -05:00
parent 831570f2e0
commit a64cbd9edf
1508 changed files with 105319 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import 'dart:async';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/sevices/background_service/background_task.dart';
import 'package:krow/core/sevices/geofencing_serivce.dart';
import 'package:krow/features/shifts/domain/shifts_repository.dart';
class ContinuousClockoutCheckerTask implements BackgroundTask {
@override
Future<void> oneTime(ServiceInstance? service) async {
// var shift = (await getIt<ShiftsRepository>()
// .getShifts(statusFilter: ShiftStatusFilterType.ongoing)
// .onError((error, stackTrace) {
// return [];
// }))
// .firstOrNull;
//
// if (shift == null) {
// if (service is AndroidServiceInstance) {
// service.setAsBackgroundService();
// }
// return;
// } else {
// GeofencingService geofencingService = getIt<GeofencingService>();
// try {
// var permission = await geofencingService.requestGeolocationPermission();
// if (permission == GeolocationStatus.enabled) {
// var inArea = await geofencingService.isInRangeCheck(
// pointLatitude: shift.locationLat,
// pointLongitude: shift.locationLon,
// range: 500,
// );
// if (!inArea) {
// await getIt<ShiftsRepository>().forceClockOut(shift.id);
// }
// }
// } catch (e) {}
// }
}
@override
Future<void> stop() async {}
}

View File

@@ -0,0 +1,37 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/sevices/geofencing_serivce.dart';
import 'package:krow/features/shifts/domain/shift_entity.dart';
import 'package:krow/features/shifts/domain/shifts_repository.dart';
StreamSubscription? geofencingClockOutStream;
@singleton
class ForceClockoutService {
final GeofencingService geofencingService;
ForceClockoutService(this.geofencingService);
startTrackOngoingLocation(ShiftEntity shift, VoidCallback? onClockOut) {
// if (geofencingClockOutStream != null) {
// geofencingClockOutStream?.cancel();
// }
//
// geofencingClockOutStream = geofencingService
// .isInRangeStream(
// pointLatitude: shift.locationLat, pointLongitude: shift.locationLon)
// .listen(
// (isInRange) async {
// if (!isInRange) {
// await getIt<ShiftsRepository>().forceClockOut(shift.id);
// onClockOut?.call();
// geofencingClockOutStream?.cancel();
// }
// },
// );
}
}

View File

@@ -0,0 +1,52 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:krow/core/application/di/injectable.dart';
import 'package:krow/core/presentation/gen/assets.gen.dart';
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
import 'package:krow/core/presentation/widgets/ui_kit/dialogs/kw_dialog.dart';
import 'package:krow/features/shifts/domain/shift_entity.dart';
import 'package:krow/features/shifts/domain/shifts_repository.dart';
import 'package:krow/features/shifts/presentation/dialogs/complete_dialog/shift_complete_dialog.dart';
class ShiftCompleterService {
Future<void> startCompleteProcess(BuildContext context, ShiftEntity shift,
{required Null Function() onComplete, bool canSkip = true}) async {
var result = await ShiftCompleteDialog.showCustomDialog(
context,
canSkip,
shift.eventName,
shift.clockIn ?? DateTime.now(),
shift.planingBreakTime ?? 30);
if (result != null) {
if(!kDebugMode)
await getIt<ShiftsRepository>()
.completeShift(shift, result['details'], !canSkip);
if (result['result'] == true) {
await KwDialog.show(
context: context,
icon: Assets.images.icons.medalStar,
state: KwDialogState.positive,
title: 'Congratulations, Shift Completed!',
message:
'Your break has been logged and added to your timeline. Keep up the good work!',
primaryButtonLabel: 'Back to Shift');
} else {
await KwDialog.show(
context: context,
icon: Assets.images.icons.alertTriangle,
state: KwDialogState.negative,
title: 'Your Selection is under review',
message:
'Labor Code § 512 requires California employers to give unpaid lunch breaks to non-exempt employees. Lunch breaks must be uninterrupted. Employers cannot require employees to do any work while on their lunch breaks. They also cannot discourage employees from taking one. However, the employer and employee can agree to waive the meal break if the workers shift is less than 6 hours.',
child: const Text(
'Once resolved you will be notify.\nNo further Action',
textAlign: TextAlign.center,
style: AppTextStyles.bodyMediumMed,
),
primaryButtonLabel: 'Continue');
}
}
}
}