chore: show loading indicator and don't hide button on subscription page (#2023)
This commit is contained in:
parent
cf56691c57
commit
d20e8918d1
4 changed files with 48 additions and 61 deletions
|
|
@ -3,7 +3,6 @@ import 'dart:convert';
|
|||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -195,30 +194,13 @@ class SubscriptionController extends BaseController {
|
|||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
GoogleAnalytics.beginPurchaseSubscription(
|
||||
selectedSubscription,
|
||||
context,
|
||||
);
|
||||
await Purchases.purchasePackage(selectedSubscription.package!);
|
||||
GoogleAnalytics.updateUserSubscriptionStatus(true);
|
||||
} catch (err) {
|
||||
final errCode = PurchasesErrorHelper.getErrorCode(
|
||||
err as PlatformException,
|
||||
);
|
||||
if (errCode == PurchasesErrorCode.purchaseCancelledError) {
|
||||
debugPrint("User cancelled purchase");
|
||||
return;
|
||||
}
|
||||
ErrorHandler.logError(
|
||||
m: "Failed to purchase revenuecat package for user $_userID with error code $errCode",
|
||||
s: StackTrace.current,
|
||||
data: {
|
||||
"selectedSubscription": selectedSubscription.toJson(),
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
GoogleAnalytics.beginPurchaseSubscription(
|
||||
selectedSubscription,
|
||||
context,
|
||||
);
|
||||
await Purchases.purchasePackage(selectedSubscription.package!);
|
||||
GoogleAnalytics.updateUserSubscriptionStatus(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,24 +31,27 @@ class ChangeSubscription extends StatelessWidget {
|
|||
const Divider(height: 1),
|
||||
SubscriptionButtons(controller: controller),
|
||||
const SizedBox(height: 32),
|
||||
if (controller.selectedSubscription != null)
|
||||
IntrinsicWidth(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: () => controller.submitChange(),
|
||||
child: Text(
|
||||
controller.selectedSubscription!.isTrial
|
||||
? L10n.of(context).activateTrial
|
||||
: L10n.of(context).pay,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
IntrinsicWidth(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
OutlinedButton(
|
||||
onPressed: controller.selectedSubscription != null
|
||||
? () => controller.submitChange()
|
||||
: null,
|
||||
child: controller.loading
|
||||
? const CircularProgressIndicator.adaptive()
|
||||
: Text(
|
||||
controller.selectedSubscription?.isTrial ?? false
|
||||
? L10n.of(context).activateTrial
|
||||
: L10n.of(context).pay,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: const Center(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
|
|
@ -12,7 +11,7 @@ import 'package:fluffychat/pangea/subscription/controllers/subscription_controll
|
|||
import 'package:fluffychat/pangea/subscription/pages/settings_subscription_view.dart';
|
||||
import 'package:fluffychat/pangea/subscription/utils/subscription_app_id.dart';
|
||||
import 'package:fluffychat/pangea/subscription/widgets/subscription_snackbar.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class SubscriptionManagement extends StatefulWidget {
|
||||
|
|
@ -26,9 +25,12 @@ class SubscriptionManagement extends StatefulWidget {
|
|||
class SubscriptionManagementController extends State<SubscriptionManagement> {
|
||||
final SubscriptionController subscriptionController =
|
||||
MatrixState.pangeaController.subscriptionController;
|
||||
|
||||
SubscriptionDetails? selectedSubscription;
|
||||
late StreamSubscription _settingsSubscription;
|
||||
StreamSubscription? _subscriptionStatusStream;
|
||||
bool loading = false;
|
||||
|
||||
late StreamSubscription _settingsSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -100,23 +102,23 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {
|
|||
.currentSubscriptionInfo!.currentPlatformMatchesPurchasePlatform;
|
||||
}
|
||||
|
||||
void submitChange({bool isPromo = false}) {
|
||||
try {
|
||||
subscriptionController.submitSubscriptionChange(
|
||||
Future<void> submitChange({bool isPromo = false}) async {
|
||||
setState(() => loading = true);
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () async => subscriptionController.submitSubscriptionChange(
|
||||
selectedSubscription,
|
||||
context,
|
||||
isPromo: isPromo,
|
||||
);
|
||||
setState(() {
|
||||
selectedSubscription = null;
|
||||
});
|
||||
} catch (err) {
|
||||
showOkAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).oopsSomethingWentWrong,
|
||||
message: L10n.of(context).errorPleaseRefresh,
|
||||
okLabel: L10n.of(context).close,
|
||||
);
|
||||
),
|
||||
onError: (error, s) {
|
||||
setState(() => loading = false);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
if (mounted && loading) {
|
||||
setState(() => loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ Future<Result<T>> showFutureLoadingDialog<T>({
|
|||
bool delay = true,
|
||||
ExceptionContext? exceptionContext,
|
||||
// #Pangea
|
||||
String Function(Object, StackTrace?)? onError,
|
||||
String? Function(Object, StackTrace?)? onError,
|
||||
VoidCallback? onDismiss,
|
||||
// Pangea#
|
||||
}) async {
|
||||
|
|
@ -79,7 +79,7 @@ class LoadingDialog<T> extends StatefulWidget {
|
|||
final Future<T> future;
|
||||
final ExceptionContext? exceptionContext;
|
||||
// #Pangea
|
||||
final String Function(Object, StackTrace?)? onError;
|
||||
final String? Function(Object, StackTrace?)? onError;
|
||||
final VoidCallback? onDismiss;
|
||||
// Pangea#
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue