|
|
|
@ -1,23 +1,22 @@
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:math';
|
|
|
|
import 'dart:math';
|
|
|
|
import 'dart:ui';
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
import 'package:google_directions_api/google_directions_api.dart';
|
|
|
|
import 'package:google_directions_api/google_directions_api.dart';
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
|
|
|
|
|
|
|
import 'package:mohem_flutter_app/classes/app_permissions.dart';
|
|
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
|
|
|
|
|
|
import 'package:mohem_flutter_app/theme/colors.dart';
|
|
|
|
// import 'package:geodesy/geodesy.dart' as geodesy;
|
|
|
|
// import 'package:geodesy/geodesy.dart' as geodesy;
|
|
|
|
|
|
|
|
|
|
|
|
import '../../classes/app_permissions.dart';
|
|
|
|
|
|
|
|
import '../../theme/colors.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Created By Mr.Zohaib
|
|
|
|
//Created By Mr.Zohaib
|
|
|
|
class Location {
|
|
|
|
class Location {
|
|
|
|
static _Map map = _Map();
|
|
|
|
static _Map map = _Map();
|
|
|
|
|
|
|
|
|
|
|
|
static havePermission(Function(bool) callback) {
|
|
|
|
static void havePermission(Function(bool) callback) {
|
|
|
|
Geolocator.checkPermission().then((value) async {
|
|
|
|
Geolocator.checkPermission().then((value) async {
|
|
|
|
if (value == LocationPermission.denied) {
|
|
|
|
if (value == LocationPermission.denied) {
|
|
|
|
value = await Geolocator.requestPermission();
|
|
|
|
value = await Geolocator.requestPermission();
|
|
|
|
@ -28,13 +27,13 @@ class Location {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static isEnabled(Function(bool) callback) {
|
|
|
|
static void isEnabled(Function(bool) callback) {
|
|
|
|
Geolocator.isLocationServiceEnabled().then((value) => callback(value));
|
|
|
|
Geolocator.isLocationServiceEnabled().then((value) => callback(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool _listeningSettingChange = true;
|
|
|
|
static bool _listeningSettingChange = true;
|
|
|
|
|
|
|
|
|
|
|
|
static listenGPS({bool change = true, Function(bool)? onChange}) async {
|
|
|
|
static void listenGPS({bool change = true, Function(bool)? onChange}) async {
|
|
|
|
_listeningSettingChange = change;
|
|
|
|
_listeningSettingChange = change;
|
|
|
|
if (change == false) return;
|
|
|
|
if (change == false) return;
|
|
|
|
|
|
|
|
|
|
|
|
@ -46,8 +45,8 @@ class Location {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static getCurrentLocation(Function(LatLng?) callback) {
|
|
|
|
static void getCurrentLocation(Function(LatLng?) callback) {
|
|
|
|
done(Position position) {
|
|
|
|
void done(Position position) {
|
|
|
|
//AppStorage.sp.saveLocation(position);
|
|
|
|
//AppStorage.sp.saveLocation(position);
|
|
|
|
|
|
|
|
|
|
|
|
LatLng? myCurrentLocation = LatLng(position.latitude, position.longitude);
|
|
|
|
LatLng? myCurrentLocation = LatLng(position.latitude, position.longitude);
|
|
|
|
@ -55,8 +54,7 @@ class Location {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AppPermissions.location((granted) {
|
|
|
|
AppPermissions.location((granted) {
|
|
|
|
|
|
|
|
if (granted) {
|
|
|
|
if (granted)
|
|
|
|
|
|
|
|
Geolocator.getLastKnownPosition(forceAndroidLocationManager: true).then((value) {
|
|
|
|
Geolocator.getLastKnownPosition(forceAndroidLocationManager: true).then((value) {
|
|
|
|
if (value == null) {
|
|
|
|
if (value == null) {
|
|
|
|
Geolocator.getCurrentPosition().then((value) {
|
|
|
|
Geolocator.getCurrentPosition().then((value) {
|
|
|
|
@ -66,6 +64,7 @@ class Location {
|
|
|
|
done(value);
|
|
|
|
done(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -125,20 +124,20 @@ class _Map {
|
|
|
|
return camera;
|
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
moveCamera(CameraPosition camera, @required Completer<GoogleMapController> mapController, bool animation) {
|
|
|
|
void moveCamera(CameraPosition camera, @required Completer<GoogleMapController> mapController, bool animation) {
|
|
|
|
mapController.future.then((controller) {
|
|
|
|
mapController.future.then((controller) {
|
|
|
|
animation ? controller.animateCamera(CameraUpdate.newCameraPosition(camera)) : controller.moveCamera(CameraUpdate.newCameraPosition(camera));
|
|
|
|
animation ? controller.animateCamera(CameraUpdate.newCameraPosition(camera)) : controller.moveCamera(CameraUpdate.newCameraPosition(camera));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
scrollBy({double x = 0, double y = 0, required Completer<GoogleMapController> mapController, bool animation = true}) {
|
|
|
|
void scrollBy({double x = 0, double y = 0, required Completer<GoogleMapController> mapController, bool animation = true}) {
|
|
|
|
var camera = CameraUpdate.scrollBy(x, y);
|
|
|
|
var camera = CameraUpdate.scrollBy(x, y);
|
|
|
|
mapController.future.then((controller) {
|
|
|
|
mapController.future.then((controller) {
|
|
|
|
animation ? controller.animateCamera(camera) : controller.moveCamera(camera);
|
|
|
|
animation ? controller.animateCamera(camera) : controller.moveCamera(camera);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
goToCurrentLocation({Completer<GoogleMapController>? mapController, double? direction = 0.0, bool? animation}) {
|
|
|
|
void goToCurrentLocation({Completer<GoogleMapController>? mapController, double? direction = 0.0, bool? animation}) {
|
|
|
|
Location.getCurrentLocation((location) {
|
|
|
|
Location.getCurrentLocation((location) {
|
|
|
|
moveTo(location!, zoom: 17, mapController: mapController!, animation: animation, direction: direction!);
|
|
|
|
moveTo(location!, zoom: 17, mapController: mapController!, animation: animation, direction: direction!);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -146,7 +145,7 @@ class _Map {
|
|
|
|
|
|
|
|
|
|
|
|
var routes = Map<String, DirectionsRoute>();
|
|
|
|
var routes = Map<String, DirectionsRoute>();
|
|
|
|
|
|
|
|
|
|
|
|
setRoutePolylines(LatLng? source, LatLng? destination, Set<Polyline> polylines, Completer<GoogleMapController> mapController, Function(DirectionsRoute?) completion) {
|
|
|
|
void setRoutePolylines(LatLng? source, LatLng? destination, Set<Polyline> polylines, Completer<GoogleMapController> mapController, Function(DirectionsRoute?) completion) {
|
|
|
|
if (source == null || destination == null) {
|
|
|
|
if (source == null || destination == null) {
|
|
|
|
completion(null);
|
|
|
|
completion(null);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -156,7 +155,7 @@ class _Map {
|
|
|
|
var destin = '${destination.latitude},${destination.longitude}';
|
|
|
|
var destin = '${destination.latitude},${destination.longitude}';
|
|
|
|
var routeId = '$origin->$destination';
|
|
|
|
var routeId = '$origin->$destination';
|
|
|
|
|
|
|
|
|
|
|
|
createPolyline(DirectionsRoute results) {
|
|
|
|
void createPolyline(DirectionsRoute results) {
|
|
|
|
List<LatLng> polylineCoordinates = results.overviewPath!.map((e) => LatLng(e.latitude, e.longitude)).toList();
|
|
|
|
List<LatLng> polylineCoordinates = results.overviewPath!.map((e) => LatLng(e.latitude, e.longitude)).toList();
|
|
|
|
PolylineId id = PolylineId("route");
|
|
|
|
PolylineId id = PolylineId("route");
|
|
|
|
Polyline polyline = Polyline(
|
|
|
|
Polyline polyline = Polyline(
|
|
|
|
@ -221,7 +220,7 @@ class _Map {
|
|
|
|
return LatLngBounds(northeast: LatLng(x1!, y1!), southwest: LatLng(x0!, y0!));
|
|
|
|
return LatLngBounds(northeast: LatLng(x1!, y1!), southwest: LatLng(x0!, y0!));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
focusCameraToLatLngBounds({LatLngBounds? bound, Completer<GoogleMapController>? mapController, double? padding}) async {
|
|
|
|
void focusCameraToLatLngBounds({LatLngBounds? bound, Completer<GoogleMapController>? mapController, double? padding}) async {
|
|
|
|
if (bound == null) return;
|
|
|
|
if (bound == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
CameraUpdate camera = CameraUpdate.newLatLngBounds(bound, padding!);
|
|
|
|
CameraUpdate camera = CameraUpdate.newLatLngBounds(bound, padding!);
|
|
|
|
@ -229,7 +228,7 @@ class _Map {
|
|
|
|
controller.animateCamera(camera);
|
|
|
|
controller.animateCamera(camera);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
focusCameraTo2Points({LatLng? point1, LatLng? point2, Completer<GoogleMapController>? mapController, double? padding}) async {
|
|
|
|
void focusCameraTo2Points({LatLng? point1, LatLng? point2, Completer<GoogleMapController>? mapController, double? padding}) async {
|
|
|
|
var source = point1;
|
|
|
|
var source = point1;
|
|
|
|
var destination = point2;
|
|
|
|
var destination = point2;
|
|
|
|
if (source != null && destination != null) {
|
|
|
|
if (source != null && destination != null) {
|
|
|
|
|