Solution 1:
I kept getting the same error, But I solved it adding by adding
file: ^6.1.4 in my dependencies
If you are having the same problem. Make sure you have the latest file dependency.
Solution 2:
If file wasn’t one of your dependency. Just run the below command to upgrade transitive dependencies
flutter pub upgrade
This will update all packages to latest compatible versions. And file may be updated as well to latest version.