From c06da8a60c533a72226993e8ad2ff56d51107fa3 Mon Sep 17 00:00:00 2001 From: tzw Date: Mon, 26 Feb 2024 17:26:25 +0630 Subject: [PATCH] add print qr code page --- assets/local/localization_en.json | 2 + assets/local/localization_mu.json | 2 + lib/helpers/pdf.dart | 1 + lib/pages/carton/carton_editor.dart | 2 +- lib/pages/carton/carton_info.dart | 21 +++++-- lib/pages/carton/print_qr_code_page.dart | 64 ++++++++++++++++++++ lib/pages/carton/widget/carton_list_row.dart | 18 +++--- lib/pages/carton/widget/carton_row.dart | 24 ++++++-- pubspec.yaml | 1 + 9 files changed, 112 insertions(+), 23 deletions(-) create mode 100644 lib/pages/carton/print_qr_code_page.dart diff --git a/assets/local/localization_en.json b/assets/local/localization_en.json index ee16197..bd9ad13 100644 --- a/assets/local/localization_en.json +++ b/assets/local/localization_en.json @@ -364,6 +364,8 @@ "box.ship.confirm":"Confirm ship?", "box.arrive.confirm":"Confirm arrive?", "box.invoice.confirm":"Confirm invoice?", + "box.print.qr.title":"Print QRCode", + "box.print.btn":"Print", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/assets/local/localization_mu.json b/assets/local/localization_mu.json index d088e21..22ed1a6 100644 --- a/assets/local/localization_mu.json +++ b/assets/local/localization_mu.json @@ -364,6 +364,8 @@ "box.ship.confirm":"ပို့ဆောင်မှုကို အတည်ပြုပါ ?", "box.arrive.confirm":"ရောက်ရှိကြောင်း အတည်ပြုပါ ?", "box.invoice.confirm":"ပြေစာ အတည်ပြုပါ ?", + "box.print.qr.title":"QRCode ပရင့်ထုတ်ရန်", + "box.print.btn":"ပရင့်ထုတ်မည်", "Boxes End ================================================================":"", "Delivery Start ================================================================":"", diff --git a/lib/helpers/pdf.dart b/lib/helpers/pdf.dart index 20d7159..33ae573 100644 --- a/lib/helpers/pdf.dart +++ b/lib/helpers/pdf.dart @@ -52,6 +52,7 @@ Future generateCartonPdf(Carton carton) async { style: pw.TextStyle( fontSize: 10, )), + pw.SizedBox(height: 3), pw.Text("${carton.actualWeight} lb", style: pw.TextStyle( fontSize: 10, diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index 8a34610..3df8d7f 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -310,7 +310,7 @@ class _CartonEditorState extends State { CupertinoPageRoute(builder: (context) => CartonInfo(carton: c)), ); }, - child: CartonRow(box: c)); + child: CartonRow(carton: c)); }).toList(); } } diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 7ae1d9f..1cd1297 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -22,6 +22,7 @@ import '../widgets/local_button.dart'; import 'carton_package_editor.dart'; import 'mix_carton/mix_carton_editor.dart'; import 'model/carton_model.dart'; +import 'print_qr_code_page.dart'; class CartonInfo extends StatefulWidget { final Carton carton; @@ -100,7 +101,16 @@ class _CartonInfoState extends State { labelTextKey: "box.number", ); - final cartonQrBox = DisplayText(iconData: AntDesign.qrcode); + final cartonQrBox = IconButton( + onPressed: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => PrintQrCodePage(carton: _carton)), + ); + }, + icon: Icon(AntDesign.qrcode, color: Colors.black)); + final cartonSubTypeBox = DisplayText( text: _carton.cartonType == carton_from_packages ? "Carton for packages" @@ -315,8 +325,8 @@ class _CartonInfoState extends State { child: LocalText(context, "box.imageupload.title", color: Colors.white, fontSize: 14)), ); - - final deleteBtn = Padding( + + final deleteBtn = Padding( padding: const EdgeInsets.symmetric(horizontal: 30), child: LocalButton( color: dangerColor, @@ -400,7 +410,7 @@ class _CartonInfoState extends State { const SizedBox(height: 30), img, const SizedBox(height: 40), - deleteBtn, + deleteBtn, const SizedBox(height: 20) ])))); } @@ -446,7 +456,8 @@ class _CartonInfoState extends State { _init(); } } - _delete() { + + _delete() { showConfirmDialog(context, "box.delete.confirm", () { _deleteCarton(); }); diff --git a/lib/pages/carton/print_qr_code_page.dart b/lib/pages/carton/print_qr_code_page.dart new file mode 100644 index 0000000..cdd8d3f --- /dev/null +++ b/lib/pages/carton/print_qr_code_page.dart @@ -0,0 +1,64 @@ +import 'package:fcs/domain/entities/carton.dart'; +import 'package:fcs/helpers/theme.dart'; +import 'package:fcs/pages/widgets/local_app_bar.dart'; +import 'package:fcs/pages/widgets/local_button.dart'; +import 'package:flutter/material.dart'; +import 'package:qr_flutter/qr_flutter.dart'; + +import '../../helpers/pdf.dart'; + +class PrintQrCodePage extends StatelessWidget { + final Carton carton; + const PrintQrCodePage({required this.carton}); + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: LocalAppBar( + labelKey: "box.print.qr.title", + backgroundColor: Colors.white, + labelColor: primaryColor, + arrowColor: primaryColor, + actions: []), + body: ListView( + padding: EdgeInsets.only(left: 15, right: 15), + children: [ + const SizedBox(height: 40), + Row( + children: [ + QrImageView( + data: 'This is a simple QR code', + version: QrVersions.auto, + size: 100, + gapless: true, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(carton.cartonNumber ?? "", + style: TextStyle(fontSize: 18,fontFamily: "Roboto")), + Text(carton.userName!, style: TextStyle(fontSize: 16,fontFamily: "Roboto")), + Padding( + padding: const EdgeInsets.only(top: 3), + child: Text("${carton.actualWeight} lb", + style: TextStyle(fontSize: 16, color: labelColor,fontFamily: "Roboto")), + ) + ], + ) + ], + ), + const SizedBox(height: 30), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 40), + child: LocalButton( + textKey: "box.print.btn", + color: primaryColor, + iconData: Icons.print_outlined, + callBack: () { + generateCartonPdf(carton); + }, + ), + ) + ], + )); + } +} diff --git a/lib/pages/carton/widget/carton_list_row.dart b/lib/pages/carton/widget/carton_list_row.dart index f69ce2f..6a4641d 100644 --- a/lib/pages/carton/widget/carton_list_row.dart +++ b/lib/pages/carton/widget/carton_list_row.dart @@ -1,13 +1,11 @@ import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/helpers/theme.dart'; -import 'package:fcs/pages/carton/model/carton_model.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; -import 'package:provider/provider.dart'; -import '../../../helpers/pdf.dart'; import '../carton_info.dart'; +import '../print_qr_code_page.dart'; class CartonListRow extends StatelessWidget { final Carton box; @@ -68,7 +66,12 @@ class CartonListRow extends StatelessWidget { const SizedBox(width: 15), IconButton( onPressed: () { - _pdf(box, context); + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + PrintQrCodePage(carton: box)), + ); }, icon: Icon(AntDesign.qrcode, color: Colors.black)) @@ -107,11 +110,4 @@ class CartonListRow extends StatelessWidget { ), ); } - - _pdf(Carton carton, BuildContext context) async { - Carton? c = await context.read().getCarton(carton.id!); - if (c == null) return; - - generateCartonPdf(c); - } } diff --git a/lib/pages/carton/widget/carton_row.dart b/lib/pages/carton/widget/carton_row.dart index 1d4bc69..f858088 100644 --- a/lib/pages/carton/widget/carton_row.dart +++ b/lib/pages/carton/widget/carton_row.dart @@ -1,11 +1,14 @@ import 'package:fcs/domain/entities/carton.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; +import '../print_qr_code_page.dart'; + class CartonRow extends StatelessWidget { - final Carton box; - CartonRow({Key? key, required this.box}) : super(key: key); + final Carton carton; + CartonRow({Key? key, required this.carton}) : super(key: key); final double dotSize = 15.0; final DateFormat dateFormat = new DateFormat("dd MMM yyyy"); @@ -23,25 +26,34 @@ class CartonRow extends StatelessWidget { padding: const EdgeInsets.symmetric(vertical: 5.0), child: new Row( children: [ - new Text(box.cartonNumber ?? "", + new Text(carton.cartonNumber ?? "", style: new TextStyle(fontSize: 15.0, color: Colors.black)), const SizedBox(width: 15), - IconButton(onPressed: () {}, icon: Icon(AntDesign.qrcode)), + IconButton( + onPressed: () { + Navigator.push( + context, + CupertinoPageRoute( + builder: (context) => + PrintQrCodePage(carton: carton)), + ); + }, + icon: Icon(AntDesign.qrcode)), ], ), ), ), Column( children: [ - box.cartonWeight == 0 + carton.cartonWeight == 0 ? Container() : Padding( padding: const EdgeInsets.only(left: 8.0, bottom: 5), child: Row( children: [ new Text( - "${box.cartonWeight.toStringAsFixed(2)} lb", + "${carton.cartonWeight.toStringAsFixed(2)} lb", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), diff --git a/pubspec.yaml b/pubspec.yaml index c53d646..9dcf6c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -56,6 +56,7 @@ dependencies: flutter_vector_icons: ^2.0.0 open_file: ^3.3.2 pdf: ^3.10.8 + qr_flutter: ^4.1.0 dev_dependencies: flutter_test: