I implemented method for checkPermissionStatus even though, I got an error message, Unhandled Exception: MissingPluginException(No implementation found for method checkPermissionStatus on channel flutter.baseflow.com/permissions/methods)
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sampletestingpro/Pages/Firstpage.dart';
import 'package:custom_switch/custom_switch.dart';
class Clockinout extends StatefulWidget {
@override
_ClockinoutState createState() => _ClockinoutState();
}
class _ClockinoutState extends State<Clockinout> {
bool location= false;
GoogleMapController _controller;
Position position;
Widget _child;
Future<void> getPermission() async{
PermissionStatus permission=await PermissionHandler()
.checkPermissionStatus(PermissionGroup.location);
if(permission==PermissionStatus.denied)
{
await PermissionHandler()
.requestPermissions([PermissionGroup.locationAlways]);
}
var geolocator=Geolocator();
GeolocationStatus geolocationStatus=await geolocator.checkGeolocationPermissionStatus();
switch(geolocationStatus)
{
case GeolocationStatus.disabled:
showToast('Disabled');
break;
case GeolocationStatus.restricted:
showToast('Restricted');
break;
case GeolocationStatus.denied:
showToast('Denid');
break;
case GeolocationStatus.unknown:
showToast('Unknown');
break;
case GeolocationStatus.granted:
showToast('Granded');
_getCurrentLocation();
break;
}
}
void showToast(message)
{
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIos: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
void _getCurrentLocation() async
{
Position res=await Geolocator().getCurrentPosition();
setState(() {
position=res;
_child=_mapWidget();
});
}
@override
void initState() {
getPermission();
super.initState();
}
Widget _mapWidget()
{
return GoogleMap(
mapType: MapType.normal,
initialCameraPosition: CameraPosition(target: LatLng(position.latitude,position.longitude),zoom:20.0),
onMapCreated:(GoogleMapController controller)
{
_controller=controller;
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(
child: Text(
'',
style: TextStyle(color: Colors.black),
),
),
backgroundColor: Colors.white,
elevation: 0.0,
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: IconButton(
icon: Icon(
Icons.chevron_left,
color: Colors.black,
),
onPressed: () {
print('back');
Navigator.of(context).push(
new MaterialPageRoute(builder: (context) => Firstpage()));
},
),
),
),
body: SingleChildScrollView(
child:Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Hentry Nixon',style: TextStyle(fontSize: 25,fontWeight: FontWeight.bold,),),
CustomSwitch(
activeColor: location == false ? Colors.red : Colors.green,
value: location,
onChanged: (value) {
print("VALUE : $value");
setState(() {
location = value;
});
},
),
],
),
Row(
children: <Widget>[
Text('2020.02.14',style: TextStyle(color: Colors.black45,),),
Text(''),
],
),
SizedBox(height: 50.0,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Current Project/Task',style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold,fontSize: 20.0),),
Text('Harmony',style: TextStyle(color: Colors.black,fontSize: 20.0),),
],
),
Divider(
thickness: 2,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Current Activity',style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold,fontSize: 20.0),),
Text('Testing',style: TextStyle(color: Colors.black,fontSize: 20.0),),
],
),
Divider(
thickness: 2,
),
Container(
height: 350.0,
color: Colors.yellow,
child: _child,
),
],
),
),
),
),
);
}
}
Are there any way to implemented check permission and get current location
hot reload
or hot restart` ? If so, stop the execution, runflutter clean
and thenflutter run
. Hope it resolves your issue. – Agoraflutter run
it's working fine, Thank a lot. This is the answer to my question. – Macmahon