Hacker News new | ask | show | jobs
by newZWhoDis 1228 days ago
Last I checked you can’t even have enums with payloads/ associated values.

Garbage language

2 comments

You can since 2.17. Not sure if you’re being sarcastic about this making it a garbage language.
Is that not just string/int/basic types? Last time I looked it was and it was a complete joke.

I want to define

enum UserState {

case loggedOut

case loggedIn(user: User)

}

where User is itself a struct with props like email/id/Etc

Then, I want to be able to switch on said enum, so that my code can take a UserSession state stream and switch over each case to react accordingly. This gives me compiler - enforced case handling completeness everywhere my enum is consumed which is amazing for code reliability.

This is trivial in Swift or any real language, but with Dart and the stupid flutter bloc model you seemingly can’t do this and end up with these huge if cast chains to send messages.

If I’m wrong and things have changed for the better please let me know, it was my biggest issue with dart/flutter

See my sibling comment. That appears to only work with basic types like strings/ints?

I need to add complex objects, sometimes multiple. Swift lets you do this easily.

No, you can add as many fields of whatever types you want to an enum in Dart.