From 3f426c8abe4ea717916d90f4cbfbeb32fbe74700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zcan=20O=C4=9Fuz?= Date: Sat, 1 Jul 2023 18:14:17 +0300 Subject: [PATCH] Add zebra stripped table functionality --- lib/app/modules/home/controllers/home_controller.dart | 10 +++++++++- lib/app/modules/home/views/home_view.dart | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/app/modules/home/controllers/home_controller.dart b/lib/app/modules/home/controllers/home_controller.dart index 7d43609..61f73ad 100644 --- a/lib/app/modules/home/controllers/home_controller.dart +++ b/lib/app/modules/home/controllers/home_controller.dart @@ -24,6 +24,7 @@ class HomeController extends GetxController { var paperSizeSelection = [true, false].obs; final qrChecked = true.obs; final ocrChecked = true.obs; + final zebraChecked = true.obs; final currentStep = 0.obs; final directoryToWrite = ".".obs; late pw.Document pdf; @@ -48,6 +49,9 @@ class HomeController extends GetxController { super.onInit(); } + Function(bool?)? get zebra => + ocrChecked.value ? (bool? value) => zebraChecked.value = value! : null; + Future filePicker() async { FilePickerResult? result; try { @@ -210,6 +214,9 @@ class HomeController extends GetxController { }, build: (pw.Context context) => [ pw.TableHelper.fromTextArray( + oddRowDecoration: zebraChecked.value + ? pw.BoxDecoration(color: PdfColor.fromHex("#ededed")) + : null, data: hashes, border: pw.TableBorder.all(style: pw.BorderStyle.none), cellStyle: pw.TextStyle( @@ -219,7 +226,7 @@ class HomeController extends GetxController { cellPadding: const pw.EdgeInsets.all(0), headerStyle: pw.TextStyle(font: pw.Font.ttf(fonts.courier.bold)), - ) + ), ])); } final file = File(path); @@ -285,6 +292,7 @@ class HomeController extends GetxController { ocrText: ocrChecked.value, letterPaper: paperSizeSelection[1]); } catch (e) { + debugPrint(e.toString()); Get.snackbar("Error", "PDF creation failed", snackPosition: SnackPosition.BOTTOM); loading.value = false; diff --git a/lib/app/modules/home/views/home_view.dart b/lib/app/modules/home/views/home_view.dart index 603a53d..3edc991 100644 --- a/lib/app/modules/home/views/home_view.dart +++ b/lib/app/modules/home/views/home_view.dart @@ -126,6 +126,15 @@ class HomeView extends GetView { subtitle: const Text( "Recommended, this option adds OCR readable text with checksums for each line"), ), + ListTile( + leading: Checkbox( + value: controller.zebraChecked.value, + onChanged: controller.zebra), + enabled: controller.ocrChecked.value, + title: const Text('Zebra-stripped table'), + subtitle: const Text( + "Make OCR page lines zebra stripped. It makes lines easy to follow by eye but may cause OCR errors."), + ), ], ), ],