pos_flutter_printer 1.0.8
pos_flutter_printer: ^1.0.8 copied to clipboard
A Flutter plugin to print text, image, QR to POS Bluetooth printers like Shreyans Z91.
// example/lib/main.dart
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:pos_flutter_printer/pos_flutter_printer.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: PrinterExamplePage(),
debugShowCheckedModeBanner: false,
);
}
}
class PrinterExamplePage extends StatefulWidget {
const PrinterExamplePage({super.key});
@override
State<PrinterExamplePage> createState() => _PrinterExamplePageState();
}
class _PrinterExamplePageState extends State<PrinterExamplePage> {
final PosFlutterPrinter _printer = PosFlutterPrinter();
Future<void> _printReceipt() async {
final ByteData logoBytes = await rootBundle.load('assets/logo.png');
final String base64Logo = base64Encode(Uint8List.view(logoBytes.buffer));
final List<Map<String, dynamic>> lines = [
{
"text": "THANK YOU",
"align": "center",
"size": 4,
"bold": true,
"font": "Roboto-Regular.ttf",
"marginTop": 20,
},
{
"text": "Pawan Kumar",
"align": "center",
"size": 3,
"bold": false,
"font": "Roboto-Regular.ttf",
"marginTop": 10,
},
{
"text": "4Brains Technologies Pvt Ltd",
"align": "center",
"size": 2,
"bold": false,
"font": "Roboto-Regular.ttf",
},
{
"text": "T0067, Akshar Business Park\nJanta Market Road, Vashi",
"align": "center",
"size": 1,
"bold": false,
"font": "Roboto-Regular.ttf",
},
{"image": base64Logo, "width": 200, "align": "center", "marginTop": 20},
{
"qr": "https://4brains.in",
"width": 200,
"align": "center",
"marginTop": 20,
},
];
try {
final result = await _printer.printStructuredReceipt(
lines: lines,
topMargin: 40,
bottomMargin: 60,
);
debugPrint("✅ Print Result: $result");
} catch (e) {
debugPrint("❌ Print Failed: $e");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("POS Flutter Printer Example")),
body: Center(
child: ElevatedButton(
onPressed: _printReceipt,
child: const Text("Print Receipt"),
),
),
);
}
}