convertJsonStringPositions method
do not remove
Implementation
// Future<void> createOrUpdatePrint({required String printDesign, String? id}) async {
// var jsonString = {
// 'image_url': '',
// 'email': 'abcd@gmail.com',
// 'website': 'www.abc.com',
// 'phone': '27777777',
// 'mobile': '9999999999',
// 'company_name': 'abc company ltd',
// 'isSelect': selectedTemplate.value,
// 'template_index': 100,
// 'isThermalPrinter': false,
// 'coverImage': "assets/image/a4_default_temp.png",
// };
//
// final updateJsonString = json.encode(jsonString);
//
// if (id != null) {
// printTempUpdateFO.value = PrintTempUpdateFO(
// id: id,
// name: 'Custom A4 Template',
// type: 0,
// branchId: userHiveBox.values
// .toList()
// .firstWhereOrNull(
// (element) => element.isActive == true,
// )
// ?.selectedBranchId,
// jsonString: updateJsonString,
// printDesigner: printDesign,
// );
// } else {
// printTempUpdateFO.value = PrintTempUpdateFO(
// name: 'Custom A4 Template',
// type: 0,
// branchId: userHiveBox.values
// .toList()
// .firstWhereOrNull(
// (element) => element.isActive == true,
// )
// ?.selectedBranchId,
// jsonString: updateJsonString,
// printDesigner: printDesign,
// );
// }
//
// var response = await repo.updatePrintTemplate(input: printTempUpdateFO.value);
//
// response.fold((left) {}, (right) async {
// fnShowSnackBarSucess(LocalName.updateSuccessMsg.tr);
// await localItemDbController.storeAndFetchPrinterTemplateData();
// });
// }
// Future<void> fromAndToBranchFetch() async {
// final allBranches = await StockTransferRepo.newBranchDropdownWithoutUserId(0, -1, '');
// maxLengthFromBranchName.value = appUserController.userBranchDetailsFromLocal.reduce((a, b) => a.name.length > b.name.length ? a : b).name;
// maxLengthToBranchName.value = allBranches.items.reduce((a, b) => a.label.length > b.label.length ? a : b,).label;
// }
List<PrinterDesignerPackageListModel> convertJsonStringPositions(String positionJson) {
if (positionJson.isEmpty) {
return [];
}
try {
Map<String, dynamic> positionJsonDecode = jsonDecode(positionJson);
// Get data for the current screen from tabsJson or fallback to positionJsonDecode
final packageData = tabsJson[screen] ?? positionJsonDecode[screen] ?? {};
if (packageData['items'] == null) {
devPrintError('Inside here empty');
return [];
}
return (packageData['items'] as List).map((item) {
double positionY = (item['positionY'] as double);
Map<String, dynamic> sectionPosition = packageData['section'];
switch (item['section']) {
case 'subHeader':
positionY += sectionPosition['subHeader']; //100;
break;
case 'subBody':
positionY += sectionPosition['subBody']; //510;
break;
case 'footer':
positionY += sectionPosition['footer']; //685;
break;
}
return PrinterDesignerPackageListModel(
id: item['id'],
section: item['section'],
label: item['label'],
imageUrl: item['imageUrl'],
type: item['type'],
value: item['value'],
prefix: item['prefix'],
positionX: (item['positionX'] ?? 0) - 3,
positionY: positionY,
height: item['height'],
width: (item['width'] ?? 0),
isSelected: item['isSelected'],
customText: item['customText'],
properties: PrintDesignPackageProperties(
fontSize: (item['properties']?['font_size'] ?? 10),
textColor: item['properties']?['text_color'] ?? 4278190080,
fontWeight: item['properties']?['font_weight'] ?? 400,
textAlign: item['properties']?['text_align'] ?? TextAlign.left.toString(),
isPrefixNeeded: item['properties']?['is_prefix_needed'] ?? false,
direction: item['properties']?['direction'] ?? 'horizontal',
prefixFontSize: (item['properties']?['prefix_font_size'] ?? 10),
prefixTextColor: item['properties']?['prefix_text_color'] ?? 4278190080,
prefixFontWeight: item['properties']?['prefix_font_weight'] ?? 400,
),
);
}).toList();
} catch (e) {
return [];
}
}