MethodChannelRequestor constructor

MethodChannelRequestor()

Implementation

MethodChannelRequestor() {
  methodChannel.setMethodCallHandler((call) async {
    switch (call.method) {
      case "download":
        String processId = call.arguments["processId"];
        for (CallBackListener cb in _getCB(processId)) {
          Map<String, dynamic> info =
              Map<String, dynamic>.from(call.arguments["info"]);
          Map<String, dynamic> network =
              Map<String, dynamic>.from(info["net"]);

          ResponseInfoDetail infoDetail = ResponseInfoDetail(
            timestamp: info["timestamp"],
            size: info["size"],
          );
          ResponseNetworkDetail networkDetail = ResponseNetworkDetail(
            type: network["type"],
            typeName: network["typeName"],
            state: network["state"],
            extra: network["extra"],
          );
          ResponseDetail responseDetail = ResponseDetail(
            network: networkDetail,
            detail: infoDetail,
          );

          SingleDownload response = SingleDownload(
            call.arguments["id"],
            call.arguments["url"],
            call.arguments["status"],
            call.arguments["statusCode"],
            call.arguments["data"],
            responseDetail,
            call.arguments["wildcard"],
          );

          cb.cbDownaload(response);
        }

        break;
      case "progress":
        String processId = call.arguments["processId"];
        for (CallBackListener cb in _getCB(processId)) {
          ProgressDownload response = ProgressDownload(
            call.arguments["id"],
            call.arguments["progress"],
            call.arguments["total"],
          );
          cb.cbProgress(response);
        }
        break;
    }
  });
}