【Flutter】freezedで「pub run build_runner build 」実行時にエラーが生じる人たちへ(analyzerでうまく行かなかった人へ)

スペック

[✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-x64, locale ja-JP)

[✓] Android toolchain – develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode – develop for iOS and macOS (Xcode 12.4)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.53.2)

freezed 仕様時に下記のようなエラーが生じた。

$ flutter pub run build_runner build --delete-conflicting-outputs

[INFO] Generating build script...
[INFO] Generating build script completed, took 377ms

[INFO] Creating build script snapshot......
[WARNING] stderr: ../../../../../.flutter/.pub-cache/hosted/pub.dartlang.org/freezed-0.12.7/lib/src/freezed_generator.dart:532:36: Error: The getter 'late' isn't defined for the class 'FieldElement'.
[WARNING] stderr: - 'FieldElement' is from 'package:analyzer/dart/element/element.dart' ('../../../../../.flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/dart/element/element.dart').
[WARNING] stderr: Try correcting the name to the name of an existing getter, or defining a getter or field named 'late'.
[WARNING] stderr: return TypeChecker.fromRuntime(late.runtimeType).hasAnnotationOf(
[WARNING] stderr: ^^^^
[WARNING] stderr: ../../../../../.flutter/.pub-cache/hosted/pub.dartlang.org/freezed-0.12.7/lib/src/templates/concrete_template.dart:361:36: Error: The getter 'nullable' isn't defined for the class 'Element'.
[WARNING] stderr: - 'Element' is from 'package:analyzer/dart/element/element.dart' ('../../../../../.flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-0.41.2/lib/dart/element/element.dart').
[WARNING] stderr: Try correcting the name to the name of an existing getter, or defining a getter or field named 'nullable'.
[WARNING] stderr: return TypeChecker.fromRuntime(nullable.runtimeType)
[WARNING] stderr: ^^^^^^^^
[INFO] Creating build script snapshot... completed, took 6.6s

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.

解消方法

dev channelに切り替えてbuildし、stable channelに戻す

$ flutter clean
$ flutter channel dev
$ flutter upgrade --force
# build
$ flutter pub run build_runner build --delete-conflicting-outputs

# buildしたときに cupertino_icons のバージョンが低くて怒られたので、修正
# pubspec.yaml
## cupertino_icons: any
##
$ flutter channel stable
$ flutter upgrade --force
$ flutter pub get

# flutter pub run build_runner build --delete-conflicting-outputs