updateControllerByLoc method
Future<void>
updateControllerByLoc(
{ - required bool needGps,
- required dynamic clientRetailerId,
})
Implementation
Future<void> updateControllerByLoc(
{required bool needGps, required var clientRetailerId}) async {
if (needGps) {
Map<String, String> locObjects =
await PermissionServices.getLocationData();
if (locObjects.isNotEmpty) {
try {
// Need to check:
updateIdentifierMap.forEach((mainKey, subKeys) {
for (var subKey in subKeys) {
if (subKey.containsKey(ConstantName.fieldName)) {
String fieldMatchKey = ErrorHandling.getContainsKey(
detail: locObjects,
inputKey: subKey[ConstantName.fieldName],
);
if (fieldMatchKey.isNotEmpty) {
subKey[ConstantName.controller].text =
locObjects[fieldMatchKey];
locObjects.remove(fieldMatchKey);
}
if (locObjects.isEmpty) {
break;
}
}
}
});
} catch (e) {
print('updateControllerByLoc: <controller Error>: $e');
}
}
if (locObjects.isNotEmpty) {
try {
List<Map<String, dynamic>> columnsInfo = await DatabaseHelper.instance
.getTableColumns(ConstantName.uploadRetailerIdTable);
/*
List<Map<String, dynamic>> columnsInfo = [
{'name': 'id', 'type': 'INTEGER'},
{'name': 'name', 'type': 'TEXT'},
{'name': 'age', 'type': 'INTEGER'}
];
*/
for (var column in columnsInfo) {
String columnMatchKey = ErrorHandling.getContainsKey(
detail: locObjects,
inputKey: column['name'] ?? '',
);
if (columnMatchKey.trim().isNotEmpty) {
var data = ErrorHandling.convertDataType(
dataType: column['type'], value: locObjects[columnMatchKey]);
// Insert Data to uploadRetailerIdTable:
await DatabaseHelper.instance.updateSpecificColumn(
tableName: ConstantName.uploadRetailerIdTable,
columnName: column['name'],
data: data,
whereArgsList: {
ConstantName.clientRetailerId: clientRetailerId
});
locObjects.remove(columnMatchKey);
}
if (locObjects.isEmpty) {
break;
}
// print('Column name: ${column['name']} - Type: ${column['type']}');
}
} catch (e) {
print('updateControllerByLoc: <db Error>: $e');
}
}
}
}