BluetoothService class
Stateless bridge to the platform Bluetooth printer APIs.
The class exposes plain static members on purpose: the SDK is used from multiple screens and services and does not require an inherited widget or a provider.
Connection lifecycle:
- init can be called once during app startup. It restores the persisted printer, checks whether the platform still holds an open socket (which is what happens after a Flutter hot restart) and, when the socket is gone, starts the automatic reconnect loop.
- While a printer is connected a lightweight watchdog verifies the link, so a printer that is switched off is noticed without a print job.
- A failed print is treated like a dropped link: the service reconnects the saved printer and retries the job once.
- A manual disconnect stops the loop until the user connects again.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
bluetooth
↔ List<
BluetoothInfo> -
getter/setter pair
- bluetoothIsConnected ↔ bool
-
getter/setter pair
- connectedPrinterMac ↔ String
-
getter/setter pair
- connectedPrinterName ↔ String
-
getter/setter pair
-
connectionEvents
→ Stream<
PrinterConnectionEvent> -
Stream of connection-loss / reconnect lifecycle events.
no setter
- connectionLoading ↔ bool
-
getter/setter pair
- currenstMsg ↔ String
-
getter/setter pair
- hasSavedPrinter → bool
-
Whether a printer was connected successfully at least once and persisted.
no setter
- isConnecting → bool
-
no setter
- isDisconnecting → bool
-
no setter
- isPrinting ↔ bool
-
getter/setter pair
- isReconnecting → bool
-
no setter
- isScanning → bool
-
no setter
- isSupported → bool
-
Whether the underlying Bluetooth printer plugin supports this platform.
no setter
- optionprinttype ↔ String
-
Currently selected paper size (
58 mmor80 mm).getter/setter pair - printerStatus ↔ String
-
getter/setter pair
- profile ↔ CapabilityProfile?
-
getter/setter pair
- requiresRuntimePermissions → bool
-
Whether the platform needs runtime Bluetooth permissions before scanning
or connecting.
no setter
- savedPrinterMac → String
-
MAC address persisted by the last successful connection.
no setter
- savedPrinterName → String
-
Display name persisted by the last successful connection.
no setter
-
statusStream
→ Stream<
String> -
Stream of human readable status changes.
no setter
Static Methods
-
connectToBluetoothPrinter(
{required String mac, required String deviceName, dynamic onStatusChanged(bool isConnecting, bool isConnected, String printerStatus)?}) → Future< bool> - Connects to a paired printer and persists it for future auto-reconnects.
-
demoPrintBluetooth(
{required String printerName}) → Future< List< int> > - Builds the bytes for the SDK test receipt.
-
disconnect(
{bool clearSaved = true}) → Future< bool> - Disconnects the active Bluetooth printer.
-
dispose(
) → Future< void> - Releases timers and platform listeners. The service is unusable afterwards until init is called again.
-
ensureConnected(
) → Future< bool> - Verifies the current link and reconnects the saved printer when needed.
-
getBluetoothDevices(
{bool autoConnectSaved = true, dynamic onStatusChanged(bool isConnecting, bool isConnected, String printerStatus)?}) → Future< List< BluetoothInfo> > - Returns the list of paired Bluetooth devices.
-
getCurrentConnectionStatus(
) → Future< bool> - Refreshes bluetoothIsConnected from the platform and returns it.
-
init(
) → Future< void> - Initializes the persisted printer and starts connection monitoring.
-
printBytes(
{required List< int> bytesToPrint, dynamic onStatusChanged(bool isConnecting, bool isConnected, String printerStatus)?}) → Future<bool> - Sends raw ESC/POS bytes to the connected printer.
-
printOrderBytes(
{required dynamic bytesToPrint, dynamic onStatusChanged(bool isConnecting, bool isConnected, String printerStatus)?}) → Future< bool> - Prints a base64 encoded raw ESC/POS payload.
-
reconnectSaved(
) → Future< bool> - Reconnects the persisted printer without user interaction.
-
testWindows(
) → Future< List< int> > - Builds a Windows-specific demo receipt.