There are two methods to print receipt.
- Using the widget method: The widget method generates an image from the flutter widget and prints generated images. This method is encouraged because it can print in an arbitrary format. For example, column, row, image, text in various languages, divider, underline, struck text, receipt border, QR code, and barcode. If we can render it on a device screen, then it can be printed. But the drawback is the print result on the dot matrix printer is not very good, see the table below. If the print quality for dot matrix printing is required, the developer needs to print using the text command
- Using text command method: Text commands rely on proper code table mapping, so you need to map the code table for the new printer correctly according to esc_pos_utils readme.md. Note: This method is a legacy method and should not be used if at all possible.
For full example usage, See example folder
General procedure is to
- Discover
PosPrinter.discover()
- Connect
PosPrinter.connect()
- Print widget
PosPrinter.widget()
- Cut
PosPrinter.cut()
- Pop drawer
PosPrinter.popDrawer()
- Transmit data to printer
PosPrinter.transmit()
Function Prototype | Return value |
---|---|
PosPrinter.discover({bool onlyKnownProfile = true, PosPrinterInterface interface = PosPrinterInterface.All})
|
Future<List<dynamic>>
|
- Description: List discovered printer
-
Parameters:
-
onlyKnownProfile
: true if you want to only discover printer that supported by the library -
interface
: POS printer inteface to discover
-
Function Prototype | Return value |
---|---|
PosPrinter.connect(dynamic printer,{String? networkPrinterProfile, required GlobalKey globalKey})
|
Future<PosPrinterStatus>
|
- Description: connect to the printer
-
Parameters:
-
printer
: obtained fromPosPrinter.discover()
-
networkPrinterProfile
: required forEscPosNetworkPrinter
, obtained fromPosPrinter.availableProfile
-
globalKey
: use for Widget image capturing. Application developer must pass the sameglobalKey
inReceiptWidget
constructor like thisReceiptWidget(globalKey: globalKey,child: ReceiptData())
-
Function Prototype | Return value |
---|---|
PosPrinter.widget()
|
Future
|
-
Description: print the
ReceiptWidget
that construct with the sameglobalKey
used when connect withPosPrinter.connect()
Function Prototype | Return value |
---|---|
PosPrinter.cut({PosCutMode mode = PosCutMode.full})
|
Future<Void>
|
- Description: cut the paper
-
Parameters:
-
mode
: cut mode. Only have two possibilities, partial cut and full cut
-
Function Prototype | Return value |
---|---|
PosPrinter.popDrawer()
|
void
|
- Description: pop the drawer
Function Prototype | Return value |
---|---|
PosPrinter.transmit()
|
Future<PosPrinterStatus>
|
- Description: transmit generated commands to connected printer
- An unsupported printer can be discovered by
// The library will load the default profile when connecting to an unsupported printer. So it will likely not work.
// Be aware that not only POS Printer will be discovered by this method.
// The return value will include other types of devices for that interface.
PosPrinter.discover(onlyKnownProfile: false)
-
For ESC/POS Network printer
- Unlike other interface, Network interface cannot retrieve information from a printer, so the library cannot automatically load correct a profile. An application developer must prompt user to manually load a profile. See
PosPrinter.connect()
for more details.
- Unlike other interface, Network interface cannot retrieve information from a printer, so the library cannot automatically load correct a profile. An application developer must prompt user to manually load a profile. See
-
For Star Micronics printer
- This library should work gracefully with every Star Micronics printer model on every interface without a profile support, due to portability of StarPrnt SDK
For full list of verified tested printer, see capabilities.json