PostHog last fixes hopefully
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
@@ -20,6 +22,8 @@ import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class AccountProvider extends ChangeNotifier {
|
||||
AccountProvider();
|
||||
|
||||
static String get currentUserRef => Constants.nilObjectRef;
|
||||
|
||||
// The resource now wraps our Account? state along with its loading/error state.
|
||||
@@ -27,6 +31,7 @@ class AccountProvider extends ChangeNotifier {
|
||||
Resource<Account?> get resource => _resource;
|
||||
late LocaleProvider _localeProvider;
|
||||
PendingLogin? _pendingLogin;
|
||||
Future<void>? _restoreFuture;
|
||||
|
||||
Account? get account => _resource.data;
|
||||
PendingLogin? get pendingLogin => _pendingLogin;
|
||||
@@ -52,9 +57,18 @@ class AccountProvider extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
// Private helper to update the resource and notify listeners.
|
||||
@protected
|
||||
Future<void> onAccountChanged(Account? previous, Account? current) => Future<void>.value();
|
||||
|
||||
void _setResource(Resource<Account?> newResource) {
|
||||
final previousAccount = _resource.data;
|
||||
_resource = newResource;
|
||||
final currentAccount = newResource.data;
|
||||
|
||||
if (previousAccount != currentAccount) {
|
||||
unawaited(onAccountChanged(previousAccount, currentAccount));
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -220,4 +234,11 @@ class AccountProvider extends ChangeNotifier {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> restoreIfPossible() {
|
||||
return _restoreFuture ??= AuthorizationService.isAuthorizationStored().then<void>((hasAuth) async {
|
||||
if (!hasAuth) return;
|
||||
await restore();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user