BASE: Switch From EasyLocalization To GetX Localization.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'package:customer/constant/constant.dart';
|
||||
import 'package:customer/widget/place_picker/selected_location_model.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'package:map_launcher/map_launcher.dart';
|
||||
import '../themes/show_toast_dialog.dart';
|
||||
@@ -37,7 +38,9 @@ class Utils {
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
// Permissions are denied forever, handle appropriately.
|
||||
return Future.error('Location permissions are permanently denied, we cannot request permissions.');
|
||||
return Future.error(
|
||||
'Location permissions are permanently denied, we cannot request permissions.',
|
||||
);
|
||||
}
|
||||
|
||||
// When we reach here, permissions are granted and we can
|
||||
@@ -45,12 +48,16 @@ class Utils {
|
||||
return await Geolocator.getCurrentPosition();
|
||||
}
|
||||
|
||||
static Future<String> getAddressFromCoordinates(double lat, double lng) async {
|
||||
static Future<String> getAddressFromCoordinates(
|
||||
double lat,
|
||||
double lng,
|
||||
) async {
|
||||
try {
|
||||
List<Placemark> placemarks = await placemarkFromCoordinates(lat, lng);
|
||||
if (placemarks.isNotEmpty) {
|
||||
Placemark place = placemarks.first;
|
||||
String address = "${place.name ?? ''}, ${place.subLocality ?? ''}, ${place.locality ?? ''}, ${place.administrativeArea ?? ''}, ${place.country ?? ''}";
|
||||
String address =
|
||||
"${place.name ?? ''}, ${place.subLocality ?? ''}, ${place.locality ?? ''}, ${place.administrativeArea ?? ''}, ${place.country ?? ''}";
|
||||
return address;
|
||||
}
|
||||
return "Unknown location";
|
||||
@@ -59,67 +66,122 @@ class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> redirectMap({required String name, required double latitude, required double longLatitude}) async {
|
||||
static Future<void> redirectMap({
|
||||
required String name,
|
||||
required double latitude,
|
||||
required double longLatitude,
|
||||
}) async {
|
||||
if (Constant.mapType == "google") {
|
||||
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.google);
|
||||
if (isAvailable == true) {
|
||||
await MapLauncher.showDirections(mapType: MapType.google, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
|
||||
await MapLauncher.showDirections(
|
||||
mapType: MapType.google,
|
||||
directionsMode: DirectionsMode.driving,
|
||||
destinationTitle: name,
|
||||
destination: Coords(latitude, longLatitude),
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("Google map is not installed".tr());
|
||||
ShowToastDialog.showToast("Google map is not installed".tr);
|
||||
}
|
||||
} else if (Constant.mapType == "googleGo") {
|
||||
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.googleGo);
|
||||
if (isAvailable == true) {
|
||||
await MapLauncher.showDirections(mapType: MapType.googleGo, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
|
||||
await MapLauncher.showDirections(
|
||||
mapType: MapType.googleGo,
|
||||
directionsMode: DirectionsMode.driving,
|
||||
destinationTitle: name,
|
||||
destination: Coords(latitude, longLatitude),
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("Google Go map is not installed".tr());
|
||||
ShowToastDialog.showToast("Google Go map is not installed".tr);
|
||||
}
|
||||
} else if (Constant.mapType == "waze") {
|
||||
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.waze);
|
||||
if (isAvailable == true) {
|
||||
await MapLauncher.showDirections(mapType: MapType.waze, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
|
||||
await MapLauncher.showDirections(
|
||||
mapType: MapType.waze,
|
||||
directionsMode: DirectionsMode.driving,
|
||||
destinationTitle: name,
|
||||
destination: Coords(latitude, longLatitude),
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("Waze is not installed".tr());
|
||||
ShowToastDialog.showToast("Waze is not installed".tr);
|
||||
}
|
||||
} else if (Constant.mapType == "mapswithme") {
|
||||
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.mapswithme);
|
||||
if (isAvailable == true) {
|
||||
await MapLauncher.showDirections(mapType: MapType.mapswithme, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
|
||||
await MapLauncher.showDirections(
|
||||
mapType: MapType.mapswithme,
|
||||
directionsMode: DirectionsMode.driving,
|
||||
destinationTitle: name,
|
||||
destination: Coords(latitude, longLatitude),
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("Mapswithme is not installed".tr());
|
||||
ShowToastDialog.showToast("Mapswithme is not installed".tr);
|
||||
}
|
||||
} else if (Constant.mapType == "yandexNavi") {
|
||||
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.yandexNavi);
|
||||
if (isAvailable == true) {
|
||||
await MapLauncher.showDirections(mapType: MapType.yandexNavi, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
|
||||
await MapLauncher.showDirections(
|
||||
mapType: MapType.yandexNavi,
|
||||
directionsMode: DirectionsMode.driving,
|
||||
destinationTitle: name,
|
||||
destination: Coords(latitude, longLatitude),
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("YandexNavi is not installed".tr());
|
||||
ShowToastDialog.showToast("YandexNavi is not installed".tr);
|
||||
}
|
||||
} else if (Constant.mapType == "yandexMaps") {
|
||||
bool? isAvailable = await MapLauncher.isMapAvailable(MapType.yandexMaps);
|
||||
if (isAvailable == true) {
|
||||
await MapLauncher.showDirections(mapType: MapType.yandexMaps, directionsMode: DirectionsMode.driving, destinationTitle: name, destination: Coords(latitude, longLatitude));
|
||||
await MapLauncher.showDirections(
|
||||
mapType: MapType.yandexMaps,
|
||||
directionsMode: DirectionsMode.driving,
|
||||
destinationTitle: name,
|
||||
destination: Coords(latitude, longLatitude),
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("yandexMaps map is not installed".tr());
|
||||
ShowToastDialog.showToast("yandexMaps map is not installed".tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String formatAddress({required SelectedLocationModel selectedLocation}) {
|
||||
static String formatAddress({
|
||||
required SelectedLocationModel selectedLocation,
|
||||
}) {
|
||||
List<String> parts = [];
|
||||
|
||||
if (selectedLocation.address!.name != null && selectedLocation.address!.name!.isNotEmpty) parts.add(selectedLocation.address!.name!);
|
||||
if (selectedLocation.address!.subThoroughfare != null && selectedLocation.address!.subThoroughfare!.isNotEmpty) parts.add(selectedLocation.address!.subThoroughfare!);
|
||||
if (selectedLocation.address!.thoroughfare != null && selectedLocation.address!.thoroughfare!.isNotEmpty) parts.add(selectedLocation.address!.thoroughfare!);
|
||||
if (selectedLocation.address!.subLocality != null && selectedLocation.address!.subLocality!.isNotEmpty) parts.add(selectedLocation.address!.subLocality!);
|
||||
if (selectedLocation.address!.locality != null && selectedLocation.address!.locality!.isNotEmpty) parts.add(selectedLocation.address!.locality!);
|
||||
if (selectedLocation.address!.subAdministrativeArea != null && selectedLocation.address!.subAdministrativeArea!.isNotEmpty) {
|
||||
if (selectedLocation.address!.name != null &&
|
||||
selectedLocation.address!.name!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.name!);
|
||||
if (selectedLocation.address!.subThoroughfare != null &&
|
||||
selectedLocation.address!.subThoroughfare!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.subThoroughfare!);
|
||||
if (selectedLocation.address!.thoroughfare != null &&
|
||||
selectedLocation.address!.thoroughfare!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.thoroughfare!);
|
||||
if (selectedLocation.address!.subLocality != null &&
|
||||
selectedLocation.address!.subLocality!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.subLocality!);
|
||||
if (selectedLocation.address!.locality != null &&
|
||||
selectedLocation.address!.locality!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.locality!);
|
||||
if (selectedLocation.address!.subAdministrativeArea != null &&
|
||||
selectedLocation.address!.subAdministrativeArea!.isNotEmpty) {
|
||||
parts.add(selectedLocation.address!.subAdministrativeArea!);
|
||||
}
|
||||
if (selectedLocation.address!.administrativeArea != null && selectedLocation.address!.administrativeArea!.isNotEmpty) parts.add(selectedLocation.address!.administrativeArea!);
|
||||
if (selectedLocation.address!.postalCode != null && selectedLocation.address!.postalCode!.isNotEmpty) parts.add(selectedLocation.address!.postalCode!);
|
||||
if (selectedLocation.address!.country != null && selectedLocation.address!.country!.isNotEmpty) parts.add(selectedLocation.address!.country!);
|
||||
if (selectedLocation.address!.isoCountryCode != null && selectedLocation.address!.isoCountryCode!.isNotEmpty) parts.add(selectedLocation.address!.isoCountryCode!);
|
||||
if (selectedLocation.address!.administrativeArea != null &&
|
||||
selectedLocation.address!.administrativeArea!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.administrativeArea!);
|
||||
if (selectedLocation.address!.postalCode != null &&
|
||||
selectedLocation.address!.postalCode!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.postalCode!);
|
||||
if (selectedLocation.address!.country != null &&
|
||||
selectedLocation.address!.country!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.country!);
|
||||
if (selectedLocation.address!.isoCountryCode != null &&
|
||||
selectedLocation.address!.isoCountryCode!.isNotEmpty)
|
||||
parts.add(selectedLocation.address!.isoCountryCode!);
|
||||
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user