fetchData static method

Future<void> fetchData(
  1. String url
)

Implementation

static Future<void> fetchData(String url) async {
  final requestId = DateTime.now().millisecondsSinceEpoch;
  DKLog.i('[$requestId] 开始请求: $url', tag: 'HTTP');

  final stopwatch = Stopwatch()..start();

  try {
    // 模拟请求
    await Future.delayed(const Duration(seconds: 1));

    stopwatch.stop();
    DKLog.s(
      '[$requestId] 请求成功,耗时: ${stopwatch.elapsedMilliseconds}ms',
      tag: 'HTTP',
    );

    // 记录响应
    final response = {'code': 200, 'message': 'success'};
    DKLog.json(response, tag: 'HTTP-Response');
  } catch (e, stack) {
    stopwatch.stop();
    DKLog.e(
      '[$requestId] 请求失败,耗时: ${stopwatch.elapsedMilliseconds}ms',
      tag: 'HTTP',
      error: e,
      stackTrace: stack,
    );
  }
}