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