mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 03:42:13 +00:00
replace global callback with broadcast
This commit is contained in:
parent
d9f9f7645e
commit
bd012a363e
4 changed files with 8 additions and 8 deletions
|
|
@ -43,10 +43,6 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
|||
await setUserPlan();
|
||||
};
|
||||
|
||||
globalCallbackUpdatePlan = (plan) {
|
||||
context.read<PurchasesProvider>().updatePlan(plan);
|
||||
};
|
||||
|
||||
unawaited(initAsync());
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +82,6 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
|||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
globalCallbackConnectionState = ({required isConnected}) {};
|
||||
globalCallbackUpdatePlan = (planId) {};
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:twonly/src/database/twonly.db.dart';
|
||||
import 'package:twonly/src/model/json/userdata.dart';
|
||||
import 'package:twonly/src/services/api.service.dart';
|
||||
import 'package:twonly/src/services/subscription.service.dart';
|
||||
|
||||
class AppEnvironment {
|
||||
static late final String cacheDir;
|
||||
|
|
@ -38,7 +37,6 @@ void Function({required bool isConnected}) globalCallbackConnectionState =
|
|||
}) {};
|
||||
void Function() globalCallbackAppIsOutdated = () {};
|
||||
void Function() globalCallbackNewDeviceRegistered = () {};
|
||||
void Function(SubscriptionPlan plan) globalCallbackUpdatePlan = (plan) {};
|
||||
|
||||
Map<String, VoidCallback> globalUserDataChangedCallBack = {};
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ class PurchasesProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|||
onError: _updateStreamOnError,
|
||||
);
|
||||
|
||||
_planSub = apiService.onPlanUpdated.listen(updatePlan);
|
||||
|
||||
loadPurchases();
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +50,7 @@ class PurchasesProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|||
late StreamSubscription<List<PurchaseDetails>> _subscription;
|
||||
final InAppPurchase iapConnection = IAPConnection.instance;
|
||||
|
||||
late StreamSubscription<SubscriptionPlan> _planSub;
|
||||
bool _userTriggeredBuyButton = false;
|
||||
|
||||
void updatePlan(SubscriptionPlan newPlan) {
|
||||
|
|
@ -225,6 +228,7 @@ class PurchasesProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
_planSub.cancel();
|
||||
_subscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ class ApiService {
|
|||
// final String apiHost = kReleaseMode ? 'api.twonly.eu' : 'dev.twonly.eu';
|
||||
final String apiSecure = kReleaseMode ? 's' : '';
|
||||
|
||||
final _planUpdateController = StreamController<SubscriptionPlan>.broadcast();
|
||||
Stream<SubscriptionPlan> get onPlanUpdated => _planUpdateController.stream;
|
||||
|
||||
bool appIsOutdated = false;
|
||||
bool isAuthenticated = false;
|
||||
|
||||
|
|
@ -333,7 +336,7 @@ class ApiService {
|
|||
user.subscriptionPlan = authenticated.plan;
|
||||
return user;
|
||||
});
|
||||
globalCallbackUpdatePlan(planFromString(authenticated.plan));
|
||||
_planUpdateController.add(planFromString(authenticated.plan));
|
||||
|
||||
// this was triggered by apiService.ipaPurchase, so call the onAuthenticated again
|
||||
if (isAuthenticated) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue