If you are working in a Windows environment, follow these steps:
In the first step: 1- Run the cmd: flutter config --list
I will show you the way out of it enter image description here
2- Second: Run the cmd: flutter config --jdk-dir /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home