RootSoft / algorand-dart

Unofficial community SDK to interact with the Algorand network, for Dart & Flutter
MIT License
36 stars 16 forks source link

Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast when try to get List<AssetHolding> from .indexer().getAccountById() #34

Closed jasonhtpham closed 2 years ago

jasonhtpham commented 2 years ago

This code

AccountResponse accResponse = await AlgorandHelpers.algorand
          .indexer()
          .getAccountById(account.publicAddress);

      AccountInformation accInfo = accResponse.account;

      logger.i("Assets:", accInfo);

      final assets = accInfo.assets;

      logger.i("Assets:", assets.length);

gives me this error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast
E/flutter (  815): #0      _$AssetHoldingFromJson
package:algorand_dart/…/assets/asset_holding_model.g.dart:12
E/flutter (  815): #1      new AssetHolding.fromJson
package:algorand_dart/…/assets/asset_holding_model.dart:43
E/flutter (  815): #2      _$AccountInformationFromJson.<anonymous closure>
package:algorand_dart/…/accounts/account_information_model.g.dart:21
E/flutter (  815): #3      MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
E/flutter (  815): #4      ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
E/flutter (  815): #5      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:206:27)
E/flutter (  815): #6      new _GrowableList.of (dart:core-patch/growable_array.dart:153:28)
E/flutter (  815): #7      new List.of (dart:core-patch/array_patch.dart:51:28)
E/flutter (  815): #8      ListIterable.toList (dart:_internal/iterable.dart:213:44)
E/flutter (  815): #9      _$AccountInformationFromJson
package:algorand_dart/…/accounts/account_information_model.g.dart:22
E/flutter (  815): #10     new AccountInformation.fromJson
package:algorand_dart/…/accounts/account_information_model.dart:116
E/flutter (  815): #11     _$AccountResponseFromJson
package:algorand_dart/…/accounts/account_lookup_response.g.dart:13
E/flutter (  815): #12     new AccountResponse.fromJson
package:algorand_dart/…/accounts/account_lookup_response.dart:15
E/flutter (  815): #13     _AccountService.getAccountById
package:algorand_dart/…/services/account_service_impl.dart:70

My suspect is because there is no creator property in the assets object.

jasonhtpham commented 2 years ago

version 1.0.3 fixes the issue! Thank you

hm122 commented 2 years ago

It looks like creator has been completely removed from AccountHolding: https://algorand.github.io/java-algorand-sdk/com/algorand/algosdk/v2/client/model/AssetHolding.html

jasonhtpham commented 2 years ago

Hmmmm.... I see. The package actually defines creator as a nullable string so that makes sense.

RootSoft commented 2 years ago

Yes, the indexer introduced a breaking api change to support unlimited applications & assets. To minimize the breaking change I've made the creator a nullable string rather then removing it.