skip to Main Content

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’;

2

Answers


  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);
    
    Login or Signup to reply.
  2. Replace:

    await Purchases.setup(_apiKey);
    

    With:

    await Purchases.configure(PurchasesConfiguration(_apiKey));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search