Andorid Studio lass 'FlutterLocationService' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult
Asked Answered
I

4

6

Out of nowhere, the build is crashing with a strange error related to the location component , the error is in the "src..\location\FlutterLocationService.kt:"

Here is the error:

e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\location-4.3.0\android\src\main\java\com\lyokone\location\FlutterLocationService.kt: (124, 1): Class 'FlutterLocationService' is not abstract and does not implement abstract member public abstract fun onRequestPermissionsResult(p0: Int, p1: Array<(out) String!>, p2: IntArray): Boolean defined in io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener
Intemerate answered 20/4, 2022 at 8:49 Comment(0)
E
15

This has been fixed in the new version. Update the dependency in the pubspec.yml file to

  location: ^4.4.0
Evilminded answered 16/5, 2022 at 15:13 Comment(1)
Yes, do that instead. With flutter 3.0.0 and location: ^4.4.0 package update problem fixed.Intemerate
I
10

Well, I solved the problem just making 3 differences. First you will put "override" before the "fun" keyword. Then delete the question marks in front of "Array" this and "grantResults: IntArray" this.

It should be "Array?" , "grantResults: IntArray?" like this at the beginning just delete the question marks.

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray): Boolean {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && permissions!!.size == 2 &&
            permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION && permissions[1] == Manifest.permission.ACCESS_BACKGROUND_LOCATION) {
        if (grantResults!![0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
            // Permissions granted, background mode can be enabled
            enableBackgroundMode()
            result?.success(1)
            result = null
        } else {
            if (!shouldShowRequestBackgroundPermissionRationale()) {
                result?.error("PERMISSION_DENIED_NEVER_ASK",
                        "Background location permission denied forever - please open app settings", null)
            } else {
                result?.error("PERMISSION_DENIED", "Background location permission denied", null)
            }
            result = null
        }
    }
    return false
}
Intemerate answered 20/4, 2022 at 9:34 Comment(0)
C
3

Update your location package to this for the main time

location:
    git:
      url: https://github.com/Yczar/flutterlocation.git
      path: packages/location 

you can also comment on the issue here

Consequence answered 12/5, 2022 at 8:32 Comment(1)
Clearly the best solution for every problem caused by a package :)Photoreceptor
A
3

Goto External libraries -> Flutter Plugins -> location-x.x.x(package version) -> android -> src.main -> java.com.xxx.location -> FlutterLocationService.kt

Remove '?' from override fun onRequestPermissionResult parameters.

Ainslie answered 23/5, 2022 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.