Skip to content

Commit

Permalink
Add an assert to make sure native implementations only return flutter…
Browse files Browse the repository at this point in the history
… prefs (flutter#106)

* Adding object storage support.

* Reverting most of the object API changes, making prefix check an assert.
gspencergoog authored and goderbauer committed Jun 9, 2017
1 parent 6243415 commit 647bd56
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/shared_preferences/lib/shared_preferences.dart
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ class SharedPreferences {
// Strip the flutter. prefix from the returned preferences.
final Map<String, Object> preferencesMap = <String, Object>{};
for (String key in fromSystem.keys) {
assert(key.startsWith(_prefix));
preferencesMap[key.substring(_prefix.length)] = fromSystem[key];
}
_instance = new SharedPreferences._(preferencesMap);
@@ -76,7 +77,7 @@ class SharedPreferences {
/// Saves a string [value] to persistent storage in the background.
void setString(String key, String value) => _setValue('String', key, value);

/// Saves a set of string [value] to persistent storage in the background.
/// Saves a list of strings [value] to persistent storage in the background.
void setStringList(String key, List<String> value) =>
_setValue('StringList', key, value);

@@ -96,9 +97,7 @@ class SharedPreferences {
/// ensure the preferences have been modified in memory. Commit is necessary
/// only if you need to be absolutely sure that the data is in persistent
/// storage before taking some other action.
Future<bool> commit() async {
return await _kChannel.invokeMethod('commit');
}
Future<bool> commit() async => await _kChannel.invokeMethod('commit');

/// Completes with true once the user preferences for the app has been cleared.
Future<bool> clear() async {
4 changes: 4 additions & 0 deletions packages/shared_preferences/test/shared_preferences_test.dart
Original file line number Diff line number Diff line change
@@ -46,6 +46,10 @@ void main() {
log.clear();
});

tearDown(() {
sharedPreferences.clear();
});

test('reading', () async {
expect(
sharedPreferences.getString('String'), kTestValues['flutter.String']);

0 comments on commit 647bd56

Please sign in to comment.