flutterdartbuild-runner

build_runner showing error The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'


When I am running build_runner command it is showing me following error:

Failed to build build_runner:build_runner:
../../.pub-cache/hosted/pub.dev/dart_style-2.3.5/lib/src/front_end/ast_node_visitor.dart:251:16: Error: The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'.
  - 'ClassDeclaration' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../.pub-cache/hosted/pub.dev/analyzer-6.2.0/lib/src/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'macroKeyword'.
          node.macroKeyword,
                ^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/dart_style-2.3.5/lib/src/source_visitor.dart:595:19: Error: The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'.
  - 'ClassDeclaration' is from 'package:analyzer/src/dart/ast/ast.dart' ('../../.pub-cache/hosted/pub.dev/analyzer-6.2.0/lib/src/dart/ast/ast.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'macroKeyword'.
    modifier(node.macroKeyword);
                  ^^^^^^^^^^^^

Solution

  • Add analyzer: ^5.11.1 to your dev_dependencies and run the following:

    flutter clean
    
    flutter pub get
    
    dart run build_runner build
    

    Note: If the analyzer version 5.11.1 doesn't work for you, try changing the version and it will work. You can check for the version here https://pub.dev/packages/analyzer/changelog