-
-
Notifications
You must be signed in to change notification settings - Fork 261
Add "isFoo" and "asFoo" getters #22
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
Comments
A isFoo wouldn't work with type promotion, and a asFoo would be unsafe You should use |
As an alternative I personally would make Example 1: // Current implementation
authState.maybeWhen(
authorized: (user) {
// Some logic for authorized users
},
orElse: () {},
);
// Shorter with default orElse
authState.maybeWhen(authorized: (user) {
// Some logic for authorized users
}); Example 2: // Current implementation
final name = authState.maybeWhen(
authorized: (user) => user.name,
orElse: () => null,
);
// Shorter with default orElse
final name = authState.maybeWhen(
authorized: (user) => user.name,
); Not that much of a change, but I think it's more concise and not an unexpected behavior since the "maybe" keyword implicates something nullable in my opinion. |
That is incompatible with non-nullable types. |
I've opened an issue on dart-lang about such For now, I would refrain on making such change, as it would cause a breaking change |
It would be very useful, especially if Union classes are declared privately, to have getter generated which checks if the class is of a certain type. Additionally a getter to cast an object to a nested union type would be useful.
Example:
The text was updated successfully, but these errors were encountered: