consume_inapp_purchase 0.0.1 copy "consume_inapp_purchase: ^0.0.1" to clipboard
consume_inapp_purchase: ^0.0.1 copied to clipboard

Consume In-App Purchase is a Flutter plugin designed to streamline the handling of consumable in-app purchases for both Android and iOS platforms. It provides an intuitive API for consuming purchases [...]

Consume In-App Purchase #

consume_inapp_purchase is a Flutter plugin that provides an easy way to consume in-app purchases in your Flutter applications. It simplifies handling consumable purchases, ensuring they are properly consumed after being acknowledged.

Features #

  • Consume consumable in-app purchases.
  • Supports both Android and iOS platforms.
  • Simple and intuitive API for Flutter developers.

Installation #

Add the following dependency to your pubspec.yaml file:

dependencies:
  consume_inapp_purchase: ^1.0.0

Then, run the following command:

flutter pub get

Usage #

Import the Plugin #

import 'package:consume_inapp_purchase/consume_inapp_purchase.dart';

Consuming a Purchase #

To consume a purchase, call the consumePurchase method with the purchase token.

Future<void> consumePurchase() async {
    String consumeStatus;
    try {
      consumeStatus = await _consumeInappPurchasePlugin.consumePurchase() ??
          'No purchase found.';
    } on PlatformException {
      consumeStatus = 'Failed to consume purchase.';
    }
    debugPrint(consumeStatus);
    if (!mounted) return;
}

Example #

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:consume_inapp_purchase/consume_inapp_purchase.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _consumeInappPurchasePlugin = ConsumeInappPurchase();

  @override
  void initState() {
    super.initState();
  }

  Future<void> consumePurchase() async {
    String consumeStatus;
    try {
      consumeStatus = await _consumeInappPurchasePlugin.consumePurchase() ??
          'No purchase found.';
    } on PlatformException {
      consumeStatus = 'Failed to consume purchase.';
    }
    debugPrint(consumeStatus);
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            ElevatedButton(
              onPressed: consumePurchase,
              child: const Text('Consume Purchase'),
            ),
          ],
        ),
      ),
    );
  }
}

Supported Platforms #

  • Android
  • iOS

Getting Started #

To get started with Flutter, visit the official documentation.

For more information about in-app purchases, refer to:

Contributing #

Contributions are welcome! If you encounter issues or have suggestions, feel free to open an issue or submit a pull request.

License #

consume_inapp_purchase is licensed under the MIT License. See the LICENSE file for more information.

0
likes
140
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

Consume In-App Purchase is a Flutter plugin designed to streamline the handling of consumable in-app purchases for both Android and iOS platforms. It provides an intuitive API for consuming purchases after they are successfully acknowledged, ensuring a seamless user experience for developers and end-users. Whether you're building a gaming app with consumable items or a productivity tool with incremental upgrades, this plugin simplifies the purchase lifecycle, saving you time and effort.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on consume_inapp_purchase

Packages that implement consume_inapp_purchase