new branch
This commit is contained in:
@@ -87,8 +87,8 @@ class RequestPermissionDialog {
|
||||
child: Text(
|
||||
appLocalization(showCupertinoDialogContext).allow_message),
|
||||
onPressed: () {
|
||||
Navigator.pop(showCupertinoDialogContext);
|
||||
AppSettings.openAppSettings(type: appSettingsType);
|
||||
Navigator.pop(showCupertinoDialogContext);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@@ -12,17 +12,20 @@ class LocationPermissionRequest {
|
||||
static LocationPermissionRequest get instance =>
|
||||
_instance ??= LocationPermissionRequest._init();
|
||||
|
||||
Future<bool> checkLocationPermission(context) async {
|
||||
var status = await Permission.location.status;
|
||||
log("Status: $status");
|
||||
if (status.isDenied || status.isPermanentlyDenied) {
|
||||
requestLocationPermisson(context, Icons.location_on_outlined,
|
||||
Permission.location, AppSettingsType.location, "Location");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Future<bool> checkLocationPermission(context) async {
|
||||
// var status = await Permission.location.status;
|
||||
// log("Status1: $status");
|
||||
// log("Status2: ${status.isDenied}");
|
||||
// log("Status3: ${status.isPermanentlyDenied}");
|
||||
// log("Status4: ${status.isGranted}");
|
||||
// if (status.isDenied || status.isPermanentlyDenied) {
|
||||
// requestLocationPermisson(context, Icons.location_on_outlined,
|
||||
// Permission.location, AppSettingsType.location, "Location");
|
||||
// return false;
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
void requestLocationPermisson(
|
||||
context,
|
||||
|
||||
@@ -43,21 +43,22 @@ class MapServices {
|
||||
List<LatLng> polylineCoordinates = [];
|
||||
PolylinePoints polylinePoints = PolylinePoints();
|
||||
|
||||
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
|
||||
ApplicationConstants.MAP_KEY,
|
||||
PointLatLng(origin.latitude, origin.longitude),
|
||||
PointLatLng(destination.latitude, destination.longitude),
|
||||
travelMode: TravelMode.driving,
|
||||
optimizeWaypoints: true);
|
||||
if (result.points.isNotEmpty) {
|
||||
for (var point in result.points) {
|
||||
polylineCoordinates.add(LatLng(point.latitude, point.longitude));
|
||||
}
|
||||
return polylineCoordinates;
|
||||
} else {
|
||||
log("Lỗi khi tìm đường");
|
||||
return [];
|
||||
}
|
||||
// PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
|
||||
// ApplicationConstants.MAP_KEY,
|
||||
// PointLatLng(origin.latitude, origin.longitude),
|
||||
// PointLatLng(destination.latitude, destination.longitude),
|
||||
// travelMode: TravelMode.driving,
|
||||
// optimizeWaypoints: true);
|
||||
// if (result.points.isNotEmpty) {
|
||||
// for (var point in result.points) {
|
||||
// polylineCoordinates.add(LatLng(point.latitude, point.longitude));
|
||||
// }
|
||||
// return polylineCoordinates;
|
||||
// } else {
|
||||
// log("Lỗi khi tìm đường");
|
||||
// return [];
|
||||
// }
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,9 @@ class NotificationServices {
|
||||
}
|
||||
|
||||
Future<String> getDeviceToken() async {
|
||||
String? token = await messaging.getToken();
|
||||
print("GET FB TOKEN");
|
||||
String? token = await messaging.getAPNSToken();
|
||||
print("GET FB: ${token}");
|
||||
return token!;
|
||||
}
|
||||
|
||||
@@ -50,6 +52,9 @@ class NotificationServices {
|
||||
}
|
||||
|
||||
Future<void> showNotification(RemoteMessage message) async {
|
||||
dev.log(message.toString());
|
||||
dev.log(message.data.toString());
|
||||
dev.log(message.data["notification"].toString());
|
||||
String? title = message.data['title'];
|
||||
String? body = message.data['body'];
|
||||
String type = message.data['type'] ?? "normal";
|
||||
|
||||
62
lib/product/utils/permission_handler.dart
Normal file
62
lib/product/utils/permission_handler.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
/// Kiểm tra xem dịch vụ vị trí có được bật không
|
||||
Future<bool> isLocationServiceEnabled() async {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
print('Vui lòng bật dịch vụ vị trí');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Kiểm tra và yêu cầu quyền truy cập vị trí
|
||||
Future<LocationPermission> checkAndRequestPermission() async {
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
print('Quyền truy cập vị trí bị từ chối');
|
||||
return permission;
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
print('Quyền truy cập vị trí bị từ chối vĩnh viễn. Vui lòng cấp quyền trong cài đặt.');
|
||||
return permission;
|
||||
}
|
||||
|
||||
return permission;
|
||||
}
|
||||
|
||||
/// Lấy vị trí hiện tại của người dùng
|
||||
Future<Position?> getCurrentPosition() async {
|
||||
try {
|
||||
Position position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high,
|
||||
);
|
||||
print('Vị trí hiện tại: ${position.latitude}, ${position.longitude}');
|
||||
return position;
|
||||
} catch (e) {
|
||||
print('Lỗi khi lấy vị trí: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Hàm chính để xử lý toàn bộ quy trình yêu cầu vị trí
|
||||
Future<void> requestLocationPermission() async {
|
||||
// Bước 1: Kiểm tra dịch vụ vị trí
|
||||
bool isServiceEnabled = await isLocationServiceEnabled();
|
||||
if (!isServiceEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bước 2: Kiểm tra và yêu cầu quyền
|
||||
LocationPermission permission = await checkAndRequestPermission();
|
||||
|
||||
// Bước 3: Nếu quyền được cấp, lấy vị trí
|
||||
if (permission == LocationPermission.whileInUse || permission == LocationPermission.always) {
|
||||
await getCurrentPosition();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user