Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

refactor: remove shared preferences and use memory to save data #1677

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 7 additions & 10 deletions flutter/beagle/lib/default/default_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,28 @@
*/

import 'package:beagle/interface/storage.dart';
import 'package:shared_preferences/shared_preferences.dart';

class DefaultStorage implements Storage {
Map<String, String> storage = {};

@override
Future<void> clear() async {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
storage.clear();
}

@override
Future<String> getItem(String key) async {
final prefs = await SharedPreferences.getInstance();
final result = prefs.getString(key);
return result;
return storage[key];
}

@override
Future<void> removeItem(String key) async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(key);
storage.remove(key);
}

@override
Future<void> setItem(String key, String value) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(key, value);
storage[key] = value;
}

}
1 change: 0 additions & 1 deletion flutter/beagle/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies:
sdk: flutter
flutter_js: ^0.5.0+0
get_it: ^7.1.3
shared_preferences: ^2.0.6
url_launcher: ^6.0.6

dev_dependencies:
Expand Down
2 changes: 0 additions & 2 deletions flutter/beagle/test/default/default_storage_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

import 'package:beagle/default/default_storage.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
group('Given a DefaultStorage', () {
SharedPreferences.setMockInitialValues({});
final defaultStorage = DefaultStorage();
group('When setItem is called', () {
test('Then it should store the value for the key', () async {
Expand Down