Connect Flutter phone auth and Android platform
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../models/gps_coordinate.dart';
|
||||
@@ -27,6 +28,7 @@ class WorkoutController extends GetxController {
|
||||
final RxDouble liveSpeed = 0.0.obs;
|
||||
|
||||
Timer? _timer;
|
||||
Future<void> _coordinateWriteQueue = Future<void>.value();
|
||||
|
||||
// ─── التحكم في الجلسة ──────────────────────────────────────────
|
||||
|
||||
@@ -42,6 +44,7 @@ class WorkoutController extends GetxController {
|
||||
currentWorkout.value!.start();
|
||||
|
||||
liveCoordinates.clear();
|
||||
_coordinateWriteQueue = Future<void>.value();
|
||||
elapsedSeconds.value = 0;
|
||||
liveDistance.value = 0;
|
||||
liveSpeed.value = 0;
|
||||
@@ -75,6 +78,7 @@ class WorkoutController extends GetxController {
|
||||
|
||||
await _gps.stopTracking();
|
||||
_timer?.cancel();
|
||||
await _coordinateWriteQueue;
|
||||
|
||||
final workout = currentWorkout.value!;
|
||||
workout.stop();
|
||||
@@ -101,7 +105,12 @@ class WorkoutController extends GetxController {
|
||||
await _sync.queueWorkout(workout);
|
||||
|
||||
currentWorkout.value = null;
|
||||
Get.snackbar("تم الحفظ", "تم حفظ التمرين بنجاح وجاري المزامنة...");
|
||||
Get.snackbar(
|
||||
"تم الحفظ",
|
||||
workout.coordinates.length >= 2
|
||||
? "تم حفظ التمرين محليًا وجاري المزامنة عند توفر الاتصال."
|
||||
: "حُفظ النشاط على الجهاز؛ لم تتوفر نقاط GPS كافية لمزامنته.",
|
||||
);
|
||||
}
|
||||
|
||||
void _handleNewCoordinate(GpsCoordinate coord) {
|
||||
@@ -111,7 +120,12 @@ class WorkoutController extends GetxController {
|
||||
liveSpeed.value = coord.speed ?? 0;
|
||||
|
||||
// حفظ فوري في DB (للحماية من انهيار التطبيق)
|
||||
_db.saveCoordinate(currentWorkout.value!.id, coord);
|
||||
final workoutId = currentWorkout.value!.id;
|
||||
_coordinateWriteQueue = _coordinateWriteQueue.then((_) async {
|
||||
await _db.saveCoordinate(workoutId, coord);
|
||||
}).catchError((Object error, StackTrace stackTrace) {
|
||||
debugPrint('[TRACKING] Coordinate persistence failed: $error');
|
||||
});
|
||||
|
||||
// حساب المسافة التراكمية حياً
|
||||
if (liveCoordinates.length > 1) {
|
||||
|
||||
Reference in New Issue
Block a user