title: How to ask for location permission in flutter? I've tried something but it doesn't work
body: <p>It's actually very simple app, only asking for location. I searched a lot about this, very speculative matter everyone says different things and I couldn't solve myself yet. What I want is, I want to ask user of location permission. I added this into dependencies in pubspec.yaml:</p>
  <pre><code>  permission_handler: ^5.0.1+1
  </code></pre>
  <p>And in AndroidManifest.xml I added these:</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; &gt;&lt;/uses-permission&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; &gt;&lt;/uses-permission&gt;
  </code></pre>
  <p>And then I've written my main.dart, just like that. Didn't do anything else:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:permission_handler/permiission_handler.dart';
  
  void main() =&gt; runApp(MaterialApp(home: MyHome()));
  
  class _MyHomeState extends StatefulWidget {
    @override
    _MyHomeState createState() =&gt; _MyHomeState();
  }
  
  class _MyHomeState extends State&lt;MyHome&gt; {
    PermissionStatus _status;
  
    @override
    void initState() {
      super.initState();
      PermissionHandler()
          .checkPermissionStatus(PermissionGroup.locationWhenInUse)
          .then(_updateStatus);
    }
  
    @override
    Widget build(BuildContext context) {
      return SafeArea(
        child: Column(
          children: &lt;Widget&gt;[
            Text('$_status'),
            SizedBox(height: 60),
            RaisedButton(
              child: Text('Ask Permission'),
              onPressed: _askPermission,
            )
          ], //&lt;Widget&gt;[]
        ),
      ); //Column, SafeArea
    }
  
    void _updateStatus(PermissionStatus status) {
      if (status != _status) {
        setState(() {
          _status = status;
        });
      }
    }
  
    void _askPermission() {
      PermissionHandler().requestPermissions(
          [PermissionGroup.locationWhenInUse]).then(_onStatusRequested);
    }
  
    void _onStatusRequested(Map&lt;PermissionGroup, PermissionStatus&gt; statuses) {
      final status = statuses[PermissionGroup.locationWhenInUse];
      //if (status != PermissionStatus.granted) {
        //PermissionHandler().openAppSettings();
      //} else { //Ignore this, this isn't important.
        _updateStatus(status);
      }
    }
  }
  </code></pre>
  <p>Then I use   flutter run        and it gives lots of error. Like:</p>
  <pre><code>Invalid depfile: /home/xx/AndroidStudioProjects/flutter_app/.dart_tool/flutter_build/e9846fe3c39761c4693f6682f4c69be2/kernel_snapshot.d
  Invalid depfile: /home/xxx/AndroidStudioProjects/flutter_app/.dart_tool/flutter_build/e9846fe3c39761c4693f6682f4c69be2/kernel_snapshot.d
  Error: Could not resolve the package 'permission_handler' in 'package:permission_handler/permiission_handler.dart'.
  lib/main.dart:11:7: Error: '_MyHomeState' is already declared in this scope.
  class _MyHomeState extends State&lt;MyHome&gt; {                              
        ^^^^^^^^^^^^                                                      
  lib/main.dart:6:7: Context: Previous declaration of '_MyHomeState'.     
  class _MyHomeState extends StatefulWidget {                             
        ^^^^^^^^^^^^                                                      
  lib/main.dart:59:1: Error: Expected a declaration, but got '}'.         
  }                                                                       
  ^                                                                       
  lib/main.dart:2:8: Error: Not found: 'package:permission_handler/permiission_handler.dart'
  import 'package:permission_handler/permiission_handler.dart';           
         ^                                                                
  lib/main.dart:8:3: Error: '_MyHomeState' isn't a type.                  
    _MyHomeState createState() =&gt; _MyHomeState();                         
    ^^^^^^^^^^^^                                                          
  lib/main.dart:8:3: Context: This isn't a type.                          
    _MyHomeState createState() =&gt; _MyHomeState();                         
    ^^^^^^^^^^^^                                                          
  lib/main.dart:11:34: Error: Type 'MyHome' not found.                    
  class _MyHomeState extends State&lt;MyHome&gt; {                              
                                   ^^^^^^                                 
  lib/main.dart:12:3: Error: Type 'PermissionStatus' not found.           
    PermissionStatus _status;                                             
    ^^^^^^^^^^^^^^^^                                                      
  lib/main.dart:38:22: Error: Type 'PermissionStatus' not found.          
    void _updateStatus(PermissionStatus status) {                         
                       ^^^^^^^^^^^^^^^^                                   
  lib/main.dart:51:31: Error: Type 'PermissionGroup' not found.           
    void _onStatusRequested(Map&lt;PermissionGroup, PermissionStatus&gt; statuses) {
                                ^^^^^^^^^^^^^^^                           
  lib/main.dart:51:48: Error: Type 'PermissionStatus' not found.          
    void _onStatusRequested(Map&lt;PermissionGroup, PermissionStatus&gt; statuses) {
                                                 ^^^^^^^^^^^^^^^^         
  lib/main.dart:4:41: Error: Method not found: 'MyHome'.                  
  void main() =&gt; runApp(MaterialApp(home: MyHome()));                     
                                          ^^^^^^                          
  lib/main.dart:8:33: Error: Can't use '_MyHomeState' because it is declared more than once.
    _MyHomeState createState() =&gt; _MyHomeState();                         
                                  ^                                       
  lib/main.dart:12:3: Error: 'PermissionStatus' isn't a type.             
    PermissionStatus _status;                                             
    ^^^^^^^^^^^^^^^^                                                      
  lib/main.dart:17:5: Error: The method 'PermissionHandler' isn't defined for the class '_MyHomeState#1'.
   - '_MyHomeState#1' is from 'package:flutter_app/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'PermissionHandler'.
      PermissionHandler()                                                 
      ^^^^^^^^^^^^^^^^^                                                   
  lib/main.dart:18:32: Error: The getter 'PermissionGroup' isn't defined for the class '_MyHomeState#1'.
   - '_MyHomeState#1' is from 'package:flutter_app/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing getter, or defining a getter or field named 'PermissionGroup'.
          .checkPermissionStatus(PermissionGroup.locationWhenInUse)       
                                 ^^^^^^^^^^^^^^^                          
  lib/main.dart:38:22: Error: 'PermissionStatus' isn't a type.            
    void _updateStatus(PermissionStatus status) {                         
                       ^^^^^^^^^^^^^^^^                                   
  lib/main.dart:47:5: Error: The method 'PermissionHandler' isn't defined for the class '_MyHomeState#1'.
   - '_MyHomeState#1' is from 'package:flutter_app/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'PermissionHandler'.
      PermissionHandler().requestPermissions(                             
      ^^^^^^^^^^^^^^^^^                                                   
  lib/main.dart:48:10: Error: The getter 'PermissionGroup' isn't defined for the class '_MyHomeState#1'.
   - '_MyHomeState#1' is from 'package:flutter_app/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing getter, or defining a getter or field named 'PermissionGroup'.
          [PermissionGroup.locationWhenInUse]).then(_onStatusRequested);  
           ^^^^^^^^^^^^^^^                                                
  lib/main.dart:51:31: Error: 'PermissionGroup' isn't a type.             
    void _onStatusRequested(Map&lt;PermissionGroup, PermissionStatus&gt; statuses) {
                                ^^^^^^^^^^^^^^^                           
  lib/main.dart:51:48: Error: 'PermissionStatus' isn't a type.            
    void _onStatusRequested(Map&lt;PermissionGroup, PermissionStatus&gt; statuses) {
                                                 ^^^^^^^^^^^^^^^^         
  lib/main.dart:52:29: Error: The getter 'PermissionGroup' isn't defined for the class '_MyHomeState#1'.
   - '_MyHomeState#1' is from 'package:flutter_app/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing getter, or defining a getter or field named 'PermissionGroup'.
      final status = statuses[PermissionGroup.locationWhenInUse];   
  </code></pre>