Last active
August 29, 2015 14:18
-
-
Save zoechi/59f4ff738632009278d4 to your computer and use it in GitHub Desktop.
SO 29567236 Enum as default value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 29567236 | |
class Status { | |
static const off = const Status._(0); | |
static const on = const Status._(1); | |
final int value; | |
const Status._(this.value); | |
} | |
doSomething1([Status status = Status.off]) { | |
if(status != null && status == Status.on) { | |
print(status.value); | |
} | |
} | |
enum Status2 { | |
off, | |
on | |
} | |
doSomething2([Status2 status = Status2.off]) { | |
if(status != null && status == Status2.on) { | |
print(status.index); | |
} | |
} | |
void main() { | |
doSomething1(Status.on); | |
doSomething2(Status.on); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment