99 lines
3.2 KiB
Dart
99 lines
3.2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:SEFER/views/widgets/mydialoug.dart';
|
|
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:location/location.dart';
|
|
// import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import '../../constant/box_name.dart';
|
|
import '../../main.dart';
|
|
import '../../print.dart';
|
|
import '../auth/captin/login_captin_controller.dart';
|
|
|
|
Future<void> getPermissionOverlay() async {
|
|
if (Platform.isAndroid) {
|
|
final bool status = await FlutterOverlayWindow.isPermissionGranted();
|
|
if (status == false) {
|
|
MyDialog().getDialog(
|
|
'Allow overlay permission'.tr,
|
|
'To display orders instantly, please grant permission to draw over other apps.'
|
|
.tr,
|
|
() async {
|
|
Get.back();
|
|
await FlutterOverlayWindow.requestPermission();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Future<void> getPermissionLocation() async {
|
|
// // final PermissionStatus status = await Permission.location.status;
|
|
// // if (!status.isGranted) {
|
|
// // Log.print('status.isGranted: ${status.isGranted}');
|
|
// // // box.write(BoxName.locationPermission, 'true');
|
|
// // await Permission.location.request();
|
|
// // Get.find<LoginDriverController>().update();
|
|
// // MyDialog().getDialog(
|
|
// // 'Enable Location Permission'.tr, // {en:ar}
|
|
// // 'Allowing location access will help us display orders near you. Please enable it now.'
|
|
// // .tr, // {en:ar}
|
|
// // () async {
|
|
// // Get.back();
|
|
// // box.write(BoxName.locationPermission, 'true');
|
|
// // await Permission.location.request();
|
|
// // },
|
|
// // );
|
|
// // }
|
|
// }
|
|
final location = Location();
|
|
Future<void> getLocationPermission() async {
|
|
bool serviceEnabled;
|
|
PermissionStatus permissionGranted;
|
|
|
|
// Check if location services are enabled
|
|
serviceEnabled = await location.serviceEnabled();
|
|
if (!serviceEnabled) {
|
|
serviceEnabled = await location.requestService();
|
|
if (!serviceEnabled) {
|
|
// Location services are still not enabled, handle the error
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Check if the app has permission to access location
|
|
permissionGranted = await location.hasPermission();
|
|
if (permissionGranted == PermissionStatus.denied) {
|
|
permissionGranted = await location.requestPermission();
|
|
if (permissionGranted != PermissionStatus.granted) {
|
|
// Location permission is still not granted, handle the error
|
|
permissionGranted = await location.requestPermission();
|
|
return;
|
|
}
|
|
}
|
|
if (permissionGranted.toString() == 'PermissionStatus.granted') {
|
|
box.write(BoxName.locationPermission, 'true');
|
|
Get.find<LoginDriverController>().update();
|
|
}
|
|
// update();
|
|
}
|
|
|
|
Future<void> getOverLay(String myListString) async {
|
|
bool isOverlayActive = await FlutterOverlayWindow.isActive();
|
|
if (isOverlayActive) {
|
|
await FlutterOverlayWindow.closeOverlay();
|
|
}
|
|
await FlutterOverlayWindow.showOverlay(
|
|
enableDrag: true,
|
|
flag: OverlayFlag.focusPointer,
|
|
visibility: NotificationVisibility.visibilityPublic,
|
|
positionGravity: PositionGravity.auto,
|
|
height: 700,
|
|
width: WindowSize.matchParent,
|
|
startPosition: const OverlayPosition(0, -150),
|
|
);
|
|
|
|
await FlutterOverlayWindow.shareData(myListString);
|
|
}
|