Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[shared_preferences] Documentation update for Readme.md#4684

Merged
fluttergithubbot merged 10 commits intoflutter:mainfrom
CodemateLtd:update_shared_prefs_docs_example
Feb 4, 2022
Merged

[shared_preferences] Documentation update for Readme.md#4684
fluttergithubbot merged 10 commits intoflutter:mainfrom
CodemateLtd:update_shared_prefs_docs_example

Conversation

@jpsiitonen
Copy link
Contributor

@jpsiitonen jpsiitonen commented Jan 21, 2022

Update for documentation on readme file:

  • Improved documentation details about plugin
  • Added short API usage examples for shared preferences API usage.

Fixes flutter/flutter#96993

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

and there is no guarantee that writes will be persisted to disk after
returning, so this plugin must not be used for storing critical data.

Although key-value storage is easy and convenient to use, it has limitations:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limitations relative to what? Only allowing specific types of data is not unusual, for instance.

I'm not sure this sentence adds anything, really. "easy and convenient" seems very subjective, and again I'm not sure what it's being compared to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, may be not the best words to describe. Dropping sentence out..

returning, so this plugin must not be used for storing critical data.

Although key-value storage is easy and convenient to use, it has limitations:
* Only primitive types can be used: `int`, `double`, `bool`, `String`, and `StringList`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know "primitive types" is not a meaningful term in Dart. I would just list the supported types without trying to editorialize it as a limitation, or trying to use a term to describe them. (I don't think the latter is even possible I can't imagine any term that would encompas lists of strings but not lists of doubles, for instance.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, yes, re-phrased this.

returning, so this plugin must not be used for storing critical data.

Although key-value storage is easy and convenient to use, it has limitations:
* Only primitive types can be used: `int`, `double`, `bool`, `String`, and `StringList`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no Dart type StringList.

Although key-value storage is easy and convenient to use, it has limitations:
* Only primitive types can be used: `int`, `double`, `bool`, `String`, and `StringList`.
* It’s not designed to store a lot of data.
* No encryption for data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially misleading, since on some platforms all data is encrypted at some level. I don't think we need to discuss encryption at all.

final success = await prefs.clear();
```

### Sample Usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no real difference in meaning between "Examples" and "Sample Usage", so having both is confusing.

Since almost everything in the code below is irrelevant, and anyone wanting that kind of example has the Example tab on pub.dev, I would just remove this whole section in favor of the above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would focus more on simple examples here. That's true that simple example app is accessible and easier to read via pub.dev. Thanks for feedback.

SharedPreferences.setMockInitialValues(values);
```

### Storage location on platforms
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/on platforms/by platform/

| :--- | :--- |
| Android | SharedPreferences |
| iOS | NSUserDefaults |
| Linux | LocalFileSystem |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the name of the class that abstracts the filesystem in Dart is a meaningful description. Saying "In the XDG_DATA_HOME directory" would be a lot more meaningful.

| Linux | LocalFileSystem |
| MacOS | NSUserDefaults |
| Web | LocalStorage |
| Windows | LocalFileSystem |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with Linux: "In the roaming AppData directory"

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparrishMines for secondary review.


#### Remove an entry
```dart
// Remove data from the provided key.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/from/for/

Also, in all the comments above you used the name of the key rather than saying "the provided key", and this should be consistent.


#### Read data
```dart
final SharedPreferences prefs = await _prefs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what _prefs is supposed to be here. Why is the code for getting the shared preferences different in this example from the example above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, my bad.

| Web | LocalStorage |
| Windows | In the roaming AppData directory |

[example]:./example No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be dead code.

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p: shared_preferences waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[shared_preferences] Documentation improvement for Readme.md

4 participants