flutter_inapp_purchase icon indicating copy to clipboard operation
flutter_inapp_purchase copied to clipboard

Future<List<PurchasedItem>?>' is not a subtype of type FutureOr<List<PurchasedItem>>

Open dmitry-mikheev opened this issue 2 years ago • 2 comments

Version of flutter_inapp_purchase

5.2.0

Platforms you faced the error (IOS or Android or both?)

iOS

Expected behavior

returns true or false

Actual behavior

throws error "Future<List<PurchasedItem>?>' is not a subtype of type FutureOr<List<PurchasedItem>>"

Tested environment (Emulator? Real Device?)

real device

Steps to reproduce the behavior

call FlutterInappPurchase.instance.checkSubscribed(...)

Code with error

File flutter_inapp_purchase.dart:

var purchases = await (getAvailablePurchases() as FutureOr<List<PurchasedItem>>); // this line throws the error. 
var history = await (getPurchaseHistory() as FutureOr<List<PurchasedItem>>); // and this one too

dmitry-mikheev avatar Jun 02 '22 10:06 dmitry-mikheev

The fix is very simple. Just replace the code lines mentioned in the description with:

List<PurchasedItem>? historyNullable = await getPurchaseHistory();
      var history = historyNullable ?? [];

and

List<PurchasedItem>? purchasesNullable = await getAvailablePurchases();
      var purchases = purchasesNullable ?? [];

Thank you for fast update!!!

dmitry-mikheev avatar Jun 07 '22 12:06 dmitry-mikheev

Any update on this?

eeoom avatar Jun 24 '22 10:06 eeoom

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 23 '22 02:09 github-actions[bot]