fixes from testing
This commit is contained in:
parent
46ff2f3d4c
commit
03de12e3b9
5 changed files with 98 additions and 101 deletions
|
|
@ -93,11 +93,10 @@ class SubscriptionController extends BaseController {
|
|||
final String profileCreatedAt =
|
||||
_pangeaController.userController.userModel!.profile!.createdAt;
|
||||
final DateTime creationTimestamp = DateTime.parse(profileCreatedAt);
|
||||
final int daysRemaining = DateTime.now()
|
||||
.add(const Duration(days: 7))
|
||||
.difference(creationTimestamp)
|
||||
.inDays;
|
||||
subscription?.setTrial(daysRemaining);
|
||||
final DateTime expirationDate = creationTimestamp.add(
|
||||
const Duration(days: 7),
|
||||
);
|
||||
subscription?.setTrial(expirationDate);
|
||||
}
|
||||
|
||||
Future<void> updateCustomerInfo() async {
|
||||
|
|
|
|||
|
|
@ -75,9 +75,9 @@ class SubscriptionInfo {
|
|||
currentSubscriptionId = null;
|
||||
}
|
||||
|
||||
void setTrial(int daysRemaining) {
|
||||
void setTrial(DateTime expiration) {
|
||||
if (currentSubscription != null) return;
|
||||
expirationDate = DateTime.now().add(Duration(days: daysRemaining));
|
||||
expirationDate = expiration;
|
||||
currentSubscriptionId = AppConfig.trialSubscriptionId;
|
||||
currentSubscription = SubscriptionDetails(
|
||||
price: 0,
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
// Dart imports:
|
||||
import 'dart:io';
|
||||
|
||||
// Flutter imports:
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:purchases_flutter/purchases_flutter.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/pangea/models/base_subscription_info.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
// Flutter imports:
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:purchases_flutter/purchases_flutter.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
class MobileSubscriptionInfo extends SubscriptionInfo {
|
||||
MobileSubscriptionInfo({required super.pangeaController}) : super();
|
||||
|
|
@ -161,17 +159,22 @@ class MobileSubscriptionInfo extends SubscriptionInfo {
|
|||
);
|
||||
}
|
||||
|
||||
final List<EntitlementInfo> activeEntitlements = info
|
||||
.entitlements.all.entries
|
||||
.where((MapEntry<String, EntitlementInfo> entry) =>
|
||||
entry.value.expirationDate == null ||
|
||||
DateTime.parse(entry.value.expirationDate!).isAfter(DateTime.now()))
|
||||
.map((MapEntry<String, EntitlementInfo> entry) => entry.value)
|
||||
.toList();
|
||||
final List<EntitlementInfo> activeEntitlements =
|
||||
info.entitlements.all.entries
|
||||
.where(
|
||||
(MapEntry<String, EntitlementInfo> entry) =>
|
||||
entry.value.expirationDate == null ||
|
||||
DateTime.parse(entry.value.expirationDate!)
|
||||
.isAfter(DateTime.now()),
|
||||
)
|
||||
.map((MapEntry<String, EntitlementInfo> entry) => entry.value)
|
||||
.toList();
|
||||
|
||||
allEntitlements = info.entitlements.all.entries
|
||||
.map((MapEntry<String, EntitlementInfo> entry) =>
|
||||
entry.value.productIdentifier)
|
||||
.map(
|
||||
(MapEntry<String, EntitlementInfo> entry) =>
|
||||
entry.value.productIdentifier,
|
||||
)
|
||||
.cast<String>()
|
||||
.toList();
|
||||
|
||||
|
|
@ -181,7 +184,9 @@ class MobileSubscriptionInfo extends SubscriptionInfo {
|
|||
);
|
||||
} else if (activeEntitlements.isEmpty) {
|
||||
debugPrint("User has no active entitlements");
|
||||
resetSubscription();
|
||||
if (!isNewUserTrial) {
|
||||
resetSubscription();
|
||||
}
|
||||
return;
|
||||
}
|
||||
final EntitlementInfo activeEntitlement = activeEntitlements[0];
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
// Flutter imports:
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
// Project imports:
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// Package imports:
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class SubscriptionOptions extends StatelessWidget {
|
||||
final PangeaController pangeaController;
|
||||
|
|
@ -19,23 +17,18 @@ class SubscriptionOptions extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
direction: Axis.horizontal,
|
||||
children: pangeaController
|
||||
.subscriptionController.subscription!.availableSubscriptions
|
||||
.map(
|
||||
(subscription) => SubscriptionCard(
|
||||
subscription: subscription,
|
||||
pangeaController: pangeaController,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
direction: Axis.horizontal,
|
||||
children: pangeaController
|
||||
.subscriptionController.subscription!.availableSubscriptions
|
||||
.map(
|
||||
(subscription) => SubscriptionCard(
|
||||
subscription: subscription,
|
||||
pangeaController: pangeaController,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -46,10 +39,10 @@ class SubscriptionCard extends StatelessWidget {
|
|||
final PangeaController pangeaController;
|
||||
|
||||
const SubscriptionCard({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.subscription,
|
||||
required this.pangeaController,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -86,7 +79,7 @@ class SubscriptionCard extends StatelessWidget {
|
|||
.submitSubscriptionChange(subscription, context);
|
||||
},
|
||||
child: Text(L10n.of(context)!.subscribe),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -30,32 +30,30 @@ class SubscriptionPaywall extends StatelessWidget {
|
|||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
if (pangeaController.matrixState.client.rooms.length > 1) ...[
|
||||
Text(
|
||||
L10n.of(context)!.welcomeBack,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
child: ListView(
|
||||
children: [
|
||||
if (pangeaController.matrixState.client.rooms.length > 1) ...[
|
||||
Text(
|
||||
L10n.of(context)!.subscriptionDesc,
|
||||
L10n.of(context)!.welcomeBack,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
pangeaController.userController.inTrialWindow
|
||||
? FreeTrialCard(
|
||||
pangeaController: pangeaController,
|
||||
)
|
||||
: SubscriptionOptions(
|
||||
pangeaController: pangeaController,
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
L10n.of(context)!.subscriptionDesc,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
pangeaController.userController.inTrialWindow
|
||||
? FreeTrialCard(
|
||||
pangeaController: pangeaController,
|
||||
)
|
||||
: SubscriptionOptions(
|
||||
pangeaController: pangeaController,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -68,40 +66,42 @@ class FreeTrialCard extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(
|
||||
color: AppConfig.primaryColorLight.withAlpha(64),
|
||||
return Align(
|
||||
child: Card(
|
||||
shape: RoundedRectangleBorder(
|
||||
side: BorderSide(
|
||||
color: AppConfig.primaryColorLight.withAlpha(64),
|
||||
),
|
||||
borderRadius: const BorderRadius.all(Radius.zero),
|
||||
),
|
||||
borderRadius: const BorderRadius.all(Radius.zero),
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 250,
|
||||
width: AppConfig.columnWidth * 0.75,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
L10n.of(context)!.freeTrial,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
Text(
|
||||
L10n.of(context)!.freeTrialDesc,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
pangeaController.subscriptionController
|
||||
.activateNewUserTrial();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(L10n.of(context)!.activateTrial),
|
||||
),
|
||||
],
|
||||
child: SizedBox(
|
||||
height: 250,
|
||||
width: AppConfig.columnWidth * 0.75,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
L10n.of(context)!.freeTrial,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
Text(
|
||||
L10n.of(context)!.freeTrialDesc,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: () {
|
||||
pangeaController.subscriptionController
|
||||
.activateNewUserTrial();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(L10n.of(context)!.activateTrial),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue