I fixed this issue by using java 17 to compile the application which can be done by running this command: " flutter config --jdk-dir= " and run " flutter doctor " to see if things are ok and try compiling.