btc_purchase 0.0.3 btc_purchase: ^0.0.3 copied to clipboard
A new InApp project.
ads_demo #
A new Flutter project.
integration #
add this two permission in AndroidManifest.xml
before test in app purchase make sure your app published in playstore or not
Getting Started #
import 'package:btc_purchase/btc_purchase.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'in app purchase Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo in app purchase'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _purchaseKey = 'enter your test id';
final _btcPurchasePlugin = BtcPurchase();
String? _alreadyPurchasedList;
Widget buyButton = Container();
var isAlreadyPurchased;
String? fetchPrize;
Future<void> initPlatformState() async {
fetchPrize = await _btcPurchasePlugin.getPurchaseList(_purchaseKey);
isAlreadyPurchased =
await _btcPurchasePlugin.getAlreadyPurchasedList(_purchaseKey);
if (fetchPrize?.isNotEmpty == true) {
setState(() {
buyButton = Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
child: Text(fetchPrize!, style: const TextStyle(fontSize: 15)),
);
});
}
if (!mounted) return;
}
fetchOldPurchaseDetails() async {
var purchasePrice = await _btcPurchasePlugin.getPurchaseList(_purchaseKey);
var alreadypurchased =
await _btcPurchasePlugin.getAlreadyPurchasedList(_purchaseKey);
setState(() {
fetchPrize = purchasePrice;
isAlreadyPurchased = alreadypurchased;
});
}
@override
void initState() {
super.initState();
initPlatformState();
fetchOldPurchaseDetails();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
/// show your purchase product price button here
buyButton],
),
),
/// check old non-consumable product purchased or not
floatingActionButton: isAlreadyPurchased != _purchseKey
? FloatingActionButton(
onPressed: () async {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
print("isAlreadyPurchased ===>$isAlreadyPurchased");
return Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25)),
color: Colors.white,
),
child: Column(
children: [
ListTile(
title: const Text("your application name here",
style: TextStyle(
fontSize: 18,
)),
subtitle: Text(
"some extra word for your application",
),
trailing: InkWell(
onTap: () async {
await _btcPurchasePlugin
.launchPurchase(_purchseKey);
},
child: Container(
padding: EdgeInsets.symmetric(
vertical: 10, horizontal: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(0xff048c13),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.25),
blurRadius: 1.0,
),
]),
child: Text("$fetchPrize",
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.bold,
color: Colors.white)),
),
))
],
),
);
},
);
},
tooltip: 'Increment',
child: const Icon(Icons.add),
)
: Container(
height: 0,
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}