Skip to content

Instantly share code, notes, and snippets.

@zoechi
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoechi/59f4ff738632009278d4 to your computer and use it in GitHub Desktop.
Save zoechi/59f4ff738632009278d4 to your computer and use it in GitHub Desktop.
SO 29567236 Enum as default value
// 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