Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve the base plan and subscription offers from the Google Play Store console in Flutter, you can use the Google Play Billing Library. Here are the steps:

  1. Add the Google Play Billing Library to your Flutter project. You can do this by adding the following dependency to your pubspec.yaml file:
dependencies:
  in_app_purchase: ^0.3.4+1
  1. Initialize the billing client in your Flutter code. You can do this using the following code:
import 'package:in_app_purchase/in_app_purchase.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final InAppPurchaseConnection _connection = InAppPurchaseConnection.instance;

  @override
  void initState() {
    super.initState();
    _connection.onBillingSetupComplete.listen((billingResult) {
      // Handle the result of the billing setup process
    });
    _connection.billingClient;
  }

  @override
  Widget build(BuildContext context) {
    // Build your Flutter UI
  }
}
  1. Retrieve the base plan and subscription offers using the billing client. You can use the following code to retrieve the offers:
Future<void> _getProducts() async {
    final ProductDetailsResponse response = await _connection.queryProductDetails(<String>[
      'base_plan_id',
      'subscription_1_month_id',
      'subscription_6_month_id',
      'subscription_1_year_id'
    ]);

    if (response.error != null) {
      // Handle the error
      return;
    }

    final List<ProductDetails> products = response.productDetails;

    // Do something with the product details, e.g. display them in a list
  }
  1. Call the _getProducts() function to retrieve the offers when necessary. For example, you can call it when the user clicks on a "Subscribe" button in your app.