I have wrestled with this thing for some time. The issue is most likely due to a Gradle update. You need to update Gradle on your Flutter project as well.
You might also need to update you Target, Compile Version SDK and Kotlin version just to rule that out.
- Go to android/app/build.gradle and update the Gradle classPath as below
classpath 'com.android.tools.build:gradle:7.1.2'
- Go to android/app/gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip
Once done, run flutter.
Battle won, but the war with Gradle continues, until next time.