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 createState() => _PermissionHandlerScreenState(); } class _PermissionHandlerScreenState extends State { Future _showMyDialog() async { return showDialog( context: context, barrierDismissible: false, // user must tap button! builder: (BuildContext context) { return AlertDialog( title: const Text('ロケーション許可'), content: SingleChildScrollView( child: ListBody( children: const [ Text( 'このアプリでは、位置情報の収集を行います。'), Text( 'このアプリでは、開始時点で位置情報を収集します。'), ], ), ), actions: [ TextButton( child: const Text('わかった'), onPressed: () { //Navigator.of(context).pop(); Get.toNamed(AppPages.TRAVEL); }, ), ], ); }, ); } @override void initState() { // TODO: implement initState super.initState(); permissionServiceCall(); } 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> permissionServices() async { // You can request multiple permissions at once. Map 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) { return Container( color: Colors.white, child: Center( child: Text(""), ), ); } }