Q:

Flutter in_app_purchase queryPastPurchases() returns empty list on iOS

Why does queryPastPurchases() return a populated list with my subscription on android, but returns an empty list on iOS?
I have a physical iOS SE phone, my apple user is added as an tester in testflight, I've added a subscription in App Store Connect, and I am able to buy the subscription(in testflight). However queryPastPurchases() returns an empty list...
  // Gets past purchases
  Future<void> _getPastPurchases() async {
    QueryPurchaseDetailsResponse response =
        await _iap.queryPastPurchases();

    for (PurchaseDetails purchase in response.pastPurchases) {
      if (Platform.isIOS) {
        InAppPurchaseConnection.instance.completePurchase(purchase);
      }
    }

    setState(() {
      _purchases = response.pastPurchases;
    });
  }

A:

Turns out there was nothing wrong with the code.
In order to make it work I had to create a sandbox user.
Then I had to log out from my current logged in AppID on the phone.
Then I had to "Edit Scheme" in Xcode from Release to Debug.
Then I ran "flutter run" in terminal.
Then I purchased my NonConsumable subscription, and in the dialog I had to enter the sandbox user email and pwd.
Updated:
Also I had to create a completely new subscription in app store connect, because the original subscription got trapped in a state were it was not bought nor purchasable. This was due to the fact that the completePurchase was done at the wrong place in my code.
It should not be done in _getPastPurchases(), but rather in the actual purchase logic.
So put completePurchase here:
_subscription = _iap.purchaseUpdatedStream.listen((data) => setState(() {
    _purchases.addAll(data);
    for(PurchaseDetails purchase in _purchases){
        if(purchase.productID == 'subName'){
            //SOLUTION
            if (Platform.isIOS) {
                InAppPurchaseConnection.instance.completePurchase(purchase);
            }
        }
    }   
}));

PS: I don't remember if I had the completePurchse in the for loop or outside...

