I implemented method for check the users permission even thought i got error message "MissingPluginException" in flutter?
Asked Answered
M

4

22

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

Macmahon answered 10/2, 2020 at 5:23 Comment(2)
Are you trying to run the app through hot reload or hot restart` ? If so, stop the execution, run flutter clean and then flutter run. Hope it resolves your issue.Agora
I tried a hot restart but not working, after your guidance, I tried flutter run it's working fine, Thank a lot. This is the answer to my question.Macmahon
M
30

This is working for me

flutter run

or

flutter clean
Macmahon answered 16/3, 2020 at 6:13 Comment(2)
is hot reload a single cmd, or something like fluter hot reload?Transact
Actually i meant, hot reload from IDE, there is no such command called hot reload. Thanks for your question, and sorry for my late replyMacmahon
T
5

I have stopped running completely, exit / kill app and restart then try to run

click on stop button, refer below enter image description here

Toscana answered 13/12, 2022 at 7:30 Comment(0)
E
4

Sometime it caused by AndroidManifest.xml if you implemented wrong meta-data or activity etc...

When I updated all of plugins by force , I faced that kind of MissingPluginException error . Because I m using old version of Facebook login meta-data and activity in AndroidManifest.xml . After fixed that everything is fine.

Endres answered 30/7, 2021 at 4:11 Comment(0)
R
0

Just stop your current running (exit), and start it again. It always works for me.

I found it here : enter link description here

Roughandready answered 3/3 at 6:37 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Distilled

© 2022 - 2024 — McMap. All rights reserved.