我实现了检查用户权限的方法,即使我在颤动中收到错误消息“MissingPluginException”?

Posted

技术标签:

【中文标题】我实现了检查用户权限的方法,即使我在颤动中收到错误消息“MissingPluginException”?【英文标题】:I implemented method for check the users permission even thought i got error message "MissingPluginException" in flutter? 【发布时间】:2020-05-25 10:08:22 【问题描述】:

我为 checkPermissionStatus 实现了方法,尽管我收到了一条错误消息,未处理的异常:MissingPluginException(在通道 flutter.baseflow.com/permissions/methods 上找不到方法 checkPermissionStatus 的实现)

  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,
              ),
             ],
           ),
         ),
        ),
      ),
    );
  

有没有办法实现检查权限并获取当前位置

【问题讨论】:

您是尝试通过hot reload 还是热重启运行应用程序?如果是这样,停止执行,运行flutter clean,然后运行flutter run。希望它能解决您的问题。 我尝试了热重启但不工作,在您的指导下,我尝试了flutter run它工作正常,非常感谢。这是我的问题的答案。 【参考方案1】:

如果你实现了错误的元数据或活动等,有时它是由 androidManifest.xml 引起的......

当我强制更新所有插件时,我遇到了那种 MissingPluginException 错误。因为我在 AndroidManifest.xml 中使用旧版本的 Facebook 登录元数据和活动。修复后一切正常。

【讨论】:

【参考方案2】:

这对我有用

flutter run

flutter clean

【讨论】:

hot reload 单个 cmd,还是类似 fluter hot reload? 其实我的意思是,从IDE热重载,没有这样的命令叫做hot reload。谢谢你的问题,很抱歉我的回复晚了

以上是关于我实现了检查用户权限的方法,即使我在颤动中收到错误消息“MissingPluginException”?的主要内容,如果未能解决你的问题,请参考以下文章

每当我在颤动中运行我的程序时,我在控制台中收到此错误任何解决方案?

ERROR_ALREADY_REQUESTING_PERMISSIONS 颤动

即使在清单中添加 WRITE_SECURE_SETTINGS 权限错误

权限处理程序颤动多个权限错误

谷歌地图颤动检查多边形内的点

如何在颤动中使用 Bloc 模式处理用户注册错误