Dart: protobuf - nested fields

At the moment I'm working on a dart-client for nakama which defines the transport-layer-messages via protobuf. Nakama uses quite a lot StringValue ( a wrapper the encapsulates a string ).

e.g. something like following is generated:


class UpdateAccountRequest extends $pb.GeneratedMessage {
  ....

  @$pb.TagNumber(1)
  $1.StringValue get username => $_getN(0);
  @$pb.TagNumber(1)
  set username($1.StringValue v) { setField(1, v); }
  @$pb.TagNumber(1)
  $core.bool hasUsername() => $_has(0);
  @$pb.TagNumber(1)
  void clearUsername() => clearField(1);
  @$pb.TagNumber(1)
  $1.StringValue ensureUsername() => $_ensure(0);
  ...
}

At first I tried something like this:

var req=UpdateAccountRequest()..username.value='name' ❌

That threw errors that this field is readonly!? Gave me a hard time...
But after a bit of search I found the solution. Obviously the Wrapper-Type still needs to be created. 😅

var req=UpdateAccountRequest()..username=StringValue()..value='name' 👌

...if it would be any other class it would be a no-brainer to create the instance but for some reason the wrapper-type clouded me and writing this down let feel, that it is time to end the day 😉