-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[shared_preferences] Add shared preferences devtools #6749
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
Merged
auto-submit
merged 86 commits into
flutter:main
from
adsonpleal:add-shared-preferences-devtools
Dec 16, 2024
Merged
Changes from all commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
9a98dce
Add shared preferences devtools
adsonpleal f6a1ce9
Add docs
adsonpleal b9c0b6b
change version constraint
adsonpleal e2f1478
update readme
adsonpleal b798091
pr requested changes
adsonpleal 0115bea
fix broken test
adsonpleal 421d981
remove icons from manifest
adsonpleal bf23f70
Use InheritedModel to avoid unnecessary rebuilds
adsonpleal 2402e78
change search bar
adsonpleal 215d551
PR requested changes
adsonpleal 18ac82b
Fix wrong change
adsonpleal 16f30fc
add TestOn annotations
adsonpleal c14409e
lint fix and update dependencies
adsonpleal 382f612
revert vm_service version change
adsonpleal aba50c5
fix licenses
adsonpleal a118924
solve some CI checks
adsonpleal 0604550
Add web unavailable message
adsonpleal eb6dc64
Add codeowners and allowed unpinned deps
adsonpleal c9dab29
PR requested changes
adsonpleal 1627ec8
update codeowners
adsonpleal c7c3eb5
fix typo
adsonpleal bb58727
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal ee1d2f4
Remove chared preferences changes and change codeowners
adsonpleal 01d7f5c
Remove asyncEval call
adsonpleal 39b3990
remove commented code
adsonpleal 00e568c
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 21202e6
pr requested changes
adsonpleal e489086
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal c32457f
Merge branch 'main' into add-shared-preferences-devtools
stuartmorgan-g c6c8068
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal c4be218
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 862938b
Add pre_publish.dart and extension config.yaml to shared_preferences
adsonpleal 84c6103
fix changelog and license validations
adsonpleal 866ef50
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 7b1a151
Support new API and update changelog
adsonpleal bffbe95
also update the version in pubspec
adsonpleal d8af525
Merge remote-tracking branch 'origin/main' into add-shared-preference…
adsonpleal 26f186b
revert changes to pubspec
adsonpleal 8b005d9
add empty line back to pubspec
adsonpleal 2dc2a33
update minor version
adsonpleal 5b7cbbf
Fix android support
adsonpleal c497026
Add api switcher
adsonpleal bc887de
add missing license
adsonpleal ffd64a9
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal e95d285
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal ed56a14
resolve conflicts
adsonpleal 8936da6
Merge branch 'add-shared-preferences-devtools' of github.com:adsonple…
adsonpleal 966d0fc
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 3267c1b
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 1acebd4
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 3846f73
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 6eb1b4f
Merge remote-tracking branch 'origin/main' into add-shared-preference…
adsonpleal d3fea9e
Merge branch 'flutter:main' into add-shared-preferences-devtools
adsonpleal af0dfca
Add devtool_eval_test to shared_preferences
adsonpleal 107fc82
apply requested changes to devtools_eval_test
adsonpleal 4b2f619
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 6abec8a
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal a45bc1c
Add license header to devtools_eval_test
adsonpleal c1a9c85
Update libraries
adsonpleal 612e118
Merge branch 'add-shared-preferences-devtools' of github.com:adsonple…
adsonpleal ea80fce
remove error holder
adsonpleal 1ef04f6
remove error holder
adsonpleal 4df0393
replace text with circular progress indicator
adsonpleal 2f8e7ea
fix broken test
adsonpleal b77893c
Apply suggested changes
adsonpleal 7a3ec34
Merge remote-tracking branch 'origin/main' into add-shared-preference…
adsonpleal e9b913c
add devtools_extension.dart file
adsonpleal 8362269
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 119df62
update pre_publish.dart
adsonpleal 38954ba
pin vm service version
adsonpleal e3c39f2
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal 9f7cdd4
Fix mockito generated code
adsonpleal 026b225
Merge branch 'add-shared-preferences-devtools' of github.com:adsonple…
adsonpleal 659b9cd
Change vm_service version
adsonpleal 7bd20c1
Merge remote-tracking branch 'origin/main' into add-shared-preference…
adsonpleal d672329
add missing license
adsonpleal e6da5b8
add path as a dev_dependency
adsonpleal 3c5cecd
change path version
adsonpleal c761404
requested changes
adsonpleal 2b7d31f
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal c80795a
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal bb0b9be
rename lib/src/shared_preferences_dev_tools_extension_data.dart to li…
adsonpleal 4f6e93b
Merge branch 'add-shared-preferences-devtools' of github.com:adsonple…
adsonpleal 4f2d2fd
rename test file
adsonpleal 9838731
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal a783959
Merge branch 'main' into add-shared-preferences-devtools
adsonpleal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.4.0 | ||
|
||
* Adds shared preferences devtools extension | ||
|
||
## 2.3.3 | ||
|
||
* Clarifies scope of prefix handling in README. | ||
|
1 change: 1 addition & 0 deletions
1
packages/shared_preferences/shared_preferences/extension/devtools/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build | ||
1 change: 1 addition & 0 deletions
1
packages/shared_preferences/shared_preferences/extension/devtools/.pubignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!build | ||
adsonpleal marked this conversation as resolved.
Show resolved
Hide resolved
|
4 changes: 4 additions & 0 deletions
4
packages/shared_preferences/shared_preferences/extension/devtools/config.yaml
adsonpleal marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: shared_preferences | ||
issueTracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22 | ||
kenzieschmoll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
version: 1.0.0 | ||
materialIconCodePoint: '0xe683' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...ed_preferences/shared_preferences/lib/src/shared_preferences_devtools_extension_data.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:convert'; | ||
import 'dart:developer' as developer; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
|
||
import '../shared_preferences.dart'; | ||
|
||
const String _eventPrefix = 'shared_preferences.'; | ||
|
||
/// A typedef for the post event function. | ||
@visibleForTesting | ||
typedef PostEvent = void Function( | ||
String eventKind, | ||
Map<String, Object?> eventData, | ||
); | ||
|
||
/// A helper class that provides data to the DevTools extension. | ||
/// | ||
/// It is only visible for testing and eval. | ||
@visibleForTesting | ||
class SharedPreferencesDevToolsExtensionData { | ||
/// The default constructor for [SharedPreferencesDevToolsExtensionData]. | ||
/// | ||
/// Accepts an optional [PostEvent] that should only be overwritten when testing. | ||
const SharedPreferencesDevToolsExtensionData([ | ||
this._postEvent = developer.postEvent, | ||
]); | ||
|
||
final PostEvent _postEvent; | ||
|
||
/// Requests all legacy and async keys and post an event with the result. | ||
Future<void> requestAllKeys() async { | ||
final SharedPreferences legacyPrefs = await SharedPreferences.getInstance(); | ||
final Set<String> legacyKeys = legacyPrefs.getKeys(); | ||
final Set<String> asyncKeys = await SharedPreferencesAsync().getKeys(); | ||
|
||
_postEvent('${_eventPrefix}all_keys', <String, List<String>>{ | ||
'asyncKeys': asyncKeys.toList(), | ||
'legacyKeys': legacyKeys.toList(), | ||
}); | ||
} | ||
|
||
/// Requests the value for a given key and posts an event with the result. | ||
Future<void> requestValue(String key, bool legacy) async { | ||
final Object? value; | ||
if (legacy) { | ||
final SharedPreferences legacyPrefs = | ||
await SharedPreferences.getInstance(); | ||
value = legacyPrefs.get(key); | ||
} else { | ||
value = await SharedPreferencesAsync().getAll(allowList: <String>{ | ||
key | ||
}).then((Map<String, Object?> map) => map.values.firstOrNull); | ||
} | ||
|
||
_postEvent('${_eventPrefix}value', <String, Object?>{ | ||
'value': value, | ||
// It is safe to use `runtimeType` here. This code | ||
// will only ever run in debug mode. | ||
'kind': value.runtimeType.toString(), | ||
}); | ||
} | ||
|
||
/// Requests the value change for the given key and posts an empty event when finished. | ||
Future<void> requestValueChange( | ||
String key, | ||
String serializedValue, | ||
String kind, | ||
bool legacy, | ||
) async { | ||
final Object? value = jsonDecode(serializedValue); | ||
if (legacy) { | ||
final SharedPreferences legacyPrefs = | ||
await SharedPreferences.getInstance(); | ||
// we need to check the kind because sometimes a double | ||
// gets interpreted as an int. If this was not an issue | ||
// we'd only need to do a simple pattern matching on value. | ||
switch (kind) { | ||
case 'int': | ||
await legacyPrefs.setInt(key, value! as int); | ||
case 'bool': | ||
await legacyPrefs.setBool(key, value! as bool); | ||
case 'double': | ||
await legacyPrefs.setDouble(key, value! as double); | ||
case 'String': | ||
await legacyPrefs.setString(key, value! as String); | ||
case 'List<String>': | ||
await legacyPrefs.setStringList( | ||
key, | ||
(value! as List<Object?>).cast(), | ||
); | ||
} | ||
} else { | ||
final SharedPreferencesAsync prefs = SharedPreferencesAsync(); | ||
// we need to check the kind because sometimes a double | ||
// gets interpreted as an int. If this was not an issue | ||
// we'd only need to do a simple pattern matching on value. | ||
switch (kind) { | ||
case 'int': | ||
await prefs.setInt(key, value! as int); | ||
case 'bool': | ||
await prefs.setBool(key, value! as bool); | ||
case 'double': | ||
await prefs.setDouble(key, value! as double); | ||
case 'String': | ||
await prefs.setString(key, value! as String); | ||
case 'List<String>': | ||
await prefs.setStringList( | ||
key, | ||
(value! as List<Object?>).cast(), | ||
); | ||
} | ||
} | ||
_postEvent('${_eventPrefix}change_value', <String, Object?>{}); | ||
} | ||
|
||
/// Requests a key removal and posts an empty event when removed. | ||
Future<void> requestRemoveKey(String key, bool legacy) async { | ||
if (legacy) { | ||
final SharedPreferences legacyPrefs = | ||
await SharedPreferences.getInstance(); | ||
await legacyPrefs.remove(key); | ||
} else { | ||
await SharedPreferencesAsync().remove(key); | ||
} | ||
_postEvent('${_eventPrefix}remove', <String, Object?>{}); | ||
} | ||
} | ||
|
||
/// Include a variable to keep the library alive in web builds. | ||
/// It must be a `final` variable. | ||
/// Check this discussion for more info: https://github.com/flutter/packages/pull/6749/files/6eb1b4fdce1eba107294770d581713658ff971e9#discussion_r1755375409 | ||
// ignore: prefer_const_declarations | ||
final bool fieldToKeepDevtoolsExtensionLibraryAlive = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.