Skip to content

0.4.0 - getters for message fields changed

Compare
Choose a tag to compare
@skybrian skybrian released this 15 Jul 23:47
· 793 commits to master since this release

This release changes how getters work for message fields, to detect a common mistake.

Previously, the protobuf API didn't report any error for an incorrect usage of setters. For example, if field "foo" is a message field of type Foo, this code would silently have no effect:

var msg = new SomeMessage();
msg.foo.bar = 123;

This is because "msg.foo" would call "new Foo()" and return it without saving it.

The example can be fixed like this:

var msg = new SomeMessage();
msg.foo = new Foo();
msg.foo.bar = 123;

Or equivalently:

var msg = new SomeMessage()
  ..foo = (new Foo()..bar = 123);

Starting in 0.4.0, the default value of "msg.foo" is an immutable instance of Foo. You can read
the default value of a field the same as before, but writes will throw UnsupportedError.

(You also need version 0.4.0 of dart-protoc-plugin to get the new behavior.)