小编Del*_*ain的帖子

如何在 Flutter 中将 api 中的 Model 类设置为 0 或 null 值

我正在调用具有混合值的 api。有些值返回 0,有些值返回 int。但是当我调用该 api 时,出现以下错误:

The getter 'actualTotalFee' was called on null.
Receiver: null
Tried calling: actualTotalFee
Run Code Online (Sandbox Code Playgroud)

我的API响应是:

"summary": {
        "said_fee": 0,
        "nos": 11,
        "currentPayable": 0,
        "eximp-sem": 1,
        "sum_of_tution_fee": 173875,
        "common_scholarship": 0,
        "actual_total_fee": 0,
        "special_scholarship": 10000,
        "per_semester_fee": 0,
        "per_semester_fee_without_scholarship": 0,
        "total_paid": 190000,
        "total_current_due": -200000,
        "Due_Up_to_April": -200000,
        "total_due": -200000
      }
Run Code Online (Sandbox Code Playgroud)

我的api调用方法:

// Getting Accounts Summery
  Future<AccountSummery> fetchAccountSummery(int userId) async {
    
    final url =
        Api.baseUrl + 'student_account_info_summary/$userId?token=$authToken';

    try {
      final response = await get(Uri.encodeFull(url));

      final loadedItem = json.decode(response.body);

      if (response.statusCode == …
Run Code Online (Sandbox Code Playgroud)

api null response dart flutter

1
推荐指数
1
解决办法
4170
查看次数

标签 统计

api ×1

dart ×1

flutter ×1

null ×1

response ×1