Commit 07b904f3 authored by Andrea Ruiz's avatar Andrea Ruiz 👽
Browse files

Implement riverpod identity provider

parent 601ff51d
Pipeline #611262274 failed
import 'package:elRepoIo/rs_service/rscontrol.dart';
import 'package:elRepoIo/ui/providers/autoupdate.dart';
import 'package:elRepoIo/ui/providers/identities_provider.dart';
import 'package:elRepoIo/user_preferences.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:elrepo_lib/repo.dart' as repo;
import 'package:elrepo_lib/cache.dart' as caches;
import 'package:flutter/foundation.dart' show defaultTargetPlatform, TargetPlatform;
import 'rs_folders_control.dart';
......@@ -52,6 +54,11 @@ class LoginHelper {
// await RsFoldersControl.prepareSystemDirectories();
if(USER_PREFERENCES.RS_CREDENTIALS != creds) setRsCredentials(creds.location, creds.secret);
// Override identity cache to update ui using riverpod.
// See [RiverpodIdentitesCacheNotifier] docs
caches.Caches.identitiesCache =;
// Start befriending with tiers, some caches...
// Initialize the connectivity settings after RS login so we can set rates.
......@@ -24,6 +24,8 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:retroshare_dart_wrapper/rs_models.dart';
import 'package:elrepo_lib/repo.dart' as repo;
import 'package:retroshare_dart_wrapper/retroshare.dart' as rs;
import 'package:elrepo_lib/cache.dart';
final ownIdentityProvider = StateNotifierProvider<OwnIdentityNotifier, Identity>((ref) {
return OwnIdentityNotifier();
......@@ -52,9 +54,47 @@ class OwnIdentityNotifier extends UpdatableNotifier<Identity> {
final cachedIdentityProvider =<Identity?, String>((ref, rsGxsId) {
final _identitesProvider = Provider<repo.Identities>((ref,) {
return repo.Identities();
\ No newline at end of file
final identitiesProvider = StateNotifierProvider<RiverpodIdentitesCacheNotifier, Map<String, Identity>>((ref) {
return RiverpodIdentitesCacheNotifier();
/// This class is also an override of the [IdentitesCache], overrided during
/// login.
/// This is one of the paths we found to bring compatibility between Riverpod
/// and elRepo-lib without giving Riverpod dependency to elRepo-lib. This cache
/// is not called only from the UI, also is called from the elRepo-lib inner
/// functions, so on this way we can update the UI wherever this cache is
/// updated.
/// Other way to do that is to create a IdentityCacheRepository that implements
/// a [IdentitesCache] with [Ref] object passed on the constructor. On this way
/// we could update other providers from there.
/// (Aruru)
class RiverpodIdentitesCacheNotifier extends StateNotifier<Map<String, Identity>> with IdentitesCache {
RiverpodIdentitesCacheNotifier() : super({});
/// Map that store [Identity.mId] and [Identity]
// var _rsGxsToIdentityMap = <String, Identity>{};
Map<String, Identity> get rsGxsToIdentityMap => state;
/// From [idList] update [_rsGxsToIdentityMap]
Future<void> _updateRsGxsToIdentityMap(List<Identity> idList) async{
print('Updating getIdentitiesSummaries cache');
state = {for (var e in idList) e.mId: e};
Future<List<Identity>> updateSummaries() async {
var idSummaries = await rs.RsIdentity.getIdentitiesSummaries();
return idSummaries;
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment