115 lines
3.5 KiB
Dart
115 lines
3.5 KiB
Dart
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:rogapp/pages/index/index_controller.dart';
|
|
import 'package:rogapp/routes/app_pages.dart';
|
|
import 'package:rogapp/services/destination_service.dart';
|
|
import 'package:rogapp/services/maxtrix_service.dart';
|
|
import 'dart:async';
|
|
|
|
class DestinationController extends GetxController {
|
|
|
|
late LocationSettings locationSettings;
|
|
|
|
List<dynamic> destinations = <dynamic>[].obs;
|
|
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
|
|
|
|
Map<String, dynamic> matrix = {};
|
|
|
|
final IndexController indexController = Get.find<IndexController>();
|
|
|
|
@override
|
|
void onInit() {
|
|
PopulateDestinations();
|
|
|
|
|
|
|
|
|
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
|
locationSettings = AndroidSettings(
|
|
accuracy: LocationAccuracy.high,
|
|
distanceFilter: 1,
|
|
forceLocationManager: true,
|
|
intervalDuration: const Duration(seconds: 10),
|
|
//(Optional) Set foreground notification config to keep the app alive
|
|
//when going to the background
|
|
foregroundNotificationConfig: const ForegroundNotificationConfig(
|
|
notificationText:
|
|
"Example app will continue to receive your location even when you aren't using it",
|
|
notificationTitle: "Running in Background",
|
|
enableWakeLock: true,
|
|
)
|
|
);
|
|
} else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
|
|
locationSettings = AppleSettings(
|
|
accuracy: LocationAccuracy.high,
|
|
activityType: ActivityType.fitness,
|
|
distanceFilter: 1,
|
|
pauseLocationUpdatesAutomatically: false,
|
|
// Only set to true if our app will be started up in the background.
|
|
showBackgroundLocationIndicator: true
|
|
);
|
|
} else {
|
|
locationSettings = LocationSettings(
|
|
accuracy: LocationAccuracy.high,
|
|
distanceFilter: 1,
|
|
);
|
|
}
|
|
|
|
|
|
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
|
|
(Position? position) {
|
|
print(position == null ? 'Unknown' : 'current position is ${position.latitude.toString()}, ${position.longitude.toString()}');
|
|
});
|
|
|
|
|
|
super.onInit();
|
|
}
|
|
|
|
void deleteDestination(int index){
|
|
int id = destinations[index]["id"];
|
|
DestinationService.deleteDestination(id).then((val){
|
|
destination_index_data.clear();
|
|
PopulateDestinations();
|
|
print("####### dest id : ${id}");
|
|
});
|
|
}
|
|
|
|
void PopulateDestinations(){
|
|
if(indexController.currentUser.isNotEmpty){
|
|
int user_id = indexController.currentUser[0]["user"]["id"] as int;
|
|
//print(user_id);
|
|
DestinationService.getDestinations(user_id).then((value){
|
|
|
|
MatrixService.getDestinations(value).then((mat){
|
|
print(mat);
|
|
matrix = mat;
|
|
|
|
destinations.clear();
|
|
destinations = value;
|
|
|
|
});
|
|
|
|
//var val = value[2]["location"]["id"];
|
|
//print("-----current destinations ----- ${val}");
|
|
});
|
|
}
|
|
else{
|
|
Get.toNamed(AppPages.LOGIN);
|
|
}
|
|
}
|
|
|
|
|
|
void makeOrder(int action_id, int order, String dir){
|
|
DestinationService.updateOrder(action_id, order, dir).then((value){
|
|
//print("----action value----${value}");
|
|
PopulateDestinations();
|
|
destination_index_data.clear();
|
|
});
|
|
|
|
}
|
|
|
|
} |