Flutter & Ethereum : Unhandled Exception: RangeError: Value not in range: 32

Flutter & Ethereum : Unhandled Exception: RangeError: Value not in range: 32

我正在尝试使用 flutter 和 Ethereum 制作一个简单的去中心化应用程序。但我一直收到这个错误。它工作正常。请看看我的代码和我的错误

我使用:

问题:为什么我会得到这个 RangerError?

团结

pragma solidity 0.6.6;

    contract PKCoin{
        int balance;
        
        constructor() public {
            balance = 0;
        }
        
        function getBalance() view public returns(int) {
            return balance;
        }
        
        function depositBalance(int amount) public {
            balance = balance + amount;
        }
        
        function withdrawBalance(int amount) public {
            balance = balance - amount;
        }
    }

颤振

@override
  void initState() {
    super.initState();
    httpClient = Client();
    // print(httpClient);
    ethClient = Web3Client(
        "https://rinkeby.infura.io/v3/b2a9d5831e3b4675a51144cfed03bafa",
        httpClient);
    getBalance(myAddress);
  }

  Future<DeployedContract> loadContract() async {
    String abi = await rootBundle.loadString("assets/abi.json");
    String contractAddress = "0xd9145CCE52D386f254917e481eB44e9943F39138";

    final contract = DeployedContract(ContractAbi.fromJson(abi, "PKCoin"),
        EthereumAddress.fromHex(contractAddress));

    return contract;
  }

  // ==== This is to get the information only ==== //
  // ==== Get method ==== //

  Future<List<dynamic>> query(String functionName, List<dynamic> args) async {
    //
    final contract = await loadContract();
    final ethFunction = contract.function(functionName);
    
    // This line below doesn't work. 
    final result = await ethClient.call(
        contract: contract, function: ethFunction, params: args);

    // print(result.toString());
    return result;
  }

  Future<void> getBalance(String targetAddress) async {
    // EthereumAddress address = EthereumAddress.fromHex(targetAddress);
    List<dynamic> result = await query("getBalance", []);
    print('In getGreeting');
    print(result[0]);

    setState(() {
      myData = result[0];
      data = true;
    });
  }

错误

Performing hot restart...                                               
Restarted application in 950ms.
E/flutter (28032): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: RangeError: Value not in range: 32
E/flutter (28032): #0      _rangeCheck (dart:typed_data-patch/typed_data_patch.dart:4807:5)
E/flutter (28032): #1      _ByteBuffer.asUint8List (dart:typed_data-patch/typed_data_patch.dart:1940:5)
E/flutter (28032): #2      _IntTypeBase.decode (package:web3dart/src/contracts/abi/integers.dart:23:31)
E/flutter (28032): #3      TupleType.decode (package:web3dart/src/contracts/abi/tuple.dart:102:29)
E/flutter (28032): #4      ContractFunction.decodeReturnValues (package:web3dart/src/contracts/abi/abi.dart:255:30)
E/flutter (28032): #5      Web3Client.call (package:web3dart/src/core/client.dart:310:21)
E/flutter (28032): <asynchronous suspension>
E/flutter (28032): #6      _MyHomePageState.query (package:greeting_blockchain/main.dart:70:36)
E/flutter (28032): <asynchronous suspension>
E/flutter (28032): #7      _MyHomePageState.getBalance (package:greeting_blockchain/main.dart:79:34)
E/flutter (28032): #8      _MyHomePageState.initState (package:greeting_blockchain/main.dart:48:5)
E/flutter (28032): #9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58)
E/flutter (28032): #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (28032): #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #13     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter (28032): #14     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #15     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #16     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (28032): #17     Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (28032): #18     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter (28032): #19     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (28032): #20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #21     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #22     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter (28032): #23     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #24     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #25     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter (28032): #26     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #27     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (28032): #29     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (28032): #30     Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (28032): #31     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter (28032): #32     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11)
E/flutter (28032): #33     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (28032): #34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #35     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #36     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter (28032): #37     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #38     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #39     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter (28032): #40     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (28032): #41     Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (28032): #42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (28032): #43     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (28032): #44     Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (28032): #45     ComponentElement._firstBuild (package:flutter/src/widgets/framework.d

结论 请查看我的代码,我期待看到您的所有答案。提前谢谢你。

取消注释 //EthereumAddress address = EthereumAddress.fromHex(targetAddress);

  Future<void> getBalance(String targetAddress) async {
EthereumAddress address = EthereumAddress.fromHex(targetAddress);
List<dynamic> result = await query("getBalance", []);
print('In getGreeting');
print(result[0]);

setState(() {
  myData = result[0];
  data = true;
});

}