Fixes for PostHog
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,9 @@ import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class AccountProvider extends ChangeNotifier {
|
||||
AccountProvider({Future<void> Function(Account?)? onAccountChanged})
|
||||
: _onAccountChanged = onAccountChanged;
|
||||
|
||||
static String get currentUserRef => Constants.nilObjectRef;
|
||||
|
||||
// The resource now wraps our Account? state along with its loading/error state.
|
||||
@@ -27,6 +32,8 @@ class AccountProvider extends ChangeNotifier {
|
||||
Resource<Account?> get resource => _resource;
|
||||
late LocaleProvider _localeProvider;
|
||||
PendingLogin? _pendingLogin;
|
||||
Future<void>? _restoreFuture;
|
||||
Future<void> Function(Account?)? _onAccountChanged;
|
||||
|
||||
Account? get account => _resource.data;
|
||||
PendingLogin? get pendingLogin => _pendingLogin;
|
||||
@@ -53,11 +60,21 @@ class AccountProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// Private helper to update the resource and notify listeners.
|
||||
void setAccountChangedListener(Future<void> Function(Account?)? listener) => _onAccountChanged = listener;
|
||||
|
||||
void _setResource(Resource<Account?> newResource) {
|
||||
final previousAccount = _resource.data;
|
||||
_resource = newResource;
|
||||
_notifyAccountChanged(previousAccount, newResource.data);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _notifyAccountChanged(Account? previous, Account? current) {
|
||||
if (previous == current) return;
|
||||
final handler = _onAccountChanged;
|
||||
if (handler != null) unawaited(handler(current));
|
||||
}
|
||||
|
||||
void updateProvider(LocaleProvider localeProvider) => _localeProvider = localeProvider;
|
||||
|
||||
void _pickupLocale(String locale) => _localeProvider.setLocale(Locale(locale));
|
||||
@@ -220,4 +237,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