调试 Future 异步颤振

时间:2021-03-30 14:04:28

标签: flutter dart

我想测试这个函数的输出......我如何使用检查或打印来调试它?

  Future<YourDataEntity> getproduct(int id) async {
    var response = await Network().getData('/publication/show/$id');
       return YourDataEntity.fromJson(response.body['publication']);
  }

1 个答案:

答案 0 :(得分:0)

将输出分配给临时变量怎么样?

import 'dart:developer';

Future<YourDataEntity> getproduct(int id) async {
  var response = await Network().getData('/publication/show/$id');
  final entity = YourDataEntity.fromJson(response.body['publication']);
  log(entity.toString())
  return entity;
}

但最正确的方法是使用调试器并在调用此函数的地方添加断点。

有一个很棒的视频可以教你: https://www.youtube.com/watch?v=ocvQ2aMluq8