【備忘録】Flutter で build_runner を使い flutter pub run build_runner build をしたときに、 Failed to precompile build_runner:build_runner といったエラーが出る場合の対応
環境
ProductName: Mac OS X ProductVersion: 10.15.7 BuildVersion: 19H1030
Flutter: 2.2.0 build_runner: 2.0.2
エラーについて
$ flutter pub run build_runner build Failed to precompile build_runner:build_runner: ../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:1600:40: Error: Getter not found: 'topLevelVariable'. return kinds.contains(TargetKind.topLevelVariable); ^^^^^^^^^^^^^^^^ ../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2024:23: Error: Getter not found: 'topLevelVariable'. case TargetKind.topLevelVariable: ^^^^^^^^^^^^^^^^ ../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2024:23: Error: Type 'dynamic' of the case expression is not a subtype of type 'TargetKind' of this switch expression. - 'TargetKind' is from 'package:meta/meta_meta.dart' ('../../../.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/lib/meta_meta.dart'). case TargetKind.topLevelVariable: ^ ../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.6.0/lib/src/error/best_practices_verifier.dart:2001:13: Context: The switch expression is here. switch (this) { ^ pub finished with exit code 1
対応
$ flutter packages pub upgrade
vscodeだと以下をクリックしてもできます
参考
https://github.com/dart-lang/build/issues/1676#issuecomment-458056325