-
Notifications
You must be signed in to change notification settings - Fork 184
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
named arguments to set fields in a constructor #155
Comments
I've been thinking of doing this along with support for read-only protobufs. I'm not working on it, though. (I think it would be better to use named parameters for all fields. Protobuf fields usually don't have a logical order.) |
I'd like to take this on, if you are interested in contributions. I've already signed the Google contributor agreement. |
I agree ! This would be a lot easier to write embedded affectation IMO. Only using named parameters could be even better too (like Flutter API). You can make named parameter @required with meta package. I find that this kind of instantiation is quite a mess (too many parenthesis and dots) : Person()
..name = "John"
..address = (Address()
..street = 5
..label = "Baker street"
..country = (Country()
..code = "en"
..name = "england"
)
) The following feels a lot more natural to me, and more aligned with traditional dart APIs : Person(
name: "John",
address: Address(
street: 5,
label: "Baker street",
country: Country(code: "en", name: "england")
)
) |
I am not sure if this feature request is worth it, but I wanted to share the idea, so here it is:
What if we take generated messages and make a constructor that takes as arguments the actual fields from the proto buff? for example:
generates:
I just often see patterns where developers have all the data they need to fill in, and end up writing code like:
instead of:
The text was updated successfully, but these errors were encountered: