androidflutterkotlindart

How to use registerForActivityResult in Flutter's MainActivity?


I am trying to use registerForActivityResult to create my own native module in Flutter but I keep getting error saying Unresolved reference: registerForActivityResult

Below is my code

private val takePicture = registerForActivityResult(ActivityResultContracts.TakePicture()) { isSaved ->
        if (isSaved)
        {

        }
    }

I tried looking at this as well but I get the same error message when I create PickerMethodChannelHandler as mentioned in the post


Solution

  • Apart from changing FlutterActivity to FlutterFragmentActivity I had to add implementation 'androidx.activity:activity-ktx:1.7.0' in build.gradle

    Also add implementation 'androidx.fragment:fragment-ktx:1.5.6' otherwise you will get an error saying Caused by: java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode