mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-26 09:20:45 +00:00
iap mock
This commit is contained in:
parent
a0a4affa8d
commit
159b98dfa2
2 changed files with 25 additions and 5 deletions
|
@ -10,7 +10,7 @@ class IAPProduct {
|
||||||
final String storeId;
|
final String storeId;
|
||||||
final IAPProductStatus status;
|
final IAPProductStatus status;
|
||||||
|
|
||||||
IAPProduct({
|
const IAPProduct({
|
||||||
required this.storeId,
|
required this.storeId,
|
||||||
this.status = IAPProductStatus.purchasable,
|
this.status = IAPProductStatus.purchasable,
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,12 @@ class IAPProductsProviderState extends State<IAPProductsProvider> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return IAPProducts(
|
return IAPProducts(
|
||||||
products: const [],
|
products: [
|
||||||
|
IAPProduct(
|
||||||
|
storeId: IAPProductType.paidFeatures.storeId,
|
||||||
|
status: IAPProductStatus.purchased,
|
||||||
|
)
|
||||||
|
],
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,13 +40,28 @@ class IAPProducts extends InheritedModel<IAPProductType> {
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
static IAPProduct? productOf(BuildContext context, IAPProductType type) => null;
|
static IAPProduct? productOf(BuildContext context, IAPProductType type) {
|
||||||
|
final IAPProducts? result = InheritedModel.inheritFrom<IAPProducts>(context, aspect: type);
|
||||||
|
return result!._findProduct(type);
|
||||||
|
}
|
||||||
|
|
||||||
static bool isPurchased(BuildContext context, IAPProductType type) => false;
|
static bool isPurchased(BuildContext context, IAPProductType type) {
|
||||||
|
final IAPProducts? result = InheritedModel.inheritFrom<IAPProducts>(context, aspect: type);
|
||||||
|
return result!._findProduct(type)?.status == IAPProductStatus.purchased;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(IAPProducts oldWidget) => false;
|
bool updateShouldNotify(IAPProducts oldWidget) => false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotifyDependent(covariant IAPProducts oldWidget, Set<IAPProductType> dependencies) => false;
|
bool updateShouldNotifyDependent(IAPProducts oldWidget, Set<IAPProductType> dependencies) =>
|
||||||
|
false;
|
||||||
|
|
||||||
|
IAPProduct? _findProduct(IAPProductType type) {
|
||||||
|
try {
|
||||||
|
return products.firstWhere((element) => element.storeId == type.storeId);
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue