-
Notifications
You must be signed in to change notification settings - Fork 123
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
Wrong generated code with classes of the same name #632
Comments
As a workaround, could you call your model |
Yes, probably it's the best workaround to use both classes without conflicts. |
Other options are:
import 'package:chopper/chopper.dart' hide Post;
import 'package:chopper/chopper.dart' as chopper; We're unlikely to change any of the annotation classes ( |
Unfortunately, importing chopper with a prefix gives the same problem: the code is generated using chopper classes without the prefixes. IMHO, the best way to fix this is to make the generator add possible prefixes. |
I'm just looking into that. Not sure about it either. 🙈 I suggest you don't use these reserved class names. EDIT: Looks like freezed has a similar issue. Could be nasty. Related: dart-lang/source_gen#462 |
Indeed looks like a tough problem. Have been experimenting a bit with macros but having checked this use case but maybe the dart augmentation offer a workaround. But this solution will have to wait till macros are ready. (And implemented in chopper) |
Another workaround would be to rename |
Steps to Reproduce
Post
class.Post
class, I put the prefixpost_model
for the model.dart run build_runner build --delete-conflicting-outputs
. The generated code will be the following:The code above doesn't compile. This happens because the generator uses the
Post
class without the prefix, which is the one in the Chopper library, used for POST requests.Putting a prefix for the
chopper.dart
package gives the same result: the generated code doesn't put the prefix before Chopper classes and annotations, so the compiler doesn't find them.The only workaround I found so far is to hide the
Post
class from Chopper, but this is not always possible: for example, if you need a POST request, you have to use both classes.Expected results: generated code with prefixes, like the following:
Logs
The text was updated successfully, but these errors were encountered: