pos_flutter_printer 2.0.2
pos_flutter_printer: ^2.0.2 copied to clipboard
A Flutter plugin to print text, image, QR to POS Bluetooth printers like Shreyans Z91.
pos_flutter_printer #
A Flutter plugin to print structured receipts (with text, images, QR codes, font styles, alignment, and margins) on Bluetooth POS printers.
🚀 Features #
- Print styled text with custom font, size, and alignment
- Print base64 images with align and width options
- Print QR codes with alignment and size
- Margin control (top and bottom)
- Supports Android Bluetooth POS printers
- Fully customizable via Flutter JSON-based structure
⚠️ Note: Make sure only one Bluetooth printer is paired with your POS terminal. The plugin automatically connects to the first paired device.
📦 Installation #
Add this plugin in your pubspec.yaml:
dependencies:
pos_flutter_printer: ^1.0.0
🛠 Usage #
1. Import the plugin #
import 'package:pos_flutter_printer/pos_flutter_printer.dart';
2. Use it in your code #
3. Bill Receipt Example #
String formatRow(String item, int qty, double rate) {
final total = (qty * rate).toStringAsFixed(2);
return "${item.padRight(14).substring(0, 14)}"
"${qty.toString().padLeft(4)}"
"${rate.toStringAsFixed(2).padLeft(6)}"
"${total.padLeft(8)}";
}
String generateDivider(String char, {int lineLength = 32}) {
return List.filled(lineLength, char).join();
}
String leftRightAlign(String left, String right, {int totalWidth = 32}) {
const spacer = ' ';
int spaceCount = totalWidth - left.length - right.length;
if (spaceCount < 1) {
final allowedLeft = totalWidth - right.length - 1;
left = left.substring(0, allowedLeft.clamp(0, left.length));
spaceCount = 1;
}
return '$left${spacer * spaceCount}$right';
}
final lines = [
{
"text": "4Brains Technologies",
"align": "center",
"size": 1,
"bold": true,
"font": "RobotoMono-Regular.ttf",
},
{
"text": "T0067, Vashi, MH",
"align": "center",
"size": 1,
"font": "RobotoMono-Regular.ttf",
},
{
"text": generateDivider('-'),
"align": "left",
"font": "RobotoMono-Regular.ttf",
"size": 1,
},
{
"text": "Item".padRight(14) +
"Qty".padLeft(4) +
"Rate".padLeft(6) +
"Total".padLeft(8),
"align": "left",
"size": 1,
"bold": true,
"font": "RobotoMono-Regular.ttf",
},
{
"text": formatRow("Pen", 2, 10.0),
"align": "left",
"size": 1,
"font": "RobotoMono-Regular.ttf",
},
{
"text": formatRow("Notebook", 1, 50.0),
"align": "left",
"size": 1,
"font": "RobotoMono-Regular.ttf",
},
{
"text": generateDivider('-'),
"align": "left",
"font": "RobotoMono-Regular.ttf",
"size": 1,
},
{
"text": leftRightAlign("Total", "₹ 100"),
"bold": false,
"size": 2,
"marginTop": 10,
"align": "left",
"font": "RobotoMono-Regular.ttf",
},
];
final result = await PosFlutterPrinter.print(
lines: lines,
topMargin: 40,
bottomMargin: 60,
);
final lines = [
{
"text": "THANK YOU",
"align": "center",
"size": 4,
"font": "Roboto-Regular.ttf",
"bold": true
},
{
"text": "Pawan Kumar",
"align": "center",
"bold": false,
"size": 3,
"font": "Roboto-Regular.ttf",
},
{
"image": "BASE64_IMAGE_STRING",
"width": 250,
"align": "center"
},
{
"qr": "https://4brains.in",
"width": 200,
"align": "center"
}
];
final result = await PosFlutterPrinter.print(
lines: lines,
topMargin: 30,
bottomMargin: 60,
);
print("Result: \$result");
Fonts #
Place your font file (e.g. Roboto-Regular.ttf) in:
android/src/main/assets/fonts/
Manifest Permissions #
In your plugin's AndroidManifest.xml:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
🧩 Parameters for Each Line #
| Key | Type | Description |
|---|---|---|
| text | String | Text to print |
| size | int | Font size scale (1 to 4) |
| bold | bool | Bold text |
| align | String | "left", "center", or "right" |
| font | String | Font filename in assets/fonts |
| image | String | Base64 image data |
| qr | String | Text/URL for QR code |
| width | int | Image or QR size in pixels |
| marginTop | int | Optional top margin before this line |
📋 License #
MIT License. Created by 4Brains Technologies.