import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; import 'package:rasadyar_core/core.dart'; import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart'; import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository_imp.dart'; import 'package:rasadyar_livestock/injection/live_stock_di.dart'; import 'package:rasadyar_livestock/presentation/page/map/view.dart'; import 'package:rasadyar_livestock/presentation/page/profile/view.dart'; import 'package:rasadyar_livestock/presentation/page/request_tagging/view.dart'; import 'package:rasadyar_livestock/presentation/page/requests/view.dart'; import 'package:rasadyar_livestock/presentation/routes/app_pages.dart'; class RootLogic extends GetxController { List pages = [ MapPage(), Navigator( key: Get.nestedKey(0), initialRoute: LiveStockRoutes.requests, onGenerateRoute: (settings) { switch (settings.name) { case LiveStockRoutes.requests: return GetPageRoute(page: () => RequestsPage()); case LiveStockRoutes.requestTagging: return GetPageRoute(page: () => RequestTaggingPage()); default: return GetPageRoute(page: () => RequestsPage()); } }, ), ProfilePage(), ]; RxInt currentIndex = 0.obs; TokenStorageService tokenService = Get.find(); late StreamSubscription> connectivitySubscription; RxList connectivityResults = [].obs; @override void onInit() { super.onInit(); connectivitySubscription = Connectivity().onConnectivityChanged.listen((result) { if (result.isNotEmpty) { connectivityResults.assignAll(result); } }); /* GetIt.instance.allReady().then((value) async { await diLiveStock.get().addLocations(generateRandomPoints()); });*/ } List generateRandomPoints() { final Random random = Random(); final double centerLat = 35.824891; final double centerLon = 50.948025; final double radiusKm = 1.0; final double kmToDegLat = 1 / 111.0; // 1 km ≈ 0.009° latitude final double kmToDegLon = 1 / (111.0 * cos(centerLat * pi / 180)); // Adjust for longitude List points = []; for (int i = 0; i < 100; i++) { // Generate random angle (0 to 2π) and random radius (0 to 1 km, using sqrt for uniform distribution) double theta = random.nextDouble() * 2 * pi; double r = sqrt(random.nextDouble()) * radiusKm; // Square root for uniform distribution in circle // Convert polar coordinates to Cartesian, then to LatLng double deltaLat = r * cos(theta) * kmToDegLat; double deltaLon = r * sin(theta) * kmToDegLon; double newLat = centerLat + deltaLat; double newLon = centerLon + deltaLon; points.add(LatLng(newLat, newLon)); } return points; } @override void onReady() { // TODO: implement onReady super.onReady(); } @override void onClose() { connectivitySubscription.cancel(); super.onClose(); } void changePage(int i) => currentIndex.value = i; }