mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
show iap dialog on every iap list tile
This commit is contained in:
parent
613a0f18a6
commit
18808a0943
3 changed files with 57 additions and 41 deletions
|
@ -1,42 +1,20 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart';
|
||||||
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
import 'package:lightmeter/screens/settings/components/utils/show_buy_pro_dialog.dart';
|
||||||
|
|
||||||
class BuyProListTile extends StatelessWidget {
|
class BuyProListTile extends StatelessWidget {
|
||||||
const BuyProListTile({super.key});
|
const BuyProListTile({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return IAPListTile(
|
||||||
leading: const Icon(Icons.star),
|
leading: const Icon(Icons.star),
|
||||||
title: Text(S.of(context).buyLightmeterPro),
|
title: Text(S.of(context).buyLightmeterPro),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
showDialog(
|
showBuyProDialog(context);
|
||||||
context: context,
|
|
||||||
builder: (_) => AlertDialog(
|
|
||||||
icon: const Icon(Icons.star),
|
|
||||||
titlePadding: Dimens.dialogIconTitlePadding,
|
|
||||||
title: Text(S.of(context).lightmeterPro),
|
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL),
|
|
||||||
content: SingleChildScrollView(child: Text(S.of(context).lightmeterProDescription)),
|
|
||||||
actionsPadding: Dimens.dialogActionsPadding,
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: Navigator.of(context).pop,
|
|
||||||
child: Text(S.of(context).cancel),
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
IAPProductsProvider.of(context).buy(IAPProductType.paidFeatures);
|
|
||||||
},
|
|
||||||
child: Text(S.of(context).buy),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
showPendingTrailing: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/res/dimens.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';
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
|
||||||
/// Depends on the product status and replaces [onTap] with purchase callback
|
/// Depends on the product status and replaces [onTap] with purchase callback
|
||||||
|
@ -9,31 +10,37 @@ class IAPListTile extends StatelessWidget {
|
||||||
final Icon leading;
|
final Icon leading;
|
||||||
final Text title;
|
final Text title;
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
|
final bool showPendingTrailing;
|
||||||
|
|
||||||
const IAPListTile({
|
const IAPListTile({
|
||||||
this.product = IAPProductType.paidFeatures,
|
this.product = IAPProductType.paidFeatures,
|
||||||
required this.leading,
|
required this.leading,
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
|
this.showPendingTrailing = false,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Opacity(
|
final status = IAPProducts.productOf(context, IAPProductType.paidFeatures)?.status;
|
||||||
opacity: IAPProducts.isPurchased(context, product)
|
final isPending = status == IAPProductStatus.purchased || status == null;
|
||||||
? Dimens.enabledOpacity
|
return ListTile(
|
||||||
: Dimens.disabledOpacity,
|
leading: leading,
|
||||||
child: ListTile(
|
title: title,
|
||||||
leading: leading,
|
onTap: switch (status) {
|
||||||
title: title,
|
IAPProductStatus.purchasable => () => showBuyProDialog(context),
|
||||||
onTap: switch (IAPProducts.productOf(context, product)?.status) {
|
IAPProductStatus.pending => null,
|
||||||
IAPProductStatus.purchasable => () => IAPProductsProvider.of(context).buy(product),
|
IAPProductStatus.purchased => onTap,
|
||||||
IAPProductStatus.pending => null,
|
null => null,
|
||||||
IAPProductStatus.purchased => onTap,
|
},
|
||||||
null => null,
|
trailing: showPendingTrailing && isPending
|
||||||
},
|
? const SizedBox(
|
||||||
),
|
height: Dimens.grid24,
|
||||||
|
width: Dimens.grid24,
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
|
|
||||||
|
Future<void> showBuyProDialog(BuildContext context) {
|
||||||
|
return showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => AlertDialog(
|
||||||
|
icon: const Icon(Icons.star),
|
||||||
|
titlePadding: Dimens.dialogIconTitlePadding,
|
||||||
|
title: Text(S.of(context).lightmeterPro),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: Dimens.paddingL),
|
||||||
|
content: SingleChildScrollView(child: Text(S.of(context).lightmeterProDescription)),
|
||||||
|
actionsPadding: Dimens.dialogActionsPadding,
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: Navigator.of(context).pop,
|
||||||
|
child: Text(S.of(context).cancel),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
IAPProductsProvider.of(context).buy(IAPProductType.paidFeatures);
|
||||||
|
},
|
||||||
|
child: Text(S.of(context).buy),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue