getPHList method

Future<List<HuDetails>> getPHList({
  1. required String warehouseNumber,
  2. required bool isProd,
  3. String? packagingMaterial,
  4. String createdBy = 'HUMBAAPP',
  5. bool doNotIgnoreError = false,
  6. Options? getPHOptions,
})

Implementation

Future<List<HuDetails>> getPHList({
  required String warehouseNumber,
  required bool isProd,
  String? packagingMaterial,
  String createdBy = 'HUMBAAPP',
  bool doNotIgnoreError = false,
  Options? getPHOptions,
}) async {
  packagingMaterial ??= '24002808';

  try {
    Response<Json> response = await _unitsApiProvider.getPH(
      warehouseNumber: warehouseNumber,
      packagingMaterial: packagingMaterial,
      createdBy: createdBy,
      getPHOptions: getPHOptions,
    );

    if (response.statusCode != 200) {
      return [];
    }

    List<Json> jsonList = List<Json>.from(response.data?['results']);
    return jsonList.map(HuDetails.fromJson).toList();
  } on DioException catch (e) {
    if (doNotIgnoreError && e.response?.statusCode == 500) {
      rethrow;
    } else {
      return [];
    }
  } catch (e) {
    return [];
  }
}