78 lines
2.0 KiB
Dart
78 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:rogapp/routes/app_pages.dart';
|
|
|
|
class PermissionHandlerScreen extends StatefulWidget {
|
|
const PermissionHandlerScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_PermissionHandlerScreenState createState() =>
|
|
_PermissionHandlerScreenState();
|
|
}
|
|
|
|
class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
_checkPermissionStatus();
|
|
});
|
|
}
|
|
|
|
Future<void> _checkPermissionStatus() async {
|
|
PermissionStatus status = await Permission.location.status;
|
|
|
|
if (status.isGranted) {
|
|
if (context.mounted) {
|
|
Get.offNamed(AppPages.LOGIN);
|
|
}
|
|
} else {
|
|
if (context.mounted) {
|
|
_showPermissionRequestDialog();
|
|
}
|
|
}
|
|
}
|
|
|
|
void _showPermissionRequestDialog() {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text('location_permission_required_title'.tr),
|
|
content: Text('location_permission_required_message'.tr),
|
|
actions: [
|
|
TextButton(
|
|
child: Text('cancel'.tr),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
Get.offNamed(AppPages.HOME);
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text('ok'.tr),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
_requestLocationPermission();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _requestLocationPermission() async {
|
|
final status = await Permission.location.request();
|
|
if (status.isGranted) {
|
|
Get.offNamed(AppPages.LOGIN);
|
|
} else {
|
|
Get.offNamed(AppPages.HOME);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(body: Container());
|
|
}
|
|
} |