diff --git a/lib/services/esc_pos_print_service.dart b/lib/services/esc_pos_print_service.dart index 5efd7dc..a802f34 100644 --- a/lib/services/esc_pos_print_service.dart +++ b/lib/services/esc_pos_print_service.dart @@ -61,6 +61,22 @@ class EscPosPrintService { // Mulai dengan inisialisasi printer List bytes = []; + + // Coba tambahkan logo toko jika ada + final logoPath = prefs.getString('store_logo_path'); + if (logoPath != null && logoPath.isNotEmpty) { + try { + final img.Image? logo = await getImageFromFilePath(logoPath); + if (logo != null) { + // Mengubah ukuran logo agar pas di struk (lebar maks 300px) + final resizedLogo = img.copyResize(logo, width: 300); + bytes += generator.image(resizedLogo, align: PosAlign.center); + bytes += generator.feed(1); // Beri sedikit spasi setelah logo + } + } catch (e) { + print('Error loading or processing store logo: $e'); + } + } // Tambahkan nama toko sebagai header bytes += generator.text(storeName, @@ -185,7 +201,7 @@ class EscPosPrintService { String customDisclaimer; try { customDisclaimer = prefs.getString('store_disclaimer_text') ?? - 'Barang yang sudah dibeli tidak dapat dikembalikan/ditukar. ' + 'Barang yang sudah dibeli tidak dapat dikembalikan/ditukar. ' 'Harap periksa kembali struk belanja Anda sebelum meninggalkan toko.'; } catch (e) { print('Error saat memuat disclaimer: $e'); @@ -348,38 +364,18 @@ class EscPosPrintService { throw Exception('Gagal mencetak struk: $e'); } } -} -/// Data class to hold image processing parameters -class ImageProcessParams { - final Uint8List imageBytes; - final int maxWidth; - - ImageProcessParams(this.imageBytes, this.maxWidth); -} - -/// Helper function to decode and resize image in an isolate -Uint8List? processImageInIsolate(ImageProcessParams params) { - try { - // Decode image - img.Image? image = img.decodeImage(params.imageBytes); - - if (image != null) { - // Resize gambar agar sesuai dengan ukuran kertas printer - if (image.width > params.maxWidth) { - final ratio = params.maxWidth / image.width; - final newHeight = (image.height * ratio).round(); - image = img.copyResize(image, width: params.maxWidth, height: newHeight); + /// Helper function to get image from file path + static Future getImageFromFilePath(String path) async { + try { + final file = File(path); + if (await file.exists()) { + final bytes = await file.readAsBytes(); + return img.decodeImage(bytes); } - - // Convert image to bytes that can be sent back to main isolate - final imageBytes = Uint8List.fromList(img.encodePng(image)); - return imageBytes; + } catch (e) { + print('Error getting image from file path: $e'); } - - return null; - } catch (e) { - print('Error processing image in isolate: $e'); return null; } -} \ No newline at end of file +} diff --git a/lib/widgets/account_settings_widget.dart b/lib/widgets/account_settings_widget.dart index 1ccf3b6..c851258 100644 --- a/lib/widgets/account_settings_widget.dart +++ b/lib/widgets/account_settings_widget.dart @@ -20,12 +20,23 @@ class AccountSettingsWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 14, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 14, height: 1.2, - ), - ); + ); + } return Container( width: double.infinity, diff --git a/lib/widgets/add_item_button.dart b/lib/widgets/add_item_button.dart index ebf02a7..a0ce2a7 100644 --- a/lib/widgets/add_item_button.dart +++ b/lib/widgets/add_item_button.dart @@ -9,12 +9,23 @@ class AddItemButton extends StatelessWidget { @override Widget build(BuildContext context) { - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 14, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 14, height: 1.2, - ), - ); + ); + } return GestureDetector( onTap: onTap, diff --git a/lib/widgets/firefly_transaction_info.dart b/lib/widgets/firefly_transaction_info.dart index a1ba5d9..47f5fb8 100644 --- a/lib/widgets/firefly_transaction_info.dart +++ b/lib/widgets/firefly_transaction_info.dart @@ -15,12 +15,23 @@ class FireflyTransactionInfo extends StatelessWidget { @override Widget build(BuildContext context) { - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 14, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 14, height: 1.2, - ), - ); + ); + } return Container( width: double.infinity, diff --git a/lib/widgets/receipt_item_widget.dart b/lib/widgets/receipt_item_widget.dart index 843ec9c..d82404b 100644 --- a/lib/widgets/receipt_item_widget.dart +++ b/lib/widgets/receipt_item_widget.dart @@ -25,12 +25,23 @@ class ReceiptItemWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 14, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 14, height: 1.2, - ), - ); + ); + } return Container( width: double.infinity, diff --git a/lib/widgets/store_disclaimer.dart b/lib/widgets/store_disclaimer.dart index 273cf3f..37b7a22 100644 --- a/lib/widgets/store_disclaimer.dart +++ b/lib/widgets/store_disclaimer.dart @@ -43,12 +43,23 @@ class _StoreDisclaimerState extends State { @override Widget build(BuildContext context) { - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 12, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 12, height: 1.2, - ), - ); + ); + } return GestureDetector( onTap: widget.onTap, // Gunakan callback onTap dari widget diff --git a/lib/widgets/store_info_widget.dart b/lib/widgets/store_info_widget.dart index 2339698..b8134b8 100644 --- a/lib/widgets/store_info_widget.dart +++ b/lib/widgets/store_info_widget.dart @@ -46,12 +46,23 @@ class _StoreInfoWidgetState extends State { // Load data every time the widget is built to ensure it's up-to-date _loadStoreInfo(); - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 14, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 14, height: 1.2, - ), - ); + ); + } return GestureDetector( onTap: widget.onTap, // Panggil callback ketika di-tap diff --git a/lib/widgets/thank_you_pantun.dart b/lib/widgets/thank_you_pantun.dart index 2cb951a..d1afaf2 100644 --- a/lib/widgets/thank_you_pantun.dart +++ b/lib/widgets/thank_you_pantun.dart @@ -51,12 +51,23 @@ class _ThankYouPantunState extends State { @override Widget build(BuildContext context) { - final courierPrime = GoogleFonts.courierPrime( - textStyle: const TextStyle( + // Mencoba menggunakan Google Fonts Courier Prime, jika gagal gunakan font sistem + TextStyle courierPrime; + try { + courierPrime = GoogleFonts.courierPrime( + textStyle: const TextStyle( + fontSize: 12, + height: 1.2, + ), + ); + } catch (e) { + // Fallback ke font sistem jika Google Fonts tidak tersedia + courierPrime = const TextStyle( + fontFamily: 'CourierPrime, Courier, monospace', fontSize: 12, height: 1.2, - ), - ); + ); + } return GestureDetector( onTap: widget.onTap, // Gunakan callback onTap dari widget