fix additional users
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run

This commit is contained in:
otsmr 2025-12-21 16:37:48 +01:00
parent fa953b8928
commit 049507cd25
3 changed files with 35 additions and 44 deletions

View file

@ -187,6 +187,10 @@ class PurchasesProvider with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
if (purchaseDetails.status == PurchaseStatus.error) {
await iapConnection.restorePurchases();
}
if (purchaseDetails.pendingCompletePurchase) { if (purchaseDetails.pendingCompletePurchase) {
await iapConnection.completePurchase(purchaseDetails); await iapConnection.completePurchase(purchaseDetails);
} }

View file

@ -65,12 +65,9 @@ class _AdditionalUsersViewState extends State<AdditionalUsersView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var plusInvites = <Response_AddAccountsInvite>[]; var plusInvites = <Response_AddAccountsInvite>[];
var freeInvites = <Response_AddAccountsInvite>[];
if (additionalInvites != null) { if (additionalInvites != null) {
plusInvites = plusInvites =
additionalInvites!.where((x) => x.planId == 'Plus').toList(); additionalInvites!.where((x) => x.planId == 'Plus').toList();
freeInvites =
additionalInvites!.where((x) => x.planId == 'Free').toList();
} }
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@ -95,11 +92,10 @@ class _AdditionalUsersViewState extends State<AdditionalUsersView> {
), ),
), ),
if (plusInvites.isNotEmpty) if (plusInvites.isNotEmpty)
ListTile( Text(
title: Text( context.lang.additionalUsersPlusTokens,
context.lang.additionalUsersPlusTokens, textAlign: TextAlign.center,
style: const TextStyle(fontSize: 13), style: const TextStyle(fontSize: 16),
),
), ),
Padding( Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@ -111,23 +107,6 @@ class _AdditionalUsersViewState extends State<AdditionalUsersView> {
children: plusInvites.map(AdditionalUserInvite.new).toList(), children: plusInvites.map(AdditionalUserInvite.new).toList(),
), ),
), ),
if (freeInvites.isNotEmpty)
ListTile(
title: Text(
context.lang.additionalUsersFreeTokens,
style: const TextStyle(fontSize: 13),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: GridView.count(
crossAxisCount: 2,
physics: const NeverScrollableScrollPhysics(),
childAspectRatio: 16 / 5,
shrinkWrap: true,
children: freeInvites.map(AdditionalUserInvite.new).toList(),
),
),
], ],
), ),
); );
@ -200,7 +179,7 @@ class _AdditionalAccountState extends State<AdditionalAccount> {
final remove = await showAlertDialog( final remove = await showAlertDialog(
context, context,
'Remove this additional user', 'Remove this additional user',
'The additional user will automatically be downgraded to the preview plan after removal and you will receive a new invitation code to give to another person.', 'The additional user will automatically be downgraded to the free plan after removal and you will receive a new invitation code to give to another person.',
); );
if (remove) { if (remove) {
final res = await apiService final res = await apiService

View file

@ -114,6 +114,8 @@ class _SubscriptionViewState extends State<SubscriptionView> {
plan: SubscriptionPlan.Family, plan: SubscriptionPlan.Family,
onPurchase: initAsync, onPurchase: initAsync,
), ),
],
if (currentPlan == SubscriptionPlan.Free) ...[
const SizedBox(height: 10), const SizedBox(height: 10),
Center( Center(
child: Padding( child: Padding(
@ -174,6 +176,13 @@ class PlanCard extends StatefulWidget {
State<PlanCard> createState() => _PlanCardState(); State<PlanCard> createState() => _PlanCardState();
} }
String getFormattedPrice(PurchasableProduct product) {
if (product.price.contains('')) {
return product.price.replaceAll(',00', '').replaceAll('.00', '');
}
return product.price;
}
class _PlanCardState extends State<PlanCard> { class _PlanCardState extends State<PlanCard> {
Future<void> onButtonPressed(PurchasableProduct? product) async { Future<void> onButtonPressed(PurchasableProduct? product) async {
if (widget.onPurchase == null) return; if (widget.onPurchase == null) return;
@ -261,7 +270,7 @@ class _PlanCardState extends State<PlanCard> {
Column( Column(
children: [ children: [
Text( Text(
'${yearlyProduct.price}/${context.lang.year}', '${getFormattedPrice(yearlyProduct)}/${context.lang.year}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
fontSize: 20, fontSize: 20,
@ -270,7 +279,7 @@ class _PlanCardState extends State<PlanCard> {
), ),
if (monthlyProduct != null) if (monthlyProduct != null)
Text( Text(
'${monthlyProduct.price}/${context.lang.month}', '${getFormattedPrice(monthlyProduct)}/${context.lang.month}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
fontSize: 16, fontSize: 16,
@ -282,8 +291,8 @@ class _PlanCardState extends State<PlanCard> {
if (widget.paidMonthly != null) if (widget.paidMonthly != null)
Text( Text(
(widget.paidMonthly!) (widget.paidMonthly!)
? '${monthlyProduct?.price}/${context.lang.month}' ? '${getFormattedPrice(monthlyProduct!)}/${context.lang.month}'
: '${yearlyProduct?.price}/${context.lang.year}', : '${getFormattedPrice(yearlyProduct!)}/${context.lang.year}',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
fontSize: 20, fontSize: 20,
@ -319,22 +328,21 @@ class _PlanCardState extends State<PlanCard> {
label: const Text('Manage subscription'), label: const Text('Manage subscription'),
), ),
if (widget.onPurchase != null && monthlyProduct != null) if (widget.onPurchase != null && monthlyProduct != null)
Padding( OutlinedButton.icon(
padding: const EdgeInsets.only(right: 10), onPressed: () => onButtonPressed(monthlyProduct),
child: OutlinedButton.icon( label: (widget.plan == SubscriptionPlan.Free ||
onPressed: () => onButtonPressed(monthlyProduct), widget.plan == SubscriptionPlan.Plus)
label: (widget.plan == SubscriptionPlan.Free || ? Text(context.lang.redeemUserInviteCodeTitle)
widget.plan == SubscriptionPlan.Plus) : Text(
? Text(context.lang.redeemUserInviteCodeTitle) context.lang.upgradeToPaidPlanButton(
: Text( widget.plan.name,
context.lang.upgradeToPaidPlanButton( ' (${context.lang.monthly})',
widget.plan.name,
' (${context.lang.monthly})',
),
), ),
), ),
), ),
if (widget.onPurchase != null && yearlyProduct != null) if (widget.onPurchase != null &&
(yearlyProduct != null ||
currentPlan == SubscriptionPlan.Free))
FilledButton.icon( FilledButton.icon(
onPressed: () => onButtonPressed(yearlyProduct), onPressed: () => onButtonPressed(yearlyProduct),
label: (widget.plan == SubscriptionPlan.Free || label: (widget.plan == SubscriptionPlan.Free ||