xsahil03x / super_enum

Create super-powered dart enums similar to sealed classes in Kotlin
https://pub.dev/packages/super_enum
MIT License
116 stars 13 forks source link

Optional fields #51

Closed shinayser closed 4 years ago

shinayser commented 4 years ago

Currently the generator adds "@required" to all DataField objects.

We should have a parameter to indicate if this is really required parameter, like:

    DataField<String>("errorMessage", required: false),

This way, the library will be 100% ready for the NNBD next release of Dart language: https://github.com/dart-lang/language/issues/110

ened commented 4 years ago

Could you use quivers Optional class for this as well?

shinayser commented 4 years ago

I disagree with Quiver suggestion. A boolean should be more than enough and no need for other external library. More dependencies increases the chances of dependency clash in build time.

ened commented 4 years ago

OK. I'm not too familiar, what is Darts declaration of a "nullable" value then look like in the future? Something like String? x (so x may be null?).

If so, would your code snippet look like this:

    DataField<String?>("errorMessage", required: false),
shinayser commented 4 years ago

Yes, exactly like that. But since the NNBD will only come in a future version (maybe 3.0?) the lib should provide a retro compatibility.

That's why I suggested the "required" parameter.

xsahil03x commented 4 years ago

I disagree with Quiver's suggestion. A boolean should be more than enough and no need for other external libraries. More dependencies increase the chances of dependency clash in build time.

Yes, this makes sense. I will add this in the next update.