Files
rog_app/lib/pages/permission/permission.dart

213 lines
6.4 KiB
Dart
Raw Normal View History

2022-07-20 15:57:40 +05:30
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:rogapp/routes/app_pages.dart';
2023-07-07 16:16:56 +05:30
import 'dart:io';
2022-07-20 15:57:40 +05:30
class PermissionHandlerScreen extends StatefulWidget {
2023-08-16 14:53:32 +05:30
const PermissionHandlerScreen({Key? key}) : super(key: key);
2022-07-20 15:57:40 +05:30
@override
State<PermissionHandlerScreen> createState() => _PermissionHandlerScreenState();
}
class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
2022-07-20 15:57:40 +05:30
2022-12-22 14:06:02 +05:30
Future<void> _showMyDialog() async {
return showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
2023-09-04 22:46:53 +05:30
title: const Text('ロケーション許可'),
content: const SingleChildScrollView(
2022-12-22 14:06:02 +05:30
child: ListBody(
2023-08-16 14:53:32 +05:30
children: <Widget>[
2022-12-22 14:06:02 +05:30
Text( 'このアプリでは、位置情報の収集を行います。'),
Text( 'このアプリでは、開始時点で位置情報を収集します。'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('わかった'),
onPressed: () {
2022-12-25 19:26:07 +05:30
//Navigator.of(context).pop();
Get.toNamed(AppPages.TRAVEL);
2022-12-22 14:06:02 +05:30
},
),
],
);
},
);
}
2022-07-20 15:57:40 +05:30
@override
void initState() {
// TODO: implement initState
super.initState();
//permissionServiceCall();
}
Future<PermissionStatus> checkLocationPermission() async {
return await Permission.location.status;
2022-07-20 15:57:40 +05:30
}
permissionServiceCall() async {
2022-07-20 15:57:40 +05:30
await permissionServices().then(
(value) {
2023-08-16 14:53:32 +05:30
if (value[Permission.location]!.isGranted ) {
/* ========= New Screen Added ============= */
2022-07-20 15:57:40 +05:30
2023-08-16 14:53:32 +05:30
Get.toNamed(AppPages.TRAVEL);
2022-07-20 15:57:40 +05:30
2023-08-16 14:53:32 +05:30
// Navigator.pushReplacement(
// context,
// MaterialPageRoute(builder: (context) => SplashScreen()),
// );
}
else{
_showMyDialog();
2022-07-20 15:57:40 +05:30
}
},
);
}
/*Permission services*/
Future<Map<Permission, PermissionStatus>> permissionServices() async {
// You can request multiple permissions at once.
Map<Permission, PermissionStatus> statuses = await [
Permission.location,
//add more permission to request here.
].request();
if (statuses[Permission.location]!.isPermanentlyDenied) {
2023-07-07 16:16:56 +05:30
await openAppSettings().then(
(value) async {
if (value) {
if (await Permission.location.status.isPermanentlyDenied == true &&
await Permission.location.status.isGranted == false) {
// openAppSettings();
permissionServiceCall(); /* opens app settings until permission is granted */
}
}
},
);
2022-07-20 15:57:40 +05:30
} else {
if (statuses[Permission.location]!.isDenied) {
permissionServiceCall();
}
}
/*{Permission.camera: PermissionStatus.granted, Permission.storage: PermissionStatus.granted}*/
return statuses;
}
2023-07-07 16:16:56 +05:30
requestPermission() async {
PermissionStatus permission = await Permission.location.status;
2023-07-20 13:42:34 +05:30
if(permission == PermissionStatus.permanentlyDenied){
showPermanentAlert(context);
}else{
2023-07-07 16:16:56 +05:30
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);
}
}
2023-07-20 13:42:34 +05:30
// if (permission != PermissionStatus.granted) {
// }
2023-07-07 16:16:56 +05:30
// If permission is granted or already was granted
return true;
}
2022-07-20 15:57:40 +05:30
@override
Widget build(BuildContext context) {
var status = Permission.location.status.then((value){
if(value.isGranted == false){
2023-07-07 16:16:56 +05:30
showAlert(context);
//requestPermission() ? Get.toNamed(AppPages.TRAVEL) : exit(0);
//Future.delayed(Duration.zero, () => showAlert(context));
2023-07-20 13:42:34 +05:30
}
else if(value.isPermanentlyDenied){
}
else {
Get.toNamed(AppPages.TRAVEL);
}
});
return Scaffold(
body: Container(
2023-08-16 14:53:32 +05:30
child: const Text(""),
),
);
}
2023-07-20 13:42:34 +05:30
void showPermanentAlert(BuildContext context) {
showDialog(
context: context,
builder: (_) => AlertDialog(
2023-09-04 22:46:53 +05:30
title: const Text('無効'),
content: const SingleChildScrollView(
2023-07-20 13:42:34 +05:30
child: ListBody(
2023-08-16 14:53:32 +05:30
children: <Widget>[
2023-07-20 13:42:34 +05:30
Text( '位置情報が無効になっています'),
Text('このアプリケーションへの位置情報アクセスが無効になっています。続行するには設定>プライバシーとセキュリティ>位置情報サービス>岐阜ナビ で有効にしてください。'),
],
),
),
actions: <Widget>[
ElevatedButton(
child: const Text('OK'),
onPressed: () {
//requestPermission();
permissionServiceCall();
},
),
],
)
);
}
void showAlert(BuildContext context) {
showDialog(
context: context,
builder: (_) => AlertDialog(
2023-09-04 22:46:53 +05:30
title: const Text('ロケーション許可'),
content: const SingleChildScrollView(
child: ListBody(
2023-08-16 14:53:32 +05:30
children: <Widget>[
Text( 'このアプリでは、位置情報の収集を行います。'),
Text('岐阜ナビアプリではチェックポイントの自動チェックインの機能を可能にするために、現在地のデータが収集されます。アプリを閉じている時や、使用していないときにも収集されます。位置情報は、個人を特定できない統計的な情報として、ユーザーの個人情報とは一切結びつかない形で送信されます。お知らせの配信、位置情報の利用を許可しない場合は、この後表示されるダイアログで「許可しない」を選択してください。'),
],
),
),
actions: <Widget>[
2023-07-10 14:18:44 +05:30
ElevatedButton(
child: const Text('OK'),
onPressed: () {
2023-07-10 14:18:44 +05:30
requestPermission();
//permissionServiceCall();
},
),
],
)
2022-12-25 19:26:07 +05:30
);
2022-07-20 15:57:40 +05:30
}
2022-07-20 15:57:40 +05:30
}