我实现了检查用户权限的方法,甚至认为我在 flutter 中收到错误消息 "MissingPluginException"?
I implemented method for check the users permission even thought i got error message "MissingPluginException" in flutter?
我为 checkPermissionStatus 实现了方法,尽管如此,我收到一条错误消息,未处理的异常:MissingPluginException(在通道 [=23 上未找到方法 checkPermissionStatus 的实现=].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,
),
],
),
),
),
),
);
}
}
有什么方法可以实现检查权限和获取当前位置
This is working for me
flutter run
或
flutter clean
如果您实施了错误的元数据或 activity 等,有时它是由 AndroidManifest.xml 引起的...
当我强制更新所有插件时,我遇到了那种 MissingPluginException 错误。因为我在 AndroidManifest.xml 中使用旧版本的 Facebook 登录元数据和 activity 。修复后一切正常
我为 checkPermissionStatus 实现了方法,尽管如此,我收到一条错误消息,未处理的异常:MissingPluginException(在通道 [=23 上未找到方法 checkPermissionStatus 的实现=].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,
),
],
),
),
),
),
);
}
}
有什么方法可以实现检查权限和获取当前位置
This is working for me
flutter run
或
flutter clean
如果您实施了错误的元数据或 activity 等,有时它是由 AndroidManifest.xml 引起的...
当我强制更新所有插件时,我遇到了那种 MissingPluginException 错误。因为我在 AndroidManifest.xml 中使用旧版本的 Facebook 登录元数据和 activity 。修复后一切正常