82 lines
2.4 KiB
Dart
82 lines
2.4 KiB
Dart
import 'dart:convert';
|
|
import 'dart:math';
|
|
|
|
import 'package:SEFER/constant/box_name.dart';
|
|
import 'package:SEFER/constant/style.dart';
|
|
import 'package:SEFER/controller/functions/location_controller.dart';
|
|
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
import '../../constant/links.dart';
|
|
import '../../main.dart';
|
|
import '../../views/widgets/mydialoug.dart';
|
|
import '../functions/crud.dart';
|
|
|
|
class RideAvailableController extends GetxController {
|
|
bool isLoading = false;
|
|
Map rideAvailableMap = {};
|
|
late LatLng southwest;
|
|
late LatLng northeast;
|
|
LatLngBounds calculateBounds(
|
|
double centerLat, double centerLng, double radius) {
|
|
// double radius = 4000; // 10 km in meters
|
|
|
|
southwest = LatLng(
|
|
centerLat - (radius / 111000),
|
|
centerLng - (radius / (111000 * cos(centerLat))),
|
|
);
|
|
|
|
northeast = LatLng(
|
|
centerLat + (radius / 111000),
|
|
centerLng + (radius / (111000 * cos(centerLat))),
|
|
);
|
|
|
|
return LatLngBounds(southwest: southwest, northeast: northeast);
|
|
}
|
|
|
|
getRideAvailable() async {
|
|
isLoading = true;
|
|
LatLngBounds bounds = calculateBounds(
|
|
Get.find<LocationController>().myLocation.latitude,
|
|
Get.find<LocationController>().myLocation.longitude,
|
|
4000);
|
|
var res = await CRUD().get(
|
|
link: AppLink.getRideWaiting,
|
|
payload: {
|
|
"carType": box.read(BoxName.carTypeOfDriver),
|
|
'southwestLat': bounds.southwest.latitude.toString(),
|
|
'southwestLon': bounds.southwest.longitude.toString(),
|
|
'northeastLat': bounds.northeast.latitude.toString(),
|
|
'northeastLon': bounds.northeast.longitude.toString(),
|
|
},
|
|
);
|
|
if (res != 'failure') {
|
|
rideAvailableMap = jsonDecode(res);
|
|
isLoading = false;
|
|
update();
|
|
} else {
|
|
MyDialog().getDialog("No Rides Available".tr, '', () {
|
|
Get.back();
|
|
Get.back();
|
|
});
|
|
// Get.defaultDialog(
|
|
// title: "No Rides Available".tr,
|
|
// middleText: '',
|
|
// titleStyle: AppStyle.title,
|
|
// confirm: MyElevatedButton(
|
|
// title: 'Ok'.tr,
|
|
// onPressed: () {
|
|
// Get.back();
|
|
// Get.back();
|
|
// }));
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
getRideAvailable();
|
|
super.onInit();
|
|
}
|
|
}
|