1

How can i fix this and make it not deprecated

import 'package:purchases_flutter/purchases_flutter.dart';
class PurchaseApi{
  static const _apiKey = '';
  static Future init() async{
    await Purchases.setDebugLogsEnabled(true);
    await Purchases.setup(_apiKey);
  }

  static Future<List<Offering>> fetchOffers() async {
   try{
    final offerings = await Purchases.getOfferings();
    final current = offerings.current;
    return current == null ? [] : [current];
  } on PlatformException catch (e) {
      return [];
    }
  }
} 

I already changed the firt on to await Purchases.setLogLevel(true as LogLevel); But when i change the setup one i get an error. The error is The method 'PurchasesConfiguration' isn't defined for the type 'Purchases'. I already tried to import'package:purchases_flutter/models/purchases_configuration.dart';

Android_devNL
  • 107
  • 1
  • 9

2 Answers2

3

Replace:

await Purchases.setup(_apiKey);

With:

await Purchases.configure(PurchasesConfiguration(_apiKey));
Dpedrinha
  • 3,741
  • 3
  • 38
  • 57
1

Deprecated error screenshoot

When you hover over the deprecated setup method, you have a hint.

You need to replace this:

await Purchases.setup(_apiKey);

to this:

PurchasesConfiguration(_apiKey);
SerjantArbuz
  • 982
  • 1
  • 12
  • 16
  • This doesn't work. There has to be an async operation to make sure no Purchase method is called before the setup/configure process is finished and PurchaseConfiguration is an Object, not an async call. – Dpedrinha Feb 28 '23 at 18:38