updateBug method
Future<Response>
updateBug({
- required String title,
- required String reportId,
- required String description,
- required String type,
- required String priority,
- required String source,
- required String reporterId,
- required String appId,
- required String device,
- required String os,
- required String screenResolution,
- required String networkType,
- required String batteryLevel,
- required String appIdCall,
- required String reportingTokenCall,
- List<
String?> ? removedMediaId, - List<
File> ? mediaFiles, - File? crashLog,
Implementation
Future<Response> updateBug(
{required String title,
required String reportId,
required String description,
required String type,
required String priority,
required String source,
required String reporterId,
required String appId,
required String device,
required String os,
required String screenResolution,
required String networkType,
required String batteryLevel,
required String appIdCall,
required String reportingTokenCall,
List<String?>? removedMediaId,
List<File>? mediaFiles,
File? crashLog}) async {
try {
List<MultipartFile> mediaFileList = [];
if (mediaFiles != null && mediaFiles.isNotEmpty) {
for (File mediaFile in mediaFiles) {
if (mediaFile.path.startsWith('http')) {
continue; // Skip files that start with 'http'
}
String fileName = path.basename(mediaFile.path);
String fileExtension = path.extension(mediaFile.path).substring(1);
String contentType = 'application/octet-stream';
if (fileExtension == 'jpg' || fileExtension == 'jpeg') {
contentType = 'image/jpeg';
} else if (fileExtension == 'png') {
contentType = 'image/png';
} else if (fileExtension == 'mp3') {
contentType = 'audio/mpeg';
}
mediaFileList.add(await MultipartFile.fromFile(mediaFile.path,
filename: fileName, contentType: MediaType.parse(contentType)));
}
}
Map<String, dynamic> deviceMetadata = {
'device': device,
'os': os,
'screenResolution': screenResolution,
'networkType': networkType,
'batteryLevel': batteryLevel,
};
FormData formData = FormData.fromMap({
'title': title,
'description': description,
'type': type.toUpperCase(),
'priority': priority.toUpperCase(),
'source': source,
'reporterId': reporterId,
'appId': appIdCall,
'deviceMetadata': jsonEncode(deviceMetadata),
if (mediaFileList.isNotEmpty) 'newMediaFiles': mediaFileList,
if(removedMediaId != null) 'mediaToRemoveIds': removedMediaId,
});
if (crashLog != null) {
String crashLogFileName = path.basename(crashLog.path);
String crashLogFileExtension =
path.extension(crashLog.path).substring(1);
String crashLogContentType = 'application/octet-stream';
if (crashLogFileExtension == 'txt') {
crashLogContentType = 'text/plain';
}
MultipartFile crashLogFile = await MultipartFile.fromFile(
crashLog.path,
filename: crashLogFileName,
contentType: MediaType.parse(crashLogContentType),
);
formData.files.add(MapEntry('crashLog', crashLogFile));
}
Options options = Options(
contentType: 'multipart/form-data',
headers: {
'Authorization': 'Bearer $reportingTokenCall',
},
);
return _dio
.patch<Map<String, dynamic>>(
'${QuashConstants.baseUrl}${QuashConstants.updateBugEndPoint}$reportId',
data: formData,
options: options,
)
.then((value) async {
return value;
}).catchError((e){
Fluttertoast.showToast(msg: 'An error occurred while updating bug $e');
return e;
});
} catch (e) {
Fluttertoast.showToast(msg: 'An error occurred while updating bug $e');
rethrow;
}
}