Skip to content

Instantly share code, notes, and snippets.

@anoochit
Created December 27, 2022 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anoochit/43fd5579173ce3951390a394c584e14b to your computer and use it in GitHub Desktop.
Save anoochit/43fd5579173ce3951390a394c584e14b to your computer and use it in GitHub Desktop.
thermal printer
// print test ticket
void printTicket() {
// make a screenshot with data
screenshotController
.captureFromWidget(
SizedBox(
width: 140,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: 140 * 0.5,
child: Image.asset("assets/flutter.png"),
),
const Text(
"ราเมน นางแบบออดิทอเรียมอพาร์ทเมนท์อัลบัมแล็บ ติว ไฮบริด ภคันทลาพาธสตาร์ทศึกษาศาสตร์ซัพพลาย",
maxLines: 5,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
const Text(
"ລາເມງໂມບາຍນາງແບບອໍດິທອລ ມໍ ພັດທະເມັນ ອັລບັ້ມແລັບຕິວ ໄຮບຼິດ ພັດຄັນທະລາພັດສະຕາດ ສຶກສາສາດສະພັດໄລ",
maxLines: 5,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
const Text(
"រ៉ាមេន មនុស្សយន្ត សាលប្រជុំ ផ្ទះល្វែ អាល់ប៊ុម មន្ទីរពិសោធន៍ ការបង្រៀន កូនកាត់ ផាកនថាឡា ផ្លូវ ចាប់ផ្តើម សិក្សា វិទ្យាសាស្ត្រ ការផ្គត់ផ្គង់",
maxLines: 5,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
const Text(
"نموذج رامين قاعة احتفالات ألبوم شقة مدرس معمل مسار هجين بدء تعليم علوم الإمداد",
maxLines: 5,
textAlign: TextAlign.right,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
const SizedBox(height: 16.0),
SizedBox(
width: 140 * 0.5,
child: BarcodeWidget(
barcode: barcodeWidget.Barcode.qrCode(),
data: 'Hello Flutter I Love You!',
),
)
],
),
),
delay: const Duration(milliseconds: 20))
.then(
(capturedImage) async {
// print screenshot data
List<int> bytes = [];
// Using default profile
final profile = await CapabilityProfile.load();
final generator = Generator(PaperSize.mm58, profile);
bytes += generator.reset();
// Handle captured image
final imageLib.Image? image = imageLib.decodeImage(capturedImage);
bytes += generator.image(image!);
bytes += generator.feed(1);
//bytes += generator.cut();
await PrintBluetoothThermal.writeBytes(bytes);
},
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment