-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to actually resolve the copyWith
deprecation warnings?
#503
Comments
I can't found any good way to fix update. So I only copy my test code to you for reference. void main(List<String> args) {
var ruler = StaticDataPool.rulers[0];
var any = Any(value: ruler.data.value, typeUrl: ruler.data.typeUrl);
print(any.canUnpackInto(RulerId.getDefault()));
var unpackInto = any.unpackInto(RulerId());
// older copy
var copyWith = unpackInto.clone();
copyWith = unpackInto.copyWith((a) {
a.ruleName = '.scdae';
});
// new copy
var newData =
GeneratedMessageGenericExtensions<RulerId>(unpackInto).deepCopy();
newData = GeneratedMessageGenericExtensions<RulerId>(unpackInto)
.rebuild((unpackInto) {
unpackInto.ruleName = 'cdsce';
});
} |
I'm guessing you meant I don't know why generated Are you sure you're not using |
I recently facing to the same problem and confused about the warning. After a deep dive, I believe the point is the document and/or warning message didn't mention I need to import
@osa1 sorry for ping. I think it can helps a lot if you could provide more guidance here/or somewhere else. |
@MuZhou233 I think we should export the extension in the generated files. I've implemented this in #907. The PR (and a release) may have to wait until the next year as some of the devs are on vacation, and we may also want to finish and include #905 in the release as well. |
Currently when a user calls deprecated methods `clone` or `copyWith`, the deprecation message points to `GeneratedMessageGenericExtensions` `deepCopy` and `rebuild` methods. However we can't just replace `clone` with `deepCopy` as currently the extension is not exported by the generated files. Instead we need to import the library explicitly in the use site. We could mention this in the deprecation message ("Use rebuild from protobuf library instead"), but it's more convenient to just export the extension in the generated message files. Closes #503.
Heeding the warning from my linter, I've upgraded to using
libprotoc 3.15.8
andprotoc_plugin 20.0.0
to generate myfoo.pb.dart
files in the hopes thatcopyWith
will no longer be used in my generated files and I can future proof my application, as well as hopefully reduce bundle size.However generating my files simply adds deprecation annotations, but doesn't use the recommended method
GeneratedMessageGenericExtensions.deepCopy
. Am I missing something obvious to fix this deprecated method usage? AFAIK the plugin should be doing this for me when I generate these files.My current Dart/Flutter:
Thanks in advance for your guidance! I must add that up until now this has been working amazingly and I'm super thankful for this package.
The text was updated successfully, but these errors were encountered: