dopos_print 0.1.7
dopos_print: ^0.1.7 copied to clipboard
***** EASY TO USE ***** The dopos_print plugin is a Flutter plugin designed to interface with thermal printers on Windows and Android OR Ethernet Printers. This plugin enables Flutter applications to [...]
example/lib/main.dart
import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:dopos_print/dopos_print.dart';
import 'package:permission_handler/permission_handler.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Request Bluetooth permissions
await _requestBluetoothPermission();
runApp(const MyApp());
}
Future<void> _requestBluetoothPermission() async {
if (Platform.isAndroid) {
await _requestBluetoothPermissions();
await _requestLocationPermission();
}
}
Future<void> _requestBluetoothPermissions() async {
PermissionStatus bluetoothScanPermission =
await Permission.bluetoothScan.request();
PermissionStatus bluetoothConnectPermission =
await Permission.bluetoothConnect.request();
if (bluetoothScanPermission.isGranted &&
bluetoothConnectPermission.isGranted) {
print("Bluetooth permissions granted");
} else {
print("Bluetooth permissions denied");
if (bluetoothScanPermission.isPermanentlyDenied ||
bluetoothConnectPermission.isPermanentlyDenied) {
openAppSettings();
}
}
}
Future<void> _requestLocationPermission() async {
PermissionStatus locationPermission =
await Permission.locationWhenInUse.request();
if (locationPermission.isGranted) {
print("Location permission granted");
} else if (locationPermission.isDenied) {
print("Location permission denied");
} else if (locationPermission.isPermanentlyDenied) {
openAppSettings();
}
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final DoposPrint _doposPrintPlugin = DoposPrint();
List<DoposDevice> _printers = [];
String _jsonInput = '';
DoposDevice? _selectedPrinter;
late Map<String, dynamic> _SAMPLE_JSON_INSTRUCTION_58MM,
_SAMPLE_JSON_INSTRUCTION_80MM;
TextEditingController _jsonD = TextEditingController();
// New variables for LAN printing option
TextEditingController _ipController = TextEditingController();
TextEditingController _portController = TextEditingController();
String _printerType = 'Bluetooth'; // To track which radio option is selected
@override
void initState() {
super.initState();
_checkPermissions();
}
Future<void> _checkPermissions() async {
if (await Permission.bluetoothConnect.request().isGranted) {
await _preparePrintInstructions();
_jsonD.text = jsonEncode(_SAMPLE_JSON_INSTRUCTION_80MM).toString();
_loadPrinters();
} else {
// Handle permission denial gracefully
print('Bluetooth/Storage permission denied!');
}
}
Future<void> _preparePrintInstructions() async {
final image =
await _loadImagePathFromAssets('assets/images/image-logo.png');
_SAMPLE_JSON_INSTRUCTION_80MM = {
"printerWidth": 576,
"charLimit": 48,
"startX": 0,
"startY": 0,
"data": [
{
"startX": 0,
"endX": 100,
"lineSpacing": 0,
"imagePath": image,
"imageWidth": 100,
"imageHeight": 120,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"lineSpacing": 0,
"barcode39": "32686327632",
"imageWidth": 400,
"imageHeight": 150,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"lineSpacing": 0,
"qrcode":
"upi://pay?pa=9475635421@hdfcbank&pn=Sk Abdul Nasim&am=100&tn=Hello&cu=INR",
"qrcodeMatrix":
"{{0,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0},{0,1,1,1,1,1,0,1,0,0,1,0,0,0,1,0,0,1,1,0,0,1,0,1,0,1,0,1,1,1,1,1,0},{0,1,0,0,0,1,0,1,1,0,0,0,1,1,0,0,1,1,1,0,1,1,1,0,1,1,0,1,0,0,0,1,0},{0,1,0,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0},{0,1,0,0,0,1,0,1,1,1,0,1,0,0,0,0,1,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0},{0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0},{0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,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,0,1,1,0,0,0},{0,1,0,0,1,0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,1},{0,1,1,1,1,0,1,1,1,0,1,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,1,0,0,0,1},{0,1,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,1,0,1},{1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,0,1,0,0,0,1,0,0,1,0,1,1,1,0,1,1,0,0},{0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,1,0,1,1,1,1,0,1,0,1,0,0,0,0,1},{0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,1,1,0,1,1,1,0,1,0,0,1},{0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,1,0,0},{0,1,0,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1},{0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,0,1,1,1,1,0,1,1,1},{0,1,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,1,1},{0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,0,0,0,0,1,1,1,0,1,0,1,0,1},}",
"imageWidth": 200,
"imageHeight": 200,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "ABDULLAH'S STORE",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "DANGAPARA, SULTANPUR, BURDWAN",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Phone: 8765346533",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "GSTIN: ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "TAX INVOICE",
"fontSize": 2,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 50,
"text": "Date: 27/09/24",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 50,
"endX": 100,
"text": "Time: 22:12:03",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Bill No.: D9S1O0083",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 1,
"endX": 40,
"text": "ITEM NAME",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 55,
"text": "MRP",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 55,
"endX": 70,
"text": "RATE",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 70,
"endX": 85,
"text": "QTY",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 85,
"endX": 100,
"text": "TOTAL",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 1,
"endX": 40,
"text": "1.ABDULLAH BEST ITEM .",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 55,
"text": "160.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 55,
"endX": 70,
"text": "150.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 70,
"endX": 85,
"text": "1.000",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 85,
"endX": 100,
"text": "150.00",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 1,
"endX": 40,
"text": "2.DERMI COOL POWDER 150G.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 55,
"text": "145.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 55,
"endX": 70,
"text": "122.88",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 70,
"endX": 85,
"text": "1.000",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 85,
"endX": 100,
"text": "145.00",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 40,
"text": "Total",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 100,
"text": "295.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 40,
"text": "Tax Amt.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 100,
"text": "22.12",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 40,
"text": "Round off",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 100,
"text": "0.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Net Payable: 295",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "ITEM(S)/QTY: 2/2.000",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "TOTAL INCL. OF ALL GST TAX.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "************************************************",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 1,
"endX": 20,
"text": "TAX%",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 20,
"endX": 40,
"text": "TAXABLE",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 40,
"endX": 60,
"text": "CGST",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 60,
"endX": 78,
"text": "SGST",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 78,
"endX": 98,
"text": "AMT",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 1,
"endX": 20,
"text": "0.0%",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 20,
"endX": 40,
"text": "150.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 40,
"endX": 60,
"text": "0.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 60,
"endX": 78,
"text": "0.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 78,
"endX": 98,
"text": "0.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 1,
"endX": 20,
"text": "18.0%",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 20,
"endX": 40,
"text": "122.88",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 40,
"endX": 60,
"text": "11.06",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 60,
"endX": 78,
"text": "11.06",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 78,
"endX": 98,
"text": "22.12",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "************************************************",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "YOU SAVED: 10.00",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "********************************",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 60,
"text": "Payment Mode:",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 60,
"endX": 100,
"text": "CASH",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 60,
"text": "CASH:",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 60,
"endX": 100,
"text": "295.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Thank You, Visit again!!!",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
}
]
};
_SAMPLE_JSON_INSTRUCTION_58MM = {
"printerWidth": 384,
"charLimit": 32,
"startX": 0,
"startY": 0,
"data": [
{
"startX": 0,
"endX": 100,
"lineSpacing": 0,
"imagePath": image,
"imageWidth": 100,
"imageHeight": 120,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"lineSpacing": 0,
"barcode39": "32686329632",
"imageWidth": 380,
"imageHeight": 150,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"lineSpacing": 0,
"qrcode":
"upi://pay?pa=9475635421@hdfcbank&pn=Sk Abdul Nasim&am=100&tn=Hello&cu=INR",
"qrcodeMatrix":
"{{0,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0},{0,1,1,1,1,1,0,1,0,0,1,0,0,0,1,0,0,1,1,0,0,1,0,1,0,1,0,1,1,1,1,1,0},{0,1,0,0,0,1,0,1,1,0,0,0,1,1,0,0,1,1,1,0,1,1,1,0,1,1,0,1,0,0,0,1,0},{0,1,0,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0},{0,1,0,0,0,1,0,1,1,1,0,1,0,0,0,0,1,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1,0},{0,1,1,1,1,1,0,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,0},{0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0},{1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1},{0,0,0,0,0,1,0,0,0,0,0,1,0,1,1,0,0,1,0,0,1,1,1,1,1,0,1,0,1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,0,0,0,1,1,0,1,0,1,0,1,1,1,1,0,0,0,0,1,0,0,0,0,0,0,1,0,1},{1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,0,1,0,0,0,1,0,0,1,0,1,1,1,0,1,1,0,0},{0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,1,0,1,1,1,1,0,1,0,1,0,0,0,0,1},{0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,1,1,0,1,1,1,0,1,0,0,1},{0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,1,0,0},{0,1,0,0,0,1,0,1,0,1,1,1,0,1,0,0,1,0,0,1,1,0,1,1,0,0,1,0,0,0,1,1,1},{0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,0,1,1,1,1,0,1,1,1},{0,1,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,1,1},{0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,0,0,0,0,1,1,1,0,1,0,1,0,1},}",
"imageWidth": 200,
"imageHeight": 200,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "DANGAPARA, SULTANPUR, BURDWAN",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Phone: 8765346533",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "GSTIN: ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "TAX INVOICE",
"fontSize": 2,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 50,
"text": "Date: 15/08/24",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 50,
"endX": 100,
"text": "Time: 09:58:09",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Bill No.: D9S1O0004",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 15,
"text": "Sl.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 15,
"endX": 68,
"text": "ITEM",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 71,
"endX": 100,
"text": "MRP",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 25,
"text": "RATE",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 25,
"endX": 50,
"text": "QTY",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 50,
"endX": 75,
"text": "TAX%",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 75,
"endX": 100,
"text": "TOTAL",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 15,
"text": "1.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 15,
"endX": 68,
"text": "RACIRAFT SYRUP 250ML.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 70,
"endX": 100,
"text": "215.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 25,
"text": "182.20",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 25,
"endX": 50,
"text": "1.000",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 50,
"endX": 75,
"text": "18.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 75,
"endX": 100,
"text": "215.00",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 40,
"text": "Total",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 100,
"text": "215.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 40,
"text": "Tax Amt.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 100,
"text": "32.80",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 40,
"text": "Round off",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 40,
"endX": 100,
"text": "0.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Net Payable: 215",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": " ",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "ITEM(S)/QTY: 1/1.000",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "TOTAL INCL. OF ALL GST TAX.",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "********************************",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 50,
"text": "TAX%",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 50,
"endX": 100,
"text": "TAXABLE",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 33,
"text": "CGST",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 33,
"endX": 63,
"text": "SGST",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 65,
"endX": 100,
"text": "TAX AMT",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 50,
"text": "18.0%",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 50,
"endX": 100,
"text": "182.20",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 33,
"text": "16.40",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 33,
"endX": 64,
"text": "16.40",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": false
},
{
"startX": 65,
"endX": 100,
"text": "32.80",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "********************************",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "YOU SAVED: 0.00",
"fontSize": 2,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "********************************",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 60,
"text": "Payment Mode:",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 60,
"endX": 100,
"text": "CASH",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 60,
"text": "CASH:",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "left",
"isNewLine": false
},
{
"startX": 60,
"endX": 100,
"text": "215.00",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "right",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "................................",
"fontSize": 1,
"fontWeight": "Bold",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
},
{
"startX": 0,
"endX": 100,
"text": "Thank You, Visit again!!!",
"fontSize": 1,
"fontWeight": "Normal",
"lineSpacing": 0,
"align": "center",
"isNewLine": true
}
]
};
setState(() {});
}
Future<String> _loadImagePathFromAssets(String assetPath) async {
final byteData = await rootBundle.load(assetPath);
final tempDir = await getTemporaryDirectory();
final file = File('${tempDir.path}/image.png');
await file.writeAsBytes(byteData.buffer.asUint8List(), flush: true);
return file.path;
}
Future<void> _loadPrinters() async {
try {
final printers = await _doposPrintPlugin.listPrinters();
setState(() {
_printers = printers.map((printerMap) {
return DoposDevice(
macId: printerMap['macId'] ?? '',
printerName: printerMap['printerName'] ?? '',
vendorId: printerMap['vendorId'] ?? '',
productId: printerMap['productId'] ?? '',
);
}).toList();
});
} catch (e) {
log('Failed to load printers: $e');
}
}
Future<void> _print() async {
_jsonInput = _jsonD.text;
if (_jsonInput.isEmpty) {
log('Please enter JSON data.');
return;
}
try {
final tempDir = await getTemporaryDirectory();
final tempFile = File('${tempDir.path}/printInstructions.json');
await tempFile.writeAsString(_jsonInput);
if (_printerType == 'BluetoothUsb' && _selectedPrinter != null) {
await _doposPrintPlugin.print(
_selectedPrinter!.macId,
_selectedPrinter!.productId,
_selectedPrinter!.vendorId,
_selectedPrinter!.printerName,
tempFile.path,
);
} else if (_printerType == 'LAN') {
String ip = _ipController.text;
String port = _portController.text;
if (ip.isNotEmpty && port.isNotEmpty) {
await _doposPrintPlugin.ethernetPrint(ip, port, tempFile.path);
} else {
log('Please enter both IP and Port.');
}
}
log('Print command sent successfully.');
} on PlatformException catch (e) {
log('Failed to send print command: ${e.message}');
} catch (e) {
log('Error: $e');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Printer App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Printer App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SizedBox(height: 20),
// Radio buttons to select printer type (Bluetooth or LAN)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Radio<String>(
value: 'BluetoothUsb',
groupValue: _printerType,
onChanged: (String? value) {
setState(() {
_printerType = value!;
});
},
),
const Text('USB/Bluetooth Printer'),
Radio<String>(
value: 'LAN',
groupValue: _printerType,
onChanged: (String? value) {
setState(() {
_printerType = value!;
});
},
),
const Text('LAN Printer'),
],
),
const SizedBox(height: 20),
if (_printerType == 'BluetoothUsb' && _printers.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: DropdownButton<DoposDevice>(
hint: const Text('Select Printer'),
value: _selectedPrinter,
onChanged: (DoposDevice? newValue) {
setState(() {
_selectedPrinter = newValue;
});
// You can access additional details from the selected printer:
final selectedMacId = _selectedPrinter?.macId;
final selectedVendorId = _selectedPrinter?.vendorId;
final selectedProductId = _selectedPrinter?.productId;
log('Selected Mac ID: $selectedMacId');
log('Selected Vendor ID: $selectedVendorId');
log('Selected Product ID: $selectedProductId');
},
items: _printers.map((printer) {
return DropdownMenuItem<DoposDevice>(
value: printer,
child: Row(
children: <Widget>[
const Icon(Icons.print),
const SizedBox(width: 10),
Text(printer.printerName),
],
),
);
}).toList(),
),
),
if (_printerType == 'LAN')
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
TextField(
controller: _ipController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'IP Address',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 10),
TextField(
controller: _portController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Port',
border: OutlineInputBorder(),
),
),
],
),
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextField(
controller: _jsonD,
maxLines: 10,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter JSON Data',
),
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _print,
child: const Text('Print'),
),
],
),
),
),
);
}
}
class DoposDevice {
final String macId;
final String printerName;
final String vendorId;
final String productId;
DoposDevice({
required this.macId,
required this.printerName,
required this.vendorId,
required this.productId,
});
// For display in DropdownButton, we'll use printerName
@override
String toString() => printerName;
}