Comments (7)
@sinadarvi that's a pretty nice use-case. Yes, we can work on this but I think we have to create different annotations for these kinds of code generation. So that the developer won't get much confused. @astralstriker whats your views on this?
from super_enum.
As good as the use case is, it is not relevant to sealed classes and therefore, super enum.
This is about enum with values, which again can be emulated with super enum but really would be an overkill. I don't want to added this feature to super enum either as it doesn't glue in with the concept of sealed classes.
Imo, we should make another package for this, that's maybe is simply called enum.
from super_enum.
@astralstriker
sry for my poor understanding, but how can it break any concept of sealed classes? is there anything I don't see? can you explain more?
from super_enum.
Might be me whose understanding is poor.
As far as my understanding goes-
Enum values by default have an index associated with them, starting from 0 of course, which is considered to be their values. Just as your use case suggested, you sometimes need to assign values different from indices to enum values.
In your case, the enum values have the same type (String) of value assigned to them. In Kotlin and Java, this is achievable by using plain enum classes.
Sealed classes come into play when there are different types of values associated with the values of an enum.
from super_enum.
@astralstriker I can understand your concern but it's not necessary to just use phrase value
we can set any name suitable! and I don't think there is any conflict with sealed class concept. as you know a sealed class can have multiple subclasses and any of them can have multiple instances. so, as far as I know, shouldn't be any problem here.
@superEnum(String,"code")
enum Country{
@value("ae")
UnitedArabEmirates,
@value("ar")
Argentina,
@value("at")
Austria,
}
main(){
Country country = Country.Austria;
print(country.code)
}
and generated country.g.dart
:
.
.
.
@immutable
class Argentina extends Country {
const Argentina() : super(_Country.Argentina);
final String code = "ar";
@override
String toString() => 'Argentina(code:${this.code})';
@override
List get props => [code];
}
.
.
.
from super_enum.
@astralstriker any idea? can we somehow figure it out?
from super_enum.
@sinadarvi thanks for the feature request but, this request is out of scope for this package and should be handled by creating another generator package.
So closing as of now 👍
from super_enum.
Related Issues (20)
- Enum as data field in another enum HOT 1
- DataFields with a name including 'T' break code generation HOT 1
- use const constructor
- @UseClass generating Error HOT 1
- Generate copyWith methods for data classes
- Create a separate whenAsync method for handling asynchronous calls and remove FutureOr from whenXXX.
- Linter Error with super_enum_generator 0.4.2 HOT 8
- Generate whenPartial with normal return type HOT 2
- Why renaming enum fields? HOT 2
- Optional fields HOT 5
- emit `when` method arguments for "empty" actions HOT 2
- Use PartBuilder instead of SharedPartBuilder in generator
- Allow setting null value in copyWith function
- WhenPartial breaks when updraging from 0.3.0 to 0.4.2 HOT 2
- Can you please make a release? HOT 1
- Could we allow to generate some types as private types to be consumed by the bloc itself only?
- super_enum is not working with analyzer ^0.40.1 HOT 2
- Overriding == operator of Data classes
- How can I convert a String to a Enum Type
- Release null safe version ? HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from super_enum.