feat : some changes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -10,15 +9,21 @@ import 'package:rasadyar_livestock/presentation/page/requests/view.dart';
|
||||
import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
|
||||
|
||||
class RootLogic extends GetxController {
|
||||
List<Widget> pages = [
|
||||
// Unique nested keys for each Navigator
|
||||
final List<GlobalKey<NavigatorState>> navigatorKeys = [
|
||||
?Get.nestedKey(0), // Map
|
||||
?Get.nestedKey(1), // Requests / RequestTagging
|
||||
?Get.nestedKey(2), // Profile
|
||||
];
|
||||
|
||||
List<Widget> get pages => [
|
||||
Navigator(
|
||||
key: Get.nestedKey(0),
|
||||
key: navigatorKeys[0],
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => MapPage()),
|
||||
),
|
||||
|
||||
Navigator(
|
||||
key: Get.nestedKey(1),
|
||||
initialRoute: LiveStockRoutes.requests,
|
||||
key: navigatorKeys[1],
|
||||
onGenerateRoute: (settings) {
|
||||
switch (settings.name) {
|
||||
case LiveStockRoutes.requests:
|
||||
@@ -32,7 +37,7 @@ class RootLogic extends GetxController {
|
||||
),
|
||||
|
||||
Navigator(
|
||||
key: Get.nestedKey(2),
|
||||
key: navigatorKeys[2],
|
||||
onGenerateRoute: (settings) => GetPageRoute(page: () => ProfilePage()),
|
||||
),
|
||||
];
|
||||
@@ -40,60 +45,28 @@ class RootLogic extends GetxController {
|
||||
RxInt currentIndex = 0.obs;
|
||||
TokenStorageService tokenService = Get.find<TokenStorageService>();
|
||||
|
||||
late StreamSubscription<List<ConnectivityResult>> connectivitySubscription;
|
||||
RxList<ConnectivityResult> connectivityResults = <ConnectivityResult>[].obs;
|
||||
|
||||
DateTime? lastBackPressed;
|
||||
|
||||
@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<LivestockRepositoryImp>().addLocations(generateRandomPoints());
|
||||
});*/
|
||||
}
|
||||
|
||||
List<LatLng> 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<LatLng> 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;
|
||||
void changePage(int index) {
|
||||
if (index == currentIndex.value) {
|
||||
// Optional: pop to first route if the same tab is tapped
|
||||
navigatorKeys[index].currentState?.popUntil((route) => route.isFirst);
|
||||
} else {
|
||||
currentIndex.value = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class RootPage extends GetView<RootLogic> {
|
||||
return;
|
||||
}
|
||||
final now = DateTime.now();
|
||||
if (controller.lastBackPressed == null ||
|
||||
/*if (controller.lastBackPressed == null ||
|
||||
now.difference(controller.lastBackPressed!) > const Duration(seconds: 2)) {
|
||||
controller.lastBackPressed = now;
|
||||
Get.snackbar(
|
||||
@@ -28,7 +28,7 @@ class RootPage extends GetView<RootLogic> {
|
||||
);
|
||||
} else {
|
||||
await SystemNavigator.pop();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user