Flutter extension-methods not working, it says "undefined class" and "requires the extension-methods language feature"

For the changes in pubspec.yaml and analysis_options.yaml to take place, you have to restart the Dart Analysis Server. In VSCode, that's as simple as Ctrl+Shift+P -> Reload Window.

In Android Studio solving this problem requires three steps:

  1. Update SDK version in pubspec.yaml (must be 2.6.0 or higher)

       sdk: ">=2.7.0 <3.0.0"
  2. Tools -> Flutter -> Flutter Clean

  3. Close project and reopen it (eg. File -> Close project)

I had to do flutter clean, then close and re-open VSCode.