0

i'm having some truble in Flutter.

flutter doctor -v output:

[✓] Flutter (Channel stable, 2.5.1, on macOS 11.6 20G165 darwin-x64, locale en-IT)
    • Flutter version 2.5.1 at /Users/me/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffb2ecea52 (6 days ago), 2021-09-17 15:26:33 -0400
    • Engine revision b3af521a05
    • Dart version 2.14.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/me/Library/Android/sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: /Applications/AndroidStudio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.0, Build version 13A233
    • CocoaPods version 1.11.2

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.60.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.26.0

[✓] Connected device (1 available)
    • SM G930F (mobile) • android-arm64 • Android 8.0.0 (API 26)

• No issues found!

I have recently updated and migrated my code to null safety and updated all the dependencies; since I do this, I have some problems with the in_app_purchase package version 1.0.8 (https://pub.dev/packages/in_app_purchase).

When i run the app on Android device (iOS devices works) i got an error:

Unhandled Exception: type 'int' is not a subtype of type 'String?' in type cast

while calling:

ProductDetailsResponse response = await InAppPurchase.instance.queryProductDetails({'MY_PRODUCT_ID'});

Right after the function got called, VSCode show me that the error happen in the sku_details_wrapper.g.dart file into the function that convert the json to SkuDetailsWrapper:

SkuDetailsWrapper _$SkuDetailsWrapperFromJson(Map json) {
  return SkuDetailsWrapper(
    description: json['description'] as String? ?? '',
    freeTrialPeriod: json['freeTrialPeriod'] as String? ?? '',
    introductoryPrice: json['introductoryPrice'] as String? ?? '',
    introductoryPriceMicros: json['introductoryPriceAmountMicros'] as String? ?? '',
    introductoryPriceCycles: json['introductoryPriceCycles'] as int? ?? 0,
    introductoryPricePeriod: json['introductoryPricePeriod'] as String? ?? '',
    price: json['price'] as String? ?? '',
    priceAmountMicros: json['priceAmountMicros'] as int? ?? 0,
    priceCurrencyCode: json['priceCurrencyCode'] as String? ?? '',
    priceCurrencySymbol: json['priceCurrencySymbol'] as String? ?? '',
    sku: json['sku'] as String? ?? '',
    subscriptionPeriod: json['subscriptionPeriod'] as String? ?? '',
    title: json['title'] as String? ?? '',
    type: const SkuTypeConverter().fromJson(json['type'] as String?),
    originalPrice: json['originalPrice'] as String? ?? '',
    originalPriceAmountMicros: json['originalPriceAmountMicros'] as int? ?? 0,
  );
}

In particular the error line is:

introductoryPriceMicros: json['introductoryPriceAmountMicros'] as String? ?? '',

where it try to convert an int (json['introductoryPriceAmountMicros']) to a String?.

Can you help me please? I'm not able to find any help online.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Marco
  • 1
  • 1
  • 2
  • Seems like a bug in the package, `introductoryPriceAmountMicros` is a `long` https://developer.android.com/reference/com/android/billingclient/api/SkuDetails#getIntroductoryPriceAmountMicros() – rckrd Sep 23 '21 at 11:12
  • Looking at the github repo i just found out that the error is a package bug described here: github.com/flutter/flutter/issues/90509 – Marco Sep 23 '21 at 14:25

2 Answers2

0

Try this:

introductoryPriceMicros: (json['introductoryPriceAmountMicros'] as int).toString()
rckrd
  • 3,124
  • 1
  • 13
  • 23
Tim Jacobs
  • 1,023
  • 1
  • 8
  • 14
  • I modify it and it actually works but file that show the error belong to an external package, is it safe to edit it? – Marco Sep 23 '21 at 13:51
  • It's kind of bad practice, but it's not unsafe or anything. The moment you update your package, you'll have the same error again, meaning you must make the change another time. Unless with this update they fix the bug, of course, in which case there's no harm done. – Tim Jacobs Sep 23 '21 at 14:11
  • 1
    Ok Thanks, i will keep the edit on that file and wait for an update of the package. – Marco Sep 23 '21 at 14:26
0

Version 1.0.9 of in_app_purchase seems to have fixed this issue: https://pub.dev/packages/in_app_purchase