updated permission

This commit is contained in:
Mohamed Nouffer
2023-07-07 16:16:56 +05:30
parent 64857d8a8b
commit 8e57515eaf

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:rogapp/routes/app_pages.dart'; import 'package:rogapp/routes/app_pages.dart';
import 'dart:io';
class PermissionHandlerScreen extends StatefulWidget { class PermissionHandlerScreen extends StatefulWidget {
PermissionHandlerScreen({Key? key}) : super(key: key); PermissionHandlerScreen({Key? key}) : super(key: key);
@ -87,18 +88,17 @@ class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
].request(); ].request();
if (statuses[Permission.location]!.isPermanentlyDenied) { if (statuses[Permission.location]!.isPermanentlyDenied) {
_showMyDialog(); await openAppSettings().then(
// await openAppSettings().then( (value) async {
// (value) async { if (value) {
// if (value) { if (await Permission.location.status.isPermanentlyDenied == true &&
// if (await Permission.location.status.isPermanentlyDenied == true && await Permission.location.status.isGranted == false) {
// await Permission.location.status.isGranted == false) { // openAppSettings();
// // openAppSettings(); permissionServiceCall(); /* opens app settings until permission is granted */
// permissionServiceCall(); /* opens app settings until permission is granted */ }
// } }
// } },
// }, );
// );
} else { } else {
if (statuses[Permission.location]!.isDenied) { if (statuses[Permission.location]!.isDenied) {
permissionServiceCall(); permissionServiceCall();
@ -110,12 +110,34 @@ class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
} }
requestPermission() async {
PermissionStatus permission = await Permission.location.status;
if (permission != PermissionStatus.granted) {
PermissionStatus newPermission = await Permission.location.request();
//showAlert(context);
if (newPermission != PermissionStatus.granted) {
// If permission not granted, handle the issue in your own way
exit(0);
}
else{
Get.toNamed(AppPages.TRAVEL);
}
}
// If permission is granted or already was granted
return true;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var status = Permission.location.status.then((value){ var status = Permission.location.status.then((value){
if(value.isGranted == false){ if(value.isGranted == false){
Future.delayed(Duration.zero, () => showAlert(context)); showAlert(context);
//requestPermission() ? Get.toNamed(AppPages.TRAVEL) : exit(0);
//Future.delayed(Duration.zero, () => showAlert(context));
} }
else { else {
Get.toNamed(AppPages.TRAVEL); Get.toNamed(AppPages.TRAVEL);
@ -145,7 +167,8 @@ class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
TextButton( TextButton(
child: const Text('わかった'), child: const Text('わかった'),
onPressed: () { onPressed: () {
permissionServiceCall(); requestPermission();
//permissionServiceCall();
}, },
), ),
], ],