Above method works but you can use this command:
flutter pub upgrade --major-versions
It will update all your dependencies.
Also check “How to correctly add dependencies to avoid “Version solving failed” error
Refer to this:
https://stackoverflow.com/a/67517680/13500457