streamHttp static method

void streamHttp(
  1. String url, {
  2. required Map<String, dynamic> parameters,
  3. dynamic onSuccess(
    1. Map response
    )?,
  4. dynamic onError(
    1. String error
    )?,
})

Implementation

static void streamHttp(
  String url, {
  required Map<String, dynamic> parameters,
  Function(Map response)? onSuccess,
  Function(String error)? onError,
}) async {
  //更新header参数配置
  Dio newDio = Dio();
  dio!.options.headers = {};

  Response request = await newDio.get(url);

  if (request.statusCode == 200) {
    if (onSuccess != null) onSuccess({"json": request.data});
  } else {
    if (onError != null) onError("请求错误");
  }
}