Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.1

* Fixes `getStringList` returning immutable list.

## 2.3.0

* Adds new `SharedPreferencesAsyncAndroid` API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ void main() {
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});

testWidgets('getStringList returns mutable list', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
final List<String>? list =
await preferences.getStringList(listKey, emptyOptions);
list?.add('value');
expect(list?.length, testList.length + 1);
});

testWidgets('getPreferences', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();
await Future.wait(<Future<void>>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ base class SharedPreferencesAsyncAndroid
// is fixed. In practice, the values will never be null, and the native implementation assumes that.
return _convertKnownExceptions<List<String>>(() async =>
(await _api.getStringList(key, _convertOptionsToPigeonOptions(options)))
?.cast<String>());
?.cast<String>()
.toList());
}

Future<T?> _convertKnownExceptions<T>(Future<T?> Function() method) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences_android
description: Android implementation of the shared_preferences plugin
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
version: 2.3.0
version: 2.3.1

environment:
sdk: ^3.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.5.1

* Fixes `getStringList` returning immutable list.
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 2.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,16 @@ void main() {
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});

testWidgets('getStringList returns mutable list', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
final List<String>? list =
await preferences.getStringList(listKey, emptyOptions);
list?.add('value');
expect(list?.length, testList.length + 1);
});

testWidgets('getPreferences', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();
await Future.wait(<Future<void>>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ base class SharedPreferencesAsyncFoundation
return _convertKnownExceptions<List<String>>(() async =>
((await _api.getValue(key, _convertOptionsToPigeonOptions(options)))
as List<Object?>?)
?.cast<String>());
?.cast<String>()
.toList());
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences_foundation
description: iOS and macOS implementation of the shared_preferences plugin.
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_foundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
version: 2.5.0
version: 2.5.1

environment:
sdk: ^3.3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 2.4.1

* Fixes `getStringList` returning immutable list.
* Fixes `getStringList` cast error.
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 2.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,15 @@ void main() {
const double testDouble = 3.14159;
const List<String> testList = <String>['foo', 'bar'];

Future<SharedPreferencesAsyncPlatform> getPreferences() async {
Future<SharedPreferencesAsyncPlatform> getPreferences(
{bool clear = true}) async {
final SharedPreferencesAsyncPlatform preferences =
SharedPreferencesAsyncPlatform.instance!;
await preferences.clear(
const ClearPreferencesParameters(filter: PreferencesFilters()),
emptyOptions);
if (clear) {
await preferences.clear(
const ClearPreferencesParameters(filter: PreferencesFilters()),
emptyOptions);
}
return preferences;
}

Expand Down Expand Up @@ -397,6 +400,24 @@ void main() {
await preferences.setStringList(listKey, testList, emptyOptions);
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});
testWidgets('getStringList does not throw cast error',
(WidgetTester _) async {
SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
preferences = await getPreferences(clear: false);
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});

testWidgets('getStringList returns mutable list', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
final List<String>? list =
await preferences.getStringList(listKey, emptyOptions);
list?.add('value');
expect(list?.length, testList.length + 1);
});

testWidgets('getPreferences', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences_linux
description: Linux implementation of the shared_preferences plugin
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_linux
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
version: 2.4.0
version: 2.4.1

environment:
sdk: ^3.3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.4.2

* Fixes `getStringList` returning immutable list.
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.

## 2.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ void main() {
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});

testWidgets('getStringList returns mutable list', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
final List<String>? list =
await preferences.getStringList(listKey, emptyOptions);
list?.add('value');
expect(list?.length, testList.length + 1);
});

testWidgets('getPreferences', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();
await Future.wait(<Future<void>>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ base class SharedPreferencesAsyncWeb extends SharedPreferencesAsyncPlatform {
) async {
final Map<String, Object> data =
await _readAllFromLocalStorage(<String>{key}, options);
return data[key] as List<String>?;
return (data[key] as List<String>?)?.toList();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences_web
description: Web platform implementation of shared_preferences
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
version: 2.4.1
version: 2.4.2

environment:
sdk: ^3.4.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 2.4.1

* Fixes `getStringList` returning immutable list.
* Fixes `getStringList` cast error.
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 2.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,15 @@ void main() {
const double testDouble = 3.14159;
const List<String> testList = <String>['foo', 'bar'];

Future<SharedPreferencesAsyncPlatform> getPreferences() async {
Future<SharedPreferencesAsyncPlatform> getPreferences(
{bool clear = true}) async {
final SharedPreferencesAsyncPlatform preferences =
SharedPreferencesAsyncPlatform.instance!;
await preferences.clear(
const ClearPreferencesParameters(filter: PreferencesFilters()),
emptyOptions);
if (clear) {
await preferences.clear(
const ClearPreferencesParameters(filter: PreferencesFilters()),
emptyOptions);
}
return preferences;
}

Expand Down Expand Up @@ -397,6 +400,24 @@ void main() {
await preferences.setStringList(listKey, testList, emptyOptions);
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});
testWidgets('getStringList does not throw cast error',
(WidgetTester _) async {
SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
preferences = await getPreferences(clear: false);
expect(await preferences.getStringList(listKey, emptyOptions), testList);
});

testWidgets('getStringList returns mutable list', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();

await preferences.setStringList(listKey, testList, emptyOptions);
final List<String>? list =
await preferences.getStringList(listKey, emptyOptions);
list?.add('value');
expect(list?.length, testList.length + 1);
});

testWidgets('getPreferences', (WidgetTester _) async {
final SharedPreferencesAsyncPlatform preferences = await getPreferences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences_windows
description: Windows implementation of shared_preferences
repository: https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences_windows
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+shared_preferences%22
version: 2.4.0
version: 2.4.1

environment:
sdk: ^3.3.0
Expand Down