super_easy_in_app_purchase 0.1.3
super_easy_in_app_purchase: ^0.1.3 copied to clipboard
A flutter plugin for creating in app purchase on Android/iOS in a super simple way.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:super_easy_in_app_purchase/super_easy_in_app_purchase.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
SuperEasyInAppPurchase inAppPurchase;
@override
void initState() {
super.initState();
inAppPurchase = SuperEasyInAppPurchase(
// Any of these function will run when its corresponding product gets purchased successfully
// For simplicity, only a message is printed to console
whenSuccessfullyPurchased: <String, Function>{
'product1': () => print('Product 1 purchased!'),
'product2': () async => print('product 2 activated!'),
'product3': () {},
},
// Any of these function will run when its corresponding product gets refunded
whenUpgradeDisabled: <String, Function>{
'product1': () async => print('Product 1 refunded !'),
'product2': () => print('product 2 deactivated !'),
},
);
}
@override
void dispose() {
inAppPurchase.stop();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Super Easy In App Purchase'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: Text('Activate product 1'),
onPressed: () async {
await inAppPurchase.startPurchase('product1');
},
),
SizedBox(height: 10),
ElevatedButton(
child: Text('Activate product 2'),
onPressed: () async {
await inAppPurchase.startPurchase('product2',
isConsumable: true);
},
),
SizedBox(height: 10),
ElevatedButton(
child: Text('Deactivate product 2'),
onPressed: () async {
await inAppPurchase.consumePurchase('product2');
},
),
],
),
),
);
}
}