onWeightChange property

Stream<WeighDetailModel> onWeightChange

Implementation

static Stream<WeighDetailModel> get onWeightChange {
  Stream<dynamic> receiveBroadcastStream =
      _sWeightEventChannel.receiveBroadcastStream();
  var nb = StreamTransformer.fromHandlers(
      //数据回调方法
      handleData: (dynamic data, EventSink<WeighDetailModel> sink) {
    Map<String, dynamic> eventMap = new Map<String, dynamic>.from(data);
    WeighDetailModel weighDetailModel = WeighDetailModel();
    if (eventMap.containsKey(WeightConstants.WEIGHT_PARAM_MODEL)) {
      weighDetailModel.model = eventMap[WeightConstants.WEIGHT_PARAM_MODEL];
    }
    if (eventMap.containsKey(WeightConstants.WEIGHT_PARAM_STATUS)) {
      weighDetailModel.status = eventMap[WeightConstants.WEIGHT_PARAM_STATUS];
    }
    if (eventMap.containsKey(WeightConstants.WEIGHT_PARAM_IS_ZERO)) {
      weighDetailModel.isZero =
          eventMap[WeightConstants.WEIGHT_PARAM_IS_ZERO];
    }
    if (eventMap.containsKey(WeightConstants.WEIGHT_PARAM_NET_WEIGHT)) {
      weighDetailModel.netWeight =
          eventMap[WeightConstants.WEIGHT_PARAM_NET_WEIGHT];
    }
    if (eventMap.containsKey(WeightConstants.WEIGHT_PARAM_NET_WEIGHT)) {
      weighDetailModel.netWeight =
          eventMap[WeightConstants.WEIGHT_PARAM_NET_WEIGHT];
    }
    if (eventMap.containsKey(WeightConstants.WEIGHT_PARAM_IS_STABLE)) {
      weighDetailModel.isStable =
          eventMap[WeightConstants.WEIGHT_PARAM_IS_STABLE];
    }
    sink.add(weighDetailModel);
  });

  Stream<WeighDetailModel> newStream =
      receiveBroadcastStream.transform<WeighDetailModel>(nb);
  return newStream.asBroadcastStream();
}