Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with EnumDeclarationsMacro #141

Open
BirjuVachhani opened this issue Nov 14, 2024 · 0 comments
Open

Issue with EnumDeclarationsMacro #141

BirjuVachhani opened this issue Nov 14, 2024 · 0 comments

Comments

@BirjuVachhani
Copy link

I was playing with macros on enums with following macro:

macro class EnumTest implements EnumDeclarationsMacro {
  const EnumTest();

  @override
  FutureOr<void> buildDeclarationsForEnum(EnumDeclaration enuum, EnumDeclarationBuilder builder) {
    builder.declareInType(DeclarationCode.fromParts([
      'void test() {',
      'print("Hello World");',
      '}',
    ]));
  }
}

Usage:

void main() {
  UserPlan userPlan = UserPlan.free;
  userPlan.test(); // Error test method is not found.
}

@EnumTest()
enum UserPlan { free, premium, team, business }

This results into an error where the test method is not found/generated. The same operation on a class with ClassDeclarationsMacro works just fine. It adds a method called test in the class declarations. I was expecting the same with enums. Is this a bug or am I missing something here?

@BirjuVachhani BirjuVachhani changed the title My Enum macro is not working Issue with EnumDeclarationsMacro Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant