For a Flutter project, in addition to what @LuanLuanLuan proposed (https://stackoverflow.com/a/68471280/385390), also do:
flutter config --jdk-dir="${JAVA_HOME}"
provided the env-var JAVA_HOME
was set earlier, as suggested.
It would be nice if Flutter could read the JAVA_HOME
env-var and not require this special notification.
Once you are there, do not forget to do:
flutter --disable-analytics
flutter doctor --disable-analytics