Had the same issue.
So first download jdk17 from respective website. then use this command in terminal of your project
flutter config --jdk-dir /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
from "/Library" to "/Home" is your desired jdk location.
This is another fix that worked for me https://stackoverflow.com/a/73985328/8764293