getSetDataFromDb method

Future<List<bool>> getSetDataFromDb()

Implementation

Future<List<bool>> getSetDataFromDb() async {
  List<bool> returnVal = [true, false];
  List<Map<String, dynamic>> formDetails = <Map<String, dynamic>>[];
  List<Map<String, dynamic>> formDependable = <Map<String, dynamic>>[];
  List<Map<String, dynamic>> formApi = <Map<String, dynamic>>[];

  await DatabaseHelper.instance
      .getSpecificRows(
          tableName: ConstantName.formDetailsTable,
          whereArgsList: {ConstantName.clientRetailerId: retailerID.text},
          changeDatatype: ConstantName.decodeFormDetailsTypes)
      .then((List result) {
    if (result[0]) {
      formDetails = result[1];
    } else {
      returnVal[0] = false;
    }
  });

  await DatabaseHelper.instance
      .getSpecificRows(
          tableName: ConstantName.formDependableTable,
          whereArgsList: {ConstantName.clientRetailerId: retailerID.text},
          changeDatatype: ConstantName.decodeFormDependableTypes)
      .then((List result) {
    if (result[0]) {
      formDependable = result[1];
    } else {
      returnVal[0] = false;
    }
  });

  await DatabaseHelper.instance
      .getSpecificRows(
          tableName: ConstantName.formApiTable,
          whereArgsList: {ConstantName.clientRetailerId: retailerID.text},
          changeDatatype: ConstantName.decodeFormApiTypes)
      .then((List result) {
    if (result[0]) {
      formApi = result[1];
    } else {
      returnVal[0] = false;
    }
  });

  if (formDetails.isNotEmpty ||
      formDependable.isNotEmpty ||
      formApi.isNotEmpty) {
    returnVal[0] = false;
    clearUserDetails();
    // Set data
    showIdentifierMap.value =
        await decodeJson2(jsonResponse: <String, dynamic>{
      ConstantName.formDetails: formDetails,
      ConstantName.formDependable: formDependable,
      ConstantName.formApi: formApi
    });

    // --> Copy showIdentifierMap to updateIdentifierMap without refrence start
    showIdentifierMap.forEach((key, value) {
      List<Map<String, dynamic>> newValue = [];
      for (var item in value) {
        Map<String, dynamic> newItem = Map<String, dynamic>.from(item);
        // Changed showIdentifierMap {controller : value} to {controller : TextEditingController}
        // Need to check:
        item[ConstantName.controller] = TextEditingController(
            text: item[ConstantName.controller]?.toString() ?? '');
        if (item[ConstantName.controller] != null) {
          newItem[ConstantName.controller] = TextEditingController.fromValue(
            item[ConstantName.controller].value,
          );
        }
        newValue.add(newItem);
      }
      updateIdentifierMap[key] = newValue;
    });

    retailerID.clear();
    returnVal = [true, true];
  }

  return returnVal;
}