Advertisement
kendy2900

page_struk

Apr 25th, 2022
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 29.31 KB | None | 0 0
  1. // import 'dart:io';
  2. // import 'dart:typed_data';
  3. import 'dart:async';
  4.  
  5. import 'package:te111/models/store.dart';
  6. import 'package:te111/models/transactionMember.dart';
  7. import 'package:te111/models/transaction_product.dart';
  8. import 'package:te111/models/user.dart';
  9. import 'package:te111/utils/database_helper.dart';
  10. import 'package:te111/utils/rupiah.dart';
  11. import 'package:intl/intl.dart';
  12. // import 'package:flutter/services.dart';
  13. // import 'package:path_provider/path_provider.dart';
  14. // import 'package:pdf/pdf.dart';
  15. // import 'package:pdf/widgets.dart' as pdf;
  16. // import 'dart:ui' as ui;
  17. import 'package:flutter/material.dart';
  18. import 'package:flutter/rendering.dart';
  19. // import 'package:printing/printing.dart';
  20. import 'package:blue_thermal_printer/blue_thermal_printer.dart';
  21. import 'package:shared_preferences/shared_preferences.dart';
  22. import '../../models/member.dart';
  23.  
  24. GlobalKey<State<StatefulWidget>> previewContainer = GlobalKey();
  25.  
  26. class PrintStrukPage extends StatefulWidget {
  27.   static const routeName = '/printStrukPage';
  28.   PrintStrukPageArgument? argument;
  29.   PrintStrukPage({this.argument});
  30.   @override
  31.   _PrintStrukPageState createState() => _PrintStrukPageState();
  32. }
  33.  
  34. class _PrintStrukPageState extends State<PrintStrukPage> {
  35.   TransactionModel? historyTransaction = TransactionModel();
  36.   Member? chooseMember = Member();
  37.   TransactionModel transactionModel = TransactionModel();
  38.   BlueThermalPrinter bluetooth = BlueThermalPrinter.instance;
  39.   final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  40.   String? pathImage, qtyBrg, hrgBrg, totalNet;
  41.   BlueThermalPrinter con = BlueThermalPrinter.instance;
  42.   List<TransactionProduct>? transactionProduct = [];
  43.   User user = User();
  44.   Store? storedata;
  45.   String? addRessPrint = '', namaPrinter = '';
  46.   DatabaseHelper dbHelper = DatabaseHelper();
  47.   List<BluetoothDevice> _devices = [];
  48.   BluetoothDevice? _device;
  49.   bool _connected = false, isLoading = false;
  50.  
  51.   Future<Store?> getStoreData() async {
  52.     final result = await dbHelper.getStoreDetail();
  53.     if (result != null) {
  54.       setState(() {
  55.         storedata = result;
  56.       });
  57.     }
  58.     return result;
  59.   }
  60.  
  61.   getUser() async {
  62.     final result = await dbHelper.getUserList();
  63.     if (result != null) {
  64.       setState(() {
  65.         user = result.first;
  66.       });
  67.     }
  68.   }
  69.  
  70.   getPrinter() async {
  71.     SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  72.     setState(() {
  73.       addRessPrint = (sharedPreferences.getString('print')! ?? "");
  74.       namaPrinter = (sharedPreferences.getString('printer_name')! ?? "");
  75.     });
  76.     print('kendy ' + addRessPrint! ?? '');
  77.  
  78.     // kon();
  79.   }
  80.  
  81.   void kon() async {
  82.     setState(() {
  83.       // if (pConnected == 1) {
  84.       if (namaPrinter != '' && addRessPrint != '') {
  85.         print("Printer terhubung ke " + namaPrinter!);
  86.         _device = BluetoothDevice(namaPrinter, addRessPrint);
  87.         connect();
  88.       } else {
  89.         _device = null;
  90.       }
  91.       // print("Konek ke $namaPrinter $addRessPrint");
  92.  
  93.       // }
  94.     });
  95.   }
  96.  
  97.   void connect() {
  98.     if (_device == null) {
  99.     } else {
  100.       con.isConnected.then((isConnected) async {
  101.         if (!isConnected!) {
  102.           await con.connect(_device!).catchError((error) {
  103.             setState(() => _connected = false);
  104.           });
  105.           setState(() => _connected = true);
  106.         }
  107.       });
  108.     }
  109.   }
  110.  
  111.   @override
  112.   void initState() {
  113.     super.initState();
  114.     getStoreData();
  115.     // getUser();
  116.     getPrinter();
  117.     transactionProduct = widget.argument!.transactionProduct;
  118.     chooseMember = widget.argument!.member;
  119.     historyTransaction = widget.argument!.transactionModel;
  120.   }
  121.  
  122.   _disconnect() async {
  123.     await bluetooth.disconnect();
  124.     setState(() => _connected = true);
  125.   }
  126.  
  127.   @override
  128.   Widget build(BuildContext context) {
  129.     return Scaffold(
  130.       key: _scaffoldKey,
  131.       appBar: AppBar(
  132.         actions: <Widget>[
  133.           IconButton(
  134.             icon: Icon(Icons.print),
  135.             tooltip: "Cetak Struk",
  136.             onPressed: tesKoneksi,
  137.           )
  138.         ],
  139.         elevation: 0.0,
  140.         backgroundColor: Colors.blue,
  141.         title: Text(
  142.           'Cetak Struk',
  143.           style: TextStyle(
  144.               fontWeight: FontWeight.w600, color: Colors.white, fontSize: 16.0),
  145.         ),
  146.         automaticallyImplyLeading: true,
  147.         iconTheme: IconThemeData(
  148.           color: Colors.white, //change your color here
  149.         ),
  150.       ),
  151.       body: SingleChildScrollView(
  152.         child: Column(
  153.           crossAxisAlignment: CrossAxisAlignment.start,
  154.           children: <Widget>[
  155.             SingleChildScrollView(
  156.                 physics: ClampingScrollPhysics(),
  157.                 child: Padding(
  158.                     padding: EdgeInsets.all(10),
  159.                     child: Card(
  160.                         elevation: 5.0,
  161.                         color: Colors.white,
  162.                         child: Padding(
  163.                           padding: const EdgeInsets.all(8.0),
  164.                           child: Column(
  165.                               mainAxisAlignment: MainAxisAlignment.start,
  166.                               children: <Widget>[
  167.                                 Column(
  168.                                   children: <Widget>[
  169.                                     Container(
  170.                                       width: double.infinity,
  171.                                       // height: 50,
  172.                                       child: Align(
  173.                                           alignment: Alignment.topCenter,
  174.                                           child: Text(
  175.                                               "${storedata?.storeName ?? ""}",
  176.                                               style: TextStyle(
  177.                                                   fontWeight: FontWeight.w600,
  178.                                                   fontSize: 20))),
  179.                                     ),
  180.                                     Container(
  181.                                       width: double.infinity,
  182.                                       // height: 50,
  183.                                       child: Align(
  184.                                           alignment: Alignment.topCenter,
  185.                                           child: Text(
  186.                                               storedata?.storeAddress != null &&
  187.                                                       storedata!.storeAddress!
  188.                                                           .isNotEmpty
  189.                                                   ? storedata!.storeAddress!
  190.                                                   : '',
  191.                                               style: TextStyle(
  192.                                                   fontWeight: FontWeight.w500,
  193.                                                   fontSize: 16))),
  194.                                     ),
  195.                                     Container(
  196.                                       width: double.infinity,
  197.                                       // height: 50,
  198.                                       child: Align(
  199.                                           alignment: Alignment.topCenter,
  200.                                           child: Text(
  201.                                               storedata?.storePhoneNumber !=
  202.                                                       null
  203.                                                   ? storedata!.storePhoneNumber!
  204.                                                   : '',
  205.                                               style: TextStyle(
  206.                                                   fontWeight: FontWeight.w500,
  207.                                                   fontSize: 16))),
  208.                                     ),
  209.                                     Container(
  210.                                       width: double.infinity,
  211.                                       // height: 50,
  212.                                       child: Align(
  213.                                           alignment: Alignment.topCenter,
  214.                                           child: Text(
  215.                                               "======================================================",
  216.                                               style: TextStyle(
  217.                                                   fontWeight: FontWeight.w500,
  218.                                                   fontSize: 12))),
  219.                                     ),
  220.                                   ],
  221.                                 ),
  222.                                 Container(
  223.                                   // color: Colors.green,
  224.                                   width: double.infinity,
  225.                                   padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
  226.                                   child: Align(
  227.                                       alignment: Alignment.center,
  228.                                       child: Text(
  229.                                           historyTransaction!.noteNumber! +
  230.                                               " / " +
  231.                                               " / " +
  232.                                               DateFormat('dd-MM-yyyy').format(
  233.                                                   DateTime.parse(
  234.                                                       historyTransaction!
  235.                                                           .transactionDate!)) +
  236.                                               ' ' +
  237.                                               DateFormat('HH:mm')
  238.                                                   .format(DateTime.now()),
  239.                                           style: TextStyle(
  240.                                               fontWeight: FontWeight.w500,
  241.                                               fontSize: 14))),
  242.                                 ),
  243.                                 Container(
  244.                                   width: double.infinity,
  245.                                   // height: 50,
  246.                                   child: Align(
  247.                                       alignment: Alignment.topCenter,
  248.                                       child: Text(
  249.                                           "======================================================",
  250.                                           style: TextStyle(
  251.                                               fontWeight: FontWeight.w500,
  252.                                               fontSize: 12))),
  253.                                 ),
  254.                                 buildListItem(),
  255.                                 Container(
  256.                                   width: double.infinity,
  257.                                   // height: 50,
  258.                                   child: Align(
  259.                                       alignment: Alignment.topCenter,
  260.                                       child: Text(
  261.                                           "======================================================",
  262.                                           style: TextStyle(
  263.                                               fontWeight: FontWeight.w500,
  264.                                               fontSize: 12))),
  265.                                 ),
  266.                                 Container(
  267.                                   width: double.infinity,
  268.                                   padding: EdgeInsets.fromLTRB(25, 2, 25, 2),
  269.                                   child: Row(
  270.                                     mainAxisAlignment:
  271.                                         MainAxisAlignment.spaceBetween,
  272.                                     children: <Widget>[
  273.                                       Text("Grand Total",
  274.                                           style: TextStyle(
  275.                                               fontWeight: FontWeight.w500,
  276.                                               fontSize: 14)),
  277.                                       Text(
  278.                                           'Rp ${rupiah(historyTransaction!.transactionTotalPrice!.toInt() + historyTransaction!.transactionUserDiscount!.toInt())}',
  279.                                           style: TextStyle(
  280.                                               fontWeight: FontWeight.w500,
  281.                                               fontSize: 16)),
  282.                                     ],
  283.                                   ),
  284.                                 ),
  285.                                 historyTransaction!.transactionUserDiscount! > 0
  286.                                     ? Container(
  287.                                         width: double.infinity,
  288.                                         padding:
  289.                                             EdgeInsets.fromLTRB(25, 2, 25, 2),
  290.                                         child: Row(
  291.                                           mainAxisAlignment:
  292.                                               MainAxisAlignment.spaceBetween,
  293.                                           children: <Widget>[
  294.                                             Text("Diskon",
  295.                                                 style: TextStyle(
  296.                                                     fontWeight: FontWeight.w500,
  297.                                                     fontSize: 14)),
  298.                                             Text(
  299.                                                 'Rp ${rupiah(historyTransaction!.transactionUserDiscount!.toInt())}',
  300.                                                 style: TextStyle(
  301.                                                     fontWeight: FontWeight.w500,
  302.                                                     fontSize: 16)),
  303.                                           ],
  304.                                         ),
  305.                                       )
  306.                                     : SizedBox(height: 1),
  307.                                 historyTransaction!.transactionUserDiscount! > 0
  308.                                     ? Container(
  309.                                         width: double.infinity,
  310.                                         padding:
  311.                                             EdgeInsets.fromLTRB(25, 2, 25, 2),
  312.                                         child: Row(
  313.                                           mainAxisAlignment:
  314.                                               MainAxisAlignment.spaceBetween,
  315.                                           children: <Widget>[
  316.                                             Text("TOTAL",
  317.                                                 style: TextStyle(
  318.                                                     fontWeight: FontWeight.w500,
  319.                                                     fontSize: 14)),
  320.                                             Text(
  321.                                                 'Rp ${rupiah(historyTransaction!.transactionTotalPrice!.toInt())}',
  322.                                                 style: TextStyle(
  323.                                                     fontWeight: FontWeight.w500,
  324.                                                     fontSize: 16)),
  325.                                           ],
  326.                                         ),
  327.                                       )
  328.                                     : SizedBox(height: 1),
  329.                                 Container(
  330.                                   width: double.infinity,
  331.                                   padding: EdgeInsets.fromLTRB(25, 2, 25, 2),
  332.                                   child: Row(
  333.                                     mainAxisAlignment:
  334.                                         MainAxisAlignment.spaceBetween,
  335.                                     children: <Widget>[
  336.                                       Text("TUNAI",
  337.                                           style: TextStyle(
  338.                                               fontWeight: FontWeight.w500,
  339.                                               fontSize: 14)),
  340.                                       Text(
  341.                                           'Rp ${rupiah(historyTransaction!.transactionUserPayment!.toInt() * 100)}',
  342.                                           style: TextStyle(
  343.                                               fontWeight: FontWeight.w500,
  344.                                               fontSize: 16)),
  345.                                     ],
  346.                                   ),
  347.                                 ),
  348.                                 Container(
  349.                                   width: double.infinity,
  350.                                   padding: EdgeInsets.fromLTRB(25, 2, 25, 2),
  351.                                   child: Row(
  352.                                     mainAxisAlignment:
  353.                                         MainAxisAlignment.spaceBetween,
  354.                                     children: <Widget>[
  355.                                       Text("Kembalian",
  356.                                           style: TextStyle(
  357.                                               fontWeight: FontWeight.w500,
  358.                                               fontSize: 14)),
  359.                                       Text(
  360.                                           'Rp ${rupiah(historyTransaction!.transactionUserReturnChange!.toInt() * 100)}',
  361.                                           style: TextStyle(
  362.                                               fontWeight: FontWeight.w500,
  363.                                               fontSize: 16)),
  364.                                     ],
  365.                                   ),
  366.                                 ),
  367.                               ]),
  368.                         ))))
  369.           ],
  370.         ),
  371.       ),
  372.     );
  373.   }
  374.  
  375.   Container buildListItem() {
  376.     return Container(
  377.       alignment: Alignment.centerRight,
  378.       width: double.infinity,
  379.       padding: EdgeInsets.fromLTRB(25, 2, 25, 2),
  380.       // height: 50,
  381.       child: Row(
  382.         crossAxisAlignment: CrossAxisAlignment.start,
  383.         mainAxisAlignment: MainAxisAlignment.spaceBetween,
  384.         children: <Widget>[
  385.           Expanded(
  386.               child: Column(
  387.                   mainAxisAlignment: MainAxisAlignment.start,
  388.                   crossAxisAlignment: CrossAxisAlignment.start,
  389.                   children: List.generate(transactionProduct!.length, (index) {
  390.                     return Container(
  391.                         alignment: Alignment.center,
  392.                         margin: EdgeInsets.only(bottom: 8.0),
  393.                         padding: EdgeInsets.only(bottom: 8),
  394.                         child: Row(
  395.                           mainAxisAlignment: MainAxisAlignment.spaceBetween,
  396.                           crossAxisAlignment: CrossAxisAlignment.center,
  397.                           children: <Widget>[
  398.                             Column(
  399.                               crossAxisAlignment: CrossAxisAlignment.start,
  400.                               children: <Widget>[
  401.                                 Text(
  402.                                     transactionProduct![index]
  403.                                                 .transactionProductName!
  404.                                                 .length >
  405.                                             25
  406.                                         ? transactionProduct![index]
  407.                                             .transactionProductName!
  408.                                             .substring(0, 25)
  409.                                         : transactionProduct![index]
  410.                                             .transactionProductName!,
  411.                                     style: TextStyle(
  412.                                         fontSize: 14.0,
  413.                                         fontWeight: FontWeight.w500)),
  414.                                 SizedBox(
  415.                                   height: 5.0,
  416.                                 ),
  417.                                 Text(
  418.                                     '${transactionProduct![index].transactionQuantity} x Rp ${rupiah(transactionProduct![index].transactionSinglePrice! ~/ 1)} / ${transactionProduct![index].transactionMeasureUnit}',
  419.                                     style: TextStyle(
  420.                                         fontSize: 12.0,
  421.                                         fontWeight: FontWeight.w500)),
  422.                               ],
  423.                             ),
  424.                             Text(
  425.                                 'Rp ${rupiah(((transactionProduct![index].transactionQuantity! * transactionProduct![index].transactionSinglePrice!).toInt()))}',
  426.                                 style: TextStyle(
  427.                                     fontSize: 16.0,
  428.                                     fontWeight: FontWeight.w500)),
  429.                           ],
  430.                         ));
  431.                   }))),
  432.         ],
  433.       ),
  434.     );
  435.   }
  436.  
  437.   void tesKoneksi() async {
  438.     getPrinter();
  439.     print(addRessPrint);
  440.     kon();
  441.     showCustomDialog(storedata, historyTransaction, chooseMember, context);
  442.   }
  443.  
  444.   void _tesPrint() async {
  445.     //SIZE
  446.     // 0- normal size text
  447.     // 1- only bold text
  448.     // 2- bold with medium text
  449.     // 3- bold with large text
  450.     //ALIGN
  451.     // 0- ESC_ALIGN_LEFT
  452.     // 1- ESC_ALIGN_CENTER
  453.     // 2- ESC_ALIGN_RIGHT
  454.  
  455.     bluetooth.isConnected.then((isConnected) {
  456.       if (isConnected!) {
  457.         if (storedata != null) {
  458.           if (storedata!.storeName != null &&
  459.               storedata!.storeName!.isNotEmpty) {
  460.             bluetooth.printCustom("${storedata!.storeName}", 0, 1);
  461.           }
  462.           if (storedata!.storeAddress != null &&
  463.               storedata!.storeAddress!.isNotEmpty) {
  464.             bluetooth.printCustom("${storedata!.storeAddress}", 0, 1);
  465.           }
  466.           if (storedata!.storePhoneNumber != null &&
  467.               storedata!.storePhoneNumber!.isNotEmpty) {
  468.             bluetooth.printCustom("${storedata!.storePhoneNumber}", 0, 1);
  469.           }
  470.         }
  471.         bluetooth.printCustom("================================", 1, 1);
  472.         if (user != null) {
  473.           String noKasir = historyTransaction!.noteNumber! +
  474.               "/" +
  475.               "/" +
  476.               DateFormat('dd-MM-yy').format(
  477.                   DateTime.parse(historyTransaction!.transactionDate!)) +
  478.               ' ' +
  479.               DateFormat('HH:mm').format(DateTime.now());
  480.           bluetooth.printCustom("$noKasir", 1, 1);
  481.         }
  482.         bluetooth.printCustom("================================", 1, 1);
  483.         transactionProduct!.map((product) {
  484.           qtyBrg = product.transactionQuantity.toString();
  485.           hrgBrg = rupiah(product.transactionSinglePrice?.toInt()) +
  486.               ' / ' +
  487.               product.transactionMeasureUnit!;
  488.           // double subtotal = product.transactionQuantity *
  489.           //     product.transactionSinglePrice.toDouble();
  490.           String subtotal = rupiah(
  491.               ((product.transactionQuantity! * product.transactionSinglePrice!)
  492.                   .toInt()));
  493.           // String subtot = rupiah(subtotal.toInt());
  494.           String? namaProd;
  495.           if (product.transactionProductName!.length > 23) {
  496.             namaProd = product.transactionProductName!.substring(0, 23);
  497.           } else {
  498.             namaProd = product.transactionProductName;
  499.           }
  500.           bluetooth.printCustom("$namaProd", 1, 0);
  501.           bluetooth.printLeftRight("$qtyBrg x $hrgBrg", "$subtotal", 1);
  502.         }).toList();
  503.         bluetooth.printCustom("--------------------------------", 1, 1);
  504.         double grndTot = historyTransaction!.transactionTotalPrice! +
  505.             historyTransaction!.transactionUserDiscount!.toInt();
  506.         String grandTotal = rupiah(grndTot.toInt());
  507.         bluetooth.printLeftRight(
  508.             "   Grand Total",
  509.             "$grandTotal",
  510.             // "${rupiah(historyTransaction.transactionTotalPrice + historyTransaction.transactionUserDiscount.toInt())}",
  511.             1);
  512.         if (historyTransaction!.transactionUserDiscount! > 0) {
  513.           bluetooth.printLeftRight(
  514.               "   DISKON",
  515.               "${rupiah(historyTransaction!.transactionUserDiscount!.toInt())}",
  516.               1);
  517.           double ttlNet = historyTransaction!.transactionTotalPrice!;
  518.           totalNet = rupiah(ttlNet.toInt());
  519.  
  520.           bluetooth.printLeftRight("   TOTAL", "$totalNet", 1);
  521.         }
  522.         int tunai = historyTransaction!.transactionUserPayment!.toInt() * 100;
  523.         String tunaiStr = rupiah(tunai);
  524.         bluetooth.printLeftRight("   TUNAI", "$tunaiStr", 1);
  525.         // "   TUNAI", "${rupiah(historyTransaction.transactionUserPayment.toInt())}", 1);
  526.         bluetooth.printLeftRight(
  527.             "   Kembalian",
  528.             "${rupiah(historyTransaction!.transactionUserReturnChange!.toInt() * 100)}",
  529.             1);
  530.         bluetooth.printCustom("--------------------------------", 1, 1);
  531.         if (chooseMember != null && chooseMember!.memberName != null) {
  532.           String brsMember = chooseMember!.memberNo! +
  533.               " | " +
  534.               chooseMember!.memberName! +
  535.               " | " +
  536.               (historyTransaction!.transactionPointReward.toString());
  537.           bluetooth.printCustom(brsMember, 1, 1);
  538.           bluetooth.printCustom("--------------------------------", 1, 1);
  539.         }
  540.         bluetooth.paperCut();
  541.         _disconnect();
  542.         Navigator.of(context).pop();
  543.       }
  544.     });
  545.   }
  546.  
  547.   void showCustomDialog(
  548.       storedata, historyTransaction, chooseMember, BuildContext context) async {
  549.     var status = await showDialog(
  550.         context: context,
  551.         builder: (context) {
  552.           return AlertDialog(
  553.             content: Text('Cetak Struk ?'),
  554.             actions: <Widget>[
  555.               RaisedButton(
  556.                 child: Text('Batal'),
  557.                 elevation: 5.0,
  558.                 color: Colors.red,
  559.                 onPressed: () {
  560.                   Navigator.of(context).pop();
  561.                 },
  562.               ),
  563.               RaisedButton(
  564.                 child: Text('Cetak'),
  565.                 elevation: 5.0,
  566.                 color: Colors.blue,
  567.                 onPressed: () {
  568.                   _tesPrint();
  569.                 },
  570.               )
  571.             ],
  572.           );
  573.         });
  574.   }
  575.  
  576.   // List<DropdownMenuItem<BluetoothDevice>> _getDeviceItems() {
  577.   //   List<DropdownMenuItem<BluetoothDevice>> items = [];
  578.   //   if (_devices.isEmpty) {
  579.   //     items.add(DropdownMenuItem(
  580.   //       child: Text('NONE'),
  581.   //     ));
  582.   //   } else {
  583.   //     _devices.forEach((device) {
  584.   //       items.add(DropdownMenuItem(
  585.   //         child: Text(device.name),
  586.   //         value: device,
  587.   //       ));
  588.   //     });
  589.   //   }
  590.   //   return items;
  591.   // }
  592.  
  593.   // void _connect() {
  594.   //   if (_device == null) {
  595.   //     show('No device selected.');
  596.   //   } else {
  597.   //     bluetooth.isConnected.then((isConnected) {
  598.   //       if (!isConnected) {
  599.   //         bluetooth.connect(_device).catchError((error) {
  600.   //           setState(() => _pressed = false);
  601.   //         });
  602.   //         setState(() => _pressed = true);
  603.   //       }
  604.   //     });
  605.   //   }
  606.   // }
  607.  
  608.   // void _disconnect() {
  609.   //   bluetooth.disconnect();
  610.   //   setState(() => _pressed = true);
  611.   // }
  612.  
  613.   // Future<void> writeToFile(ByteData data, String path) {
  614.   //   final buffer = data.buffer;
  615.   //   return new File(path).writeAsBytes(buffer.asUint8List(data.offsetInBytes, data.lengthInBytes));
  616.   // }
  617.  
  618.   // Future show(
  619.   //   String message, {
  620.   //   Duration duration: const Duration(seconds: 3),
  621.   // }) async {
  622.   //   await new Future.delayed(new Duration(milliseconds: 100));
  623.   //   _scaffoldKey.currentState.showSnackBar(
  624.   //     new SnackBar(
  625.   //       content: new Text(
  626.   //         message,
  627.   //         style: new TextStyle(
  628.   //           color: Colors.white,
  629.   //         ),
  630.   //       ),
  631.   //       duration: duration,
  632.   //     ),
  633.   //   );
  634.   // }
  635.  
  636.   // Future<void> printScreen() async {
  637.   //   final RenderRepaintBoundary boundary = previewContainer.currentContext.findRenderObject();
  638.   //   final ui.Image im = await boundary.toImage();
  639.   //   final ByteData bytes = await im.toByteData(format: ui.ImageByteFormat.rawRgba);
  640.   //   print('Print Screen ${im.width}x${im.height} ...');
  641.  
  642.   //   Printing.layoutPdf(onLayout: (PdfPageFormat format) {
  643.   //     final pdf.Document document = pdf.Document();
  644.  
  645.   //     final PdfImage image =
  646.   //         PdfImage(document.document, image: bytes.buffer.asUint8List(), width: im.width, height: im.height);
  647.  
  648.   //     document.addPage(pdf.Page(
  649.   //         pageFormat: format,
  650.   //         build: (pdf.Context context) {
  651.   //           return pdf.Center(
  652.   //             child: pdf.Expanded(
  653.   //               child: pdf.Image(image),
  654.   //             ),
  655.   //           ); // Center
  656.   //         })); // Page
  657.  
  658.   //     return document.save();
  659.   //   });
  660.   // }
  661.  
  662.   int getTotal() {
  663.     int total = 0;
  664.     for (int i = 0; i < transactionProduct!.length; i++) {
  665.       total += transactionProduct![i].transactionQuantity!;
  666.     }
  667.     return total;
  668.   }
  669.  
  670.   String parseToDate(String dateTimeFormat) {
  671.     DateTime date = DateTime.parse(dateTimeFormat);
  672.     DateFormat dateFormat = DateFormat("dd MMMM yyyy");
  673.     return dateFormat.format(date);
  674.   }
  675. }
  676.  
  677. class PrintStrukPageArgument {
  678.   final Member? member;
  679.   final List<TransactionProduct>? transactionProduct;
  680.   final TransactionModel? transactionModel;
  681.   // final TransactionModel historyTransaction;
  682.  
  683.   PrintStrukPageArgument({
  684.     this.member,
  685.     this.transactionProduct,
  686.     this.transactionModel,
  687.     // this.historyTransaction,
  688.   });
  689. }
  690.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement