imageListInCamera method

  1. @override
Future<Map<String, dynamic>> imageListInCamera()
override

Implementation

@override
Future<Map<String, dynamic>> imageListInCamera() async {
  // if (isRequestPending) {
  //   return {
  //     "isError": true,
  //     "message": "PENDING_PREVIOUS_REQUEST",
  //     "details": "Called imageListInCamera()"
  //   };
  // }
  try {
    if (initializedCamera.isEmpty) {
      return {"isError": true, "message": "Invalid camera operation!"};
    }
    // isRequestPending = true;

    List dataList = await methodChannel
        .invokeMethod('IMAGE_LIST', {"cameraId": initializedCamera});
    // isRequestPending = false;

    String arrayString = dataList[0];
    List<String> elements = arrayString.split('H264_DVR_FILE_DATA ');
    elements.removeAt(0);

    List<String> result = [];
    for (String element in elements) {
      int startIndex =
          element.indexOf("st_2_fileName=") + "st_2_fileName=".length;
      int endIndex = element.indexOf(", st_3_beginTime=");

      result.add(
          (element.substring(startIndex, endIndex)).replaceAll('/', '_'));
    }

    return {"isError": false, "dataList": result};
  } catch (e) {
    // isRequestPending = false;
    if (e is PlatformException) {
      return {"isError": true, "message": e.message};
    }

    return {"isError": true, "message": "Error: $e"};
  }
}