I have fixed this error with flutter config --jdk-dir /your/path/jvm/java-17-openjdk/
flutter config --jdk-dir /your/path/jvm/java-17-openjdk/
This is a global config and it changes the jdk for all of your projects. You can unset the config with flutter config --jdk-dir ''
flutter config --jdk-dir ''