233 lines
7.2 KiB
Dart
233 lines
7.2 KiB
Dart
import 'dart:ffi';
|
|
|
|
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({super.key});
|
|
|
|
@override
|
|
State<PermissionHandlerScreen> createState() => _PermissionHandlerScreenState();
|
|
}
|
|
|
|
class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
|
|
|
|
@override
|
|
void initState(){
|
|
super.initState();
|
|
_checkPermissions();
|
|
}
|
|
|
|
void _checkPermissions() async {
|
|
// You can ask for multiple permissions at once.
|
|
Map<Permission, PermissionStatus> statuses = await [
|
|
Permission.location,
|
|
Permission.camera,
|
|
].request();
|
|
|
|
bool isCameraGranted = statuses[Permission.camera]!.isGranted;
|
|
bool isLocationGranted = statuses[Permission.location]!.isGranted;
|
|
|
|
if (!isCameraGranted || !isLocationGranted) {
|
|
bool isCameraPermanentlyDenied = statuses[Permission.camera]!.isPermanentlyDenied;
|
|
bool isLocationPermanentlyDenied = statuses[Permission.location]!.isPermanentlyDenied;
|
|
|
|
if (isCameraPermanentlyDenied || isLocationPermanentlyDenied) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text('Permissions not granted'),
|
|
content: const Text(
|
|
'This app needs camera and location permissions to function. Please open settings and grant permissions.'),
|
|
actions: <Widget>[
|
|
ElevatedButton(
|
|
child: const Text('Open settings'),
|
|
onPressed: () {
|
|
openAppSettings();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
} else {
|
|
// ask permissions again
|
|
_checkPermissions();
|
|
}
|
|
} else {
|
|
Get.toNamed(AppPages.INITIAL);
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: Text('Checking permissions...'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
// PermissionHandlerScreen({Key? key}) : super(key: key);
|
|
|
|
// @override
|
|
// State<PermissionHandlerScreen> createState() => _PermissionHandlerScreenState();
|
|
// }
|
|
|
|
// class _PermissionHandlerScreenState extends State<PermissionHandlerScreen> {
|
|
|
|
|
|
// Future<void> _showMyDialog() async {
|
|
// return showDialog<void>(
|
|
// context: context,
|
|
// barrierDismissible: false, // user must tap button!
|
|
// builder: (BuildContext context) {
|
|
// return AlertDialog(
|
|
// title: const Text('ロケーション許可'),
|
|
// content: SingleChildScrollView(
|
|
// child: ListBody(
|
|
// children: const <Widget>[
|
|
// Text( 'このアプリでは、位置情報の収集を行います。'),
|
|
// Text( 'このアプリでは、開始時点で位置情報を収集します。'),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// actions: <Widget>[
|
|
// TextButton(
|
|
// child: const Text('わかった'),
|
|
// onPressed: () {
|
|
// //Navigator.of(context).pop();
|
|
// Get.toNamed(AppPages.TRAVEL);
|
|
// },
|
|
// ),
|
|
// ],
|
|
// );
|
|
// },
|
|
// );
|
|
// }
|
|
|
|
// @override
|
|
// void initState() {
|
|
// // TODO: implement initState
|
|
// super.initState();
|
|
|
|
// //permissionServiceCall();
|
|
// }
|
|
|
|
// Future<PermissionStatus> checkLocationPermission() async {
|
|
// return await Permission.location.status;
|
|
// }
|
|
|
|
// permissionServiceCall() async {
|
|
// await permissionServices().then(
|
|
// (value) {
|
|
// if (value != null) {
|
|
// if (value[Permission.location]!.isGranted ) {
|
|
// /* ========= New Screen Added ============= */
|
|
|
|
// Get.toNamed(AppPages.TRAVEL);
|
|
|
|
// // Navigator.pushReplacement(
|
|
// // context,
|
|
// // MaterialPageRoute(builder: (context) => SplashScreen()),
|
|
// // );
|
|
// }
|
|
// else{
|
|
// _showMyDialog();
|
|
// }
|
|
// }
|
|
// },
|
|
// );
|
|
// }
|
|
|
|
|
|
// /*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) {
|
|
// 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 */
|
|
// }
|
|
// }
|
|
// },
|
|
// );
|
|
// } else {
|
|
// if (statuses[Permission.location]!.isDenied) {
|
|
// permissionServiceCall();
|
|
// }
|
|
// }
|
|
|
|
// /*{Permission.camera: PermissionStatus.granted, Permission.storage: PermissionStatus.granted}*/
|
|
// return statuses;
|
|
// }
|
|
|
|
|
|
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// var status = Permission.location.status.then((value){
|
|
// if(value.isGranted == false){
|
|
// Future.delayed(Duration.zero, () => showAlert(context));
|
|
// }
|
|
// else {
|
|
// Get.toNamed(AppPages.TRAVEL);
|
|
// }
|
|
// });
|
|
// return Scaffold(
|
|
// body: Container(
|
|
// child: Text(""),
|
|
// ),
|
|
// );
|
|
// }
|
|
|
|
// void showAlert(BuildContext context) {
|
|
// showDialog(
|
|
// context: context,
|
|
// builder: (_) => AlertDialog(
|
|
// title: const Text('ロケーション許可'),
|
|
// content: SingleChildScrollView(
|
|
// child: ListBody(
|
|
// children: const <Widget>[
|
|
// Text( 'このアプリでは、位置情報の収集を行います。'),
|
|
// Text('岐阜ナビアプリではチェックポイントの自動チェックインの機能を可能にするために、現在地のデータが収集されます。アプリを閉じている時や、使用していないときにも収集されます。位置情報は、個人を特定できない統計的な情報として、ユーザーの個人情報とは一切結びつかない形で送信されます。お知らせの配信、位置情報の利用を許可しない場合は、この後表示されるダイアログで「許可しない」を選択してください。'),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// actions: <Widget>[
|
|
// TextButton(
|
|
// child: const Text('わかった'),
|
|
// onPressed: () {
|
|
// permissionServiceCall();
|
|
// },
|
|
// ),
|
|
// ],
|
|
// )
|
|
// );
|
|
// }
|
|
|
|
|
|
// } |