flutter_billing_plugin

Last updated:

0 purchases

flutter_billing_plugin Image
flutter_billing_plugin Images
Add to Cart

Description:

flutter billing plugin

flutter_billing_plugin #
This plugin supports in-app purchases for App Store (on iOS) or Google Play (on Android).
Simple steps to add in-app purchases in you flutter app.
Getting Started #
Add below line to your pubspec.yaml file
dependencies:
flutter_billing_plugin: ^1.0.0
copied to clipboard
Initialize Plugin
@override
void initState() {
super.initState();
initBilling();
initListeners();
initPrice();
}

Future<void> initBilling() async {
billingHelper = FlutterBillingPlugin();
await billingHelper?.init(productIds);
}

Future<void> initPrice() async {
await billingHelper?.getPrice(Platform.isAndroid ? 'android.test.purchased' : 'weekly');
}

void initListeners() {
billingHelper?.setPurchaseUpdateHandler((status, value) async {
switch (status) {
case 'success':
if (kDebugMode) {
print('$status : $value');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: const Duration(seconds: 1),
backgroundColor: Utils.getPrimaryColor(),
content: Text(
'Purchase Sucessfully',
style: TextStyle(fontSize: 18.0, fontFamily: 'Sans', fontStyle: FontStyle.normal, fontWeight: FontWeight.w500, color: Utils.getWhiteColor()),
)));
}
break;
case 'cancelled':
if (kDebugMode) {
print('$status : $value');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: const Duration(seconds: 1),
backgroundColor: Utils.getPrimaryColor(),
content: Text(
'Purchase cancelled by you',
style: TextStyle(fontSize: 18.0, fontFamily: 'Sans', fontStyle: FontStyle.normal, fontWeight: FontWeight.w500, color: Utils.getWhiteColor()),
)));
}
break;
case 'error':
if (kDebugMode) {
print('$status : $value');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: const Duration(seconds: 1),
backgroundColor: Utils.getPrimaryColor(),
content: Text(
'Something went wrong, Please try again after sometime',
style: TextStyle(fontSize: 18.0, fontFamily: 'Sans', fontStyle: FontStyle.normal, fontWeight: FontWeight.w500, color: Utils.getWhiteColor()),
)));
}
break;
case 'restore':
if (kDebugMode) {
print('$status : $value');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: const Duration(seconds: 1),
backgroundColor: Utils.getPrimaryColor(),
content: Text(
value ? 'Restore Successfully' : 'You don\'t have purchase to restore',
style: TextStyle(fontSize: 18.0, fontFamily: 'Sans', fontStyle: FontStyle.normal, fontWeight: FontWeight.w500, color: Utils.getWhiteColor()),
)));
}
break;
default:
if (kDebugMode) {
print('$status : $value');
}
}
});

billingHelper!.setPriceUpdateHandler((price) {
if (kDebugMode) {
print("Price: $price");
setState(() {
this.price = price;
});
}
});
}
copied to clipboard
Purchase product by passing product id as String and get response as 'success', 'cancelled', 'error'.
billingHelper!.buyProduct(Platform.isAndroid ? 'android.test.purchased' : 'weekly');
copied to clipboard
Recover old purchaseed product using below line call and return callback to restore with bool value
billingHelper!.checkRestore();
copied to clipboard
Support #
For support, email [email protected]

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.