diff --git a/packages/shared_preferences/shared_preferences_web/CHANGELOG.md b/packages/shared_preferences/shared_preferences_web/CHANGELOG.md index 747f25adc43f..6d6a106370bb 100644 --- a/packages/shared_preferences/shared_preferences_web/CHANGELOG.md +++ b/packages/shared_preferences/shared_preferences_web/CHANGELOG.md @@ -1,6 +1,7 @@ -## NEXT +<<<<<<< HEAD +## 2.2.2 -* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. +* Updates minimum supported SDK version to Dart 3.2. ## 2.2.1 diff --git a/packages/shared_preferences/shared_preferences_web/lib/shared_preferences_web.dart b/packages/shared_preferences/shared_preferences_web/lib/shared_preferences_web.dart index 34c33ce82cfd..10bea9e2b369 100644 --- a/packages/shared_preferences/shared_preferences_web/lib/shared_preferences_web.dart +++ b/packages/shared_preferences/shared_preferences_web/lib/shared_preferences_web.dart @@ -4,11 +4,11 @@ import 'dart:async'; import 'dart:convert' show json; -import 'dart:html' as html; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart'; import 'package:shared_preferences_platform_interface/types.dart'; +import 'package:web/web.dart' as html; /// The web implementation of [SharedPreferencesStorePlatform]. /// @@ -69,20 +69,20 @@ class SharedPreferencesPlugin extends SharedPreferencesStorePlatform { final Map allData = {}; for (final String key in _getFilteredKeys(filter.prefix, allowList: filter.allowList)) { - allData[key] = _decodeValue(html.window.localStorage[key]!); + allData[key] = _decodeValue(html.window.localStorage.getItem(key)!); } return allData; } @override Future remove(String key) async { - html.window.localStorage.remove(key); + html.window.localStorage.removeItem(key); return true; } @override Future setValue(String valueType, String key, Object? value) async { - html.window.localStorage[key] = _encodeValue(value); + html.window.localStorage.setItem(key, _encodeValue(value)); return true; } @@ -111,3 +111,12 @@ class SharedPreferencesPlugin extends SharedPreferencesStorePlatform { return decodedValue!; } } + +extension on html.Storage { + void remove(String item) => removeItem(item); + Iterable get keys sync* { + for (int i = 0; i < html.window.localStorage.length; i++) { + yield html.window.localStorage.key(i)!; + } + } +} diff --git a/packages/shared_preferences/shared_preferences_web/pubspec.yaml b/packages/shared_preferences/shared_preferences_web/pubspec.yaml index 2a64a80e09c6..ceb1dfebcf7a 100644 --- a/packages/shared_preferences/shared_preferences_web/pubspec.yaml +++ b/packages/shared_preferences/shared_preferences_web/pubspec.yaml @@ -2,11 +2,11 @@ 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.2.1 +version: 2.2.2 environment: - sdk: ">=3.0.0 <4.0.0" - flutter: ">=3.10.0" + sdk: ">=3.2.0 <4.0.0" + flutter: ">=3.16.0" flutter: plugin: @@ -22,6 +22,7 @@ dependencies: flutter_web_plugins: sdk: flutter shared_preferences_platform_interface: ^2.3.0 + web: '>=0.3.0 <0.5.0' dev_dependencies: flutter_test: