Skip to content

[shared_preferences] Documented return values for remove and set methods. - #7198

Closed
RamonFarizel wants to merge 11 commits into
flutter:mainfrom
RamonFarizel:ramonfarizel/fix-docs
Closed

[shared_preferences] Documented return values for remove and set methods.#7198
RamonFarizel wants to merge 11 commits into
flutter:mainfrom
RamonFarizel:ramonfarizel/fix-docs

Conversation

@RamonFarizel

@RamonFarizel RamonFarizel commented Jul 22, 2024

Copy link
Copy Markdown
Contributor

This PR adds documentation about the remove and set methods.
Those methods are basically following the get methods patterns, they throw an exception when the type is not expected.
Also, returns true when the operation succeeded.

List which issues are fixed by this PR. You must list at least one issue.
fixes: #146070

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@tarrinneal

Copy link
Copy Markdown
Contributor

All of the changelogs and pubspecs changes for the sub packages (android, foundation, etc) should be reverted. Only the subpackages with changes need them.

@tarrinneal

Copy link
Copy Markdown
Contributor

I'm of the opinion that these changes to the doc comments aren't necessary, as the methods are self documenting.

You can't call setString with anything that isn't a string. Same with the other set methods.

The "returns true" comments are unfortunately not exactly correct, as some platforms don't actually have any response that verifies success. If I were to design this api myself today, I wouldn't have any bool returns for that reason.

@stuartmorgan what do you think?

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

as the methods are self documenting

I don't think the return value is self-documenting; I literally had to go back and read every platform's implementation to figure out what it actually does, and I wrote several of those implementations.

I think it's worth trying to describe the reality of what they do as best we can, which I agree the proposed language doesn't do because of the differences across platforms. The best we can do is probably something like:

/// Returns `false` if the platform implementation can definitively determine that storing the preference
/// failed. A return value of `true` indicates either that the value was written successfully, or that the
/// underlying platform API does not report success or failure.

You can't call setString with anything that isn't a string. Same with the other set methods.

Yes, those parts of the additions are not correct; the cases described would not compile, so could not throw at runtime.

@RamonFarizel

Copy link
Copy Markdown
Contributor Author

Thanks for your thoughts, folks.

So if we are moving with updating the docs, what do you think is the best approach?

  1. Should we have this message repeated for all set and remove methods?
  2. Only a single message mentioning that this is useful for all those methods?

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Unless something is part of the comment directly on a method, it won't show up in IDE tools, and it will be harder to find even when looking at the header manually, so far fewer people would see anything added anywhere but to each method.

@RamonFarizel

Copy link
Copy Markdown
Contributor Author

Okay, I've implemented the changes.

@RamonFarizel
RamonFarizel deleted the ramonfarizel/fix-docs branch August 5, 2024 22:40
binSaed added a commit to binSaed/packages that referenced this pull request Jul 28, 2026
Add dartdoc to setBool, setInt, setDouble, setString, setStringList,
and remove explaining the meaning of their return values, using the
wording suggested by @stuartmorgan-g in the closed PR flutter#7198.

Fixes flutter/flutter#146070
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[shared_preferences] document return values of remove and set... methods

3 participants