This commit is contained in:
Mohamed Nouffer
2022-06-04 20:16:29 +05:30
parent 56bb8556bb
commit eea432c3c7
8 changed files with 139 additions and 5 deletions

View File

@ -1,14 +1,18 @@
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;
@ -20,6 +24,48 @@ class DestinationController extends GetxController {
@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();
}
@ -55,11 +101,13 @@ class DestinationController extends GetxController {
Get.toNamed(AppPages.LOGIN);
}
}
void makeOrder(BuildContext context, int action_id, int order, String dir){
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();
});
}

View File

@ -1,7 +1,9 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/destination_map/destination_map_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
@ -23,6 +25,18 @@ class _DestinationPageState extends State<DestinationPage> {
final IndexController indexController = Get.find<IndexController>();
final List<int> _items = List<int>.generate(50, (int index) => index);
List<bool> isSelected = [true];
Future<void> showCurrentPosition() async {
LocationPermission permission = await Geolocator.checkPermission();
if (permission != LocationPermission.whileInUse ||
permission != LocationPermission.always) {
permission = await Geolocator.requestPermission();
}
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
indexController.rogMapController?.move(LatLng(position.latitude, position.longitude), 14);
}
Image getImage(int index){
if(destinationController.destinations[index]["location"]["properties"]["photos"] == null || destinationController.destinations[index]["location"]["properties"]["photos"] == ""){
@ -68,6 +82,25 @@ class _DestinationPageState extends State<DestinationPage> {
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
appBar:AppBar(
title: Text("Iternery"),
actions: [
ToggleButtons(
disabledColor: Colors.grey.shade200,
selectedColor: Colors.red,
children: <Widget>[
Icon(Icons.explore
)],
onPressed: (int index) {
setState(() {
isSelected[index] = !isSelected[index];
});
},
isSelected: isSelected,
),
IconButton(onPressed: (){
showCurrentPosition();
},
icon: Icon(Icons.location_on_outlined))
],
),
body: Obx(() =>
indexController.desination_mode.value == 0 ?