dim paid features list tiles

This commit is contained in:
Vadim 2023-10-30 10:31:51 +01:00
parent 6d1be75070
commit 690badccd2
2 changed files with 20 additions and 22 deletions

View file

@ -2,15 +2,18 @@ import 'package:flutter/material.dart';
import 'package:lightmeter/data/models/feature.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/remote_config_provider.dart';
import 'package:lightmeter/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/settings/components/utils/show_buy_pro_dialog.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
class BuyProListTile extends StatelessWidget {
const BuyProListTile({super.key});
@override
Widget build(BuildContext context) {
return IAPListTile(
final status = IAPProducts.productOf(context, IAPProductType.paidFeatures)?.status;
final isPending = status == IAPProductStatus.purchased || status == null;
return ListTile(
leading: const Icon(Icons.star),
title: Text(
RemoteConfig.isEnabled(context, Feature.unlockProFeaturesText)
@ -20,7 +23,13 @@ class BuyProListTile extends StatelessWidget {
onTap: () {
showBuyProDialog(context);
},
showPendingTrailing: true,
trailing: isPending
? const SizedBox(
height: Dimens.grid24,
width: Dimens.grid24,
child: CircularProgressIndicator(),
)
: null,
);
}
}

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/res/dimens.dart';
import 'package:lightmeter/screens/settings/components/utils/show_buy_pro_dialog.dart';
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
/// Depends on the product status and replaces [onTap] with purchase callback
@ -23,24 +22,14 @@ class IAPListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final status = IAPProducts.productOf(context, IAPProductType.paidFeatures)?.status;
final isPending = status == IAPProductStatus.purchased || status == null;
return ListTile(
final isPurchased = IAPProducts.isPurchased(context, IAPProductType.paidFeatures);
return Opacity(
opacity: isPurchased ? Dimens.enabledOpacity : Dimens.disabledOpacity,
child: ListTile(
leading: leading,
title: title,
onTap: switch (status) {
IAPProductStatus.purchasable => () => showBuyProDialog(context),
IAPProductStatus.pending => null,
IAPProductStatus.purchased => onTap,
null => null,
},
trailing: showPendingTrailing && isPending
? const SizedBox(
height: Dimens.grid24,
width: Dimens.grid24,
child: CircularProgressIndicator(),
)
: null,
onTap: isPurchased ? onTap : null,
),
);
}
}