final argument that defaults to uuid?

22 views
Skip to first unread message

Guyren Howe

unread,
Aug 18, 2021, 1:23:45 PM8/18/21
to Dart Misc
This seems reasonable to me:

class Thing{
  final uuid = Uuid();
String id;

Thing({
this.id = const uuid.v1()
});
}

gives me the error “The prefix uuid can’t be used here because it is shadowed by a local declaration”.

Doesn’t seem to matter if uuid is static, final or anything else.

How do I do this?

Guyren Howe

unread,
Aug 18, 2021, 1:28:38 PM8/18/21
to Dart Misc
Answering my own question:

class Thing{
  final uuid = Uuid();
String id;

Thing({
    String? id
}):
   this.id = id ?? uuid.v1();
}
Reply all
Reply to author
Forward
0 new messages