Skip to content

Commit

Permalink
feat(#59) adiciona storage value
Browse files Browse the repository at this point in the history
Co-authored-by: Yasm1nNasc1mento <yasmin.mn4@gmail.com>
Co-authored-by: dylancavalcante <dylanportelacavalcante@gmail.com>
  • Loading branch information
3 people committed Dec 8, 2024
1 parent b54c3ef commit 51658db
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
55 changes: 55 additions & 0 deletions lib/core/data/local/StorageValue.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:aranduapp/core/log/Log.dart';

class StorageValue {

static const String _authToken = "auth_token";
static const String _refreshToken = "refresh_token";
static const String _email = "email";
static const String _name = "name";

static StorageValue? _singleton;
final FlutterSecureStorage storage;

StorageValue._internal()
: storage = const FlutterSecureStorage(
aOptions: AndroidOptions(encryptedSharedPreferences: true));

factory StorageValue.getInstance() =>
_singleton ??= StorageValue._internal();

Future<void> _setValue(String key, String value) async {
try {
await storage.write(key: key, value: value);
} catch (e) {
Log.e("Error while setting $key: $e");
}
}

Future<String?> _getValue(String key) async {
try {
return await storage.read(key: key);
} catch (e) {
Log.e("Error while getting $key: $e");
return null;
}
}

Future<void> setAuthToken(String token) => _setValue(_authToken, token);
Future<void> setRefreshToken(String token) => _setValue(_refreshToken, token);
Future<void> setEmail(String email) => _setValue(_email, email);
Future<void> setName(String name) => _setValue(_name, name);

Future<String?> getAuthToken() => _getValue(_authToken);
Future<String?> getRefreshToken() => _getValue(_refreshToken);
Future<String?> getEmail() => _getValue(_email);
Future<String?> getName() => _getValue(_name);

Future<void> clear() async {
try {
await storage.deleteAll();
} catch (e) {
Log.e("Error while clearing storage: $e");
}
}
}
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "generated_plugin_registrant.h"

#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import FlutterMacOS
import Foundation

import flutter_secure_storage_macos
import local_auth_darwin
import path_provider_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
FLALocalAuthPlugin.register(with: registry.registrar(forPlugin: "FLALocalAuthPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
}
69 changes: 69 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,64 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.23"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
sha256: "165164745e6afb5c0e3e3fcc72a012fb9e58496fb26ffb92cf22e16a821e85d0"
url: "https://pub.dev"
source: hosted
version: "9.2.2"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
sha256: "4d91bfc23047422cbcd73ac684bc169859ee766482517c22172c86596bf1464b"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
sha256: "1693ab11121a5f925bbea0be725abfcfbbcf36c1e29e571f84a0c0f436147a81"
url: "https://pub.dev"
source: hosted
version: "3.1.2"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
name: flutter_secure_storage_platform_interface
sha256: cf91ad32ce5adef6fba4d736a542baca9daf3beac4db2d04be350b87f69ac4a8
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_secure_storage_web:
dependency: transitive
description:
name: flutter_secure_storage_web
sha256: f4ebff989b4f07b2656fb16b47852c0aab9fed9b4ec1c70103368337bc1886a9
url: "https://pub.dev"
source: hosted
version: "1.2.1"
flutter_secure_storage_windows:
dependency: transitive
description:
name: flutter_secure_storage_windows
sha256: b20b07cb5ed4ed74fc567b78a72936203f587eba460af1df11281c9326cd3709
url: "https://pub.dev"
source: hosted
version: "3.1.2"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
font_awesome_flutter:
dependency: "direct main"
description:
Expand Down Expand Up @@ -171,6 +224,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.19.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -448,6 +509,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
win32:
dependency: transitive
description:
name: win32
sha256: "8b338d4486ab3fbc0ba0db9f9b4f5239b6697fcee427939a40e720cbb9ee0a69"
url: "https://pub.dev"
source: hosted
version: "5.9.0"
xdg_directories:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
local_auth: ^2.3.0
dio: ^5.7.0
font_awesome_flutter: ^10.8.0
flutter_secure_storage: ^9.2.2

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <local_auth_windows/local_auth_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
LocalAuthPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("LocalAuthPlugin"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows
local_auth_windows
)

Expand Down

0 comments on commit 51658db

Please sign in to comment.