You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in dart I find we have to put scope braces and break statement in cases in switch statement.
Can we do like in swift we have switch case as shown below.
switch index {
case 100 :
println( "Value of index is 100")
case 10, 15:
println( "Value of index is either 10 or 15")
case 5 :
println( "Value of index is 5")
default :
println( "default case")
}
Enum Switch case type infer: In each switch case we have mention enumName.value. Can we do like in swift
DART
enum Status { none, run, stop, pause }
extension StatusEx on Status {
String get name {
switch (this) {
case Status.run:
return 'RUN';
case Status.stop:
return 'STOP';
default:
return "NONE";
}
}
}
In swift we don't have to mention enum name, we use direct .notation.
SWIFT
enum Status { none, run, stop, pause }
extension Status {
String get name {
switch (this) {
case .run:
return 'RUN';
case .stop:
return 'STOP';
default:
return "NONE";
}
}
}
For extending Enum, can we remove mentioning new name as above?
The text was updated successfully, but these errors were encountered:
switch (index) {
case100:print( "Value of index is 100");
break;
case10:case15:print( "Value of index is either 10 or 15");
break;
case5:print( "Value of index is 5");
break;
default:print( "default case")
}
I'd love to get rid of the requirement to have a break. I don't think we have an open issue for that.
As for allowing unnamed extensions, you can write:
extension on Status { ... }
but that only works within the same library.
For now you need extension StatusExtension on Status { ... } because it gives the extension a name, which allows you to hide or show it in an import. An unnamed extension would be impossible to hide or show.
I'd rather improve enums so that you can declare the method directly on the enum, rather than have to add it with an extension.
Can we do like in swift we have switch case as shown below.
DART
In swift we don't have to mention enum name, we use direct .notation.
SWIFT
The text was updated successfully, but these errors were encountered: