35 lines
936 B
Dart
35 lines
936 B
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:mnemo_cards/features/subscription/subscription_api.dart';
|
||
|
|
import 'package:mnemo_cards/managers/user_state_holder.dart';
|
||
|
|
|
||
|
|
import '../../domain/router/app_router.dart';
|
||
|
|
import '../../main.dart';
|
||
|
|
import '../../managers/user_manager.dart';
|
||
|
|
import 'subscription_page.dart';
|
||
|
|
|
||
|
|
class SubscriptionManager {
|
||
|
|
final UserManager _userManager;
|
||
|
|
final SubscriptionApi _subscriptionApi;
|
||
|
|
|
||
|
|
SubscriptionManager(
|
||
|
|
this._userManager,
|
||
|
|
this._subscriptionApi,
|
||
|
|
);
|
||
|
|
|
||
|
|
Future<void> openSubscriptionPage() async {
|
||
|
|
final user = _userManager.user;
|
||
|
|
if (user == null) {
|
||
|
|
AppRouter.openAuthOrProfile();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
final buyDto =
|
||
|
|
await _subscriptionApi.getBuySubscription().catchError((_) => null);
|
||
|
|
if (buyDto != null) {
|
||
|
|
showDialog(
|
||
|
|
context: scaffoldKey.currentContext!,
|
||
|
|
builder: (_) => SubscriptionPage(buyDto.page!),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|