# Flutter Receipt Printing: Connect Your App to a POS Printer

> Build Flutter receipt printing for Android and iOS with a secure backend and cloud API. Learn printer setup, ESC/POS formatting, and safe retry handling.

Published 2026-11-24 · https://printscaler.com/blog/flutter-receipt-printing-pos-printer

![Tablet checkout app connected through a cloud service to a thermal receipt printer and small local computer](https://printscaler.com/blog/images/flutter-receipt-printing-pos-printer-30.jpg)

You can implement Flutter receipt printing by sending an authenticated request from your app to your backend, then having the backend submit an ESC/POS print job to a cloud printing API. The receipt reaches a supported printer through a local agent or, for supported Epson models, a direct connection without a computer. This approach is useful for fixed checkout counters and shared printers; a Bluetooth plugin may be a better fit for a handheld printer that travels with the cashier.

## Choose the right Flutter receipt printing architecture

Before selecting a package, decide how the phone or tablet will reach the printer. A printer having Bluetooth, Wi-Fi, or USB does not automatically mean every Flutter plugin can use it.

There are three common approaches:

| Approach | Best fit | Main consideration |
|---|---|---|
| Flutter plugin or manufacturer SDK | A mobile device printing directly to a nearby printer | Confirm printer model, operating system, transport, and permission support |
| Backend plus local printing agent | Fixed checkout stations and printers shared across devices | Requires a computer or Raspberry Pi running the agent |
| Backend plus supported direct-connect Epson printer | Tablet POS setups without a counter computer | Requires a model with Epson Server Direct Print support |

Direct printing can be appropriate when the app must operate without an internet connection. It also puts printer discovery, connection management, and platform-specific behavior inside your mobile application.

An API-based design moves those responsibilities out of Flutter. Your app requests a business action—print the receipt for a particular sale—and your server controls the document, destination, and retry policy.

The workflow in this tutorial is:

```text
Flutter app
    -> authenticated application backend
    -> PrintScaler HTTPS API
    -> local agent or supported direct-connect printer
    -> physical receipt
```

This does not make an ordinary USB printer independently internet-connected. Something still needs to receive the job at the printer location: the agent or supported printer firmware.

## What you need before writing code

Prepare the following:

- A Flutter app with an authenticated user session.
- A backend that can verify the user and load completed sales.
- An ESC/POS-compatible receipt printer for RAW output.
- A computer running Windows, macOS, Linux, or Raspberry Pi OS for the agent-based setup.
- A PrintScaler API key stored on the backend.

Confirm the exact printer model and its supported command language. Thermal printers do not all accept the same RAW commands. A label printer that expects ZPL is not interchangeable with an ESC/POS receipt printer.

Also confirm the paper width. An 80 mm printer and a 58 mm printer need different receipt layouts, and usable character width depends on the selected font and device settings.

For this example, the backend creates a short, plain-text ESC/POS receipt. Production receipts may also need taxes, discounts, payment details, legally required identifiers, or other information determined by your business and jurisdiction.

## Step 1: Connect the receipt printer to PrintScaler

### Option A: Use the local agent

Install the printer and verify that it works locally before debugging the application. A cloud API cannot correct an incompatible driver, disconnected USB cable, or empty paper roll.

Then:

1. [Download the PrintScaler agent](https://printscaler.com/download) for the computer connected to the printer.
2. Install it and enter the dashboard pairing code to link the computer.
3. Confirm that the printer appears in the dashboard.
4. Use the dashboard test-page button to check the connection.
5. Record the printer ID for your backend configuration.

The agent runs in the background, starts after reboots, and connects through an outbound WebSocket. You do not need to open an inbound firewall port for this setup.

A successful test page establishes that the printing path works. It does not prove your ESC/POS commands are correct, so follow it with a small RAW receipt test.

### Option B: Use a supported Epson printer without a computer

Certain Epson receipt printers support Server Direct Print and can connect to PrintScaler directly. Supported families include the TM-m30III, selected TM-m30II variants, TM-m50/II, TM-T88VI/VII, and TM-i series.

Check the exact model rather than assuming every Epson network printer supports this connection method. Follow the [Epson setup documentation](https://printscaler.com/docs#epson) for the direct-connect path.

For either option, keep the printer mapping on your server. A cashier's Flutter app should not be able to submit an arbitrary printer ID and redirect receipts to another store.

## Step 2: Define a small, secure app-to-backend contract

Your Flutter app should send the order identifier, not the PrintScaler API key or a complete trusted receipt payload.

For example, define an endpoint in your own application:

```http
POST /api/orders/order_8421/receipt
Authorization: Bearer <your-application-session-token>
```

This is an endpoint you implement, not a PrintScaler endpoint.

When your backend receives the request, it should:

1. Authenticate the user.
2. Verify that the user can access the order and its store.
3. Check that the order is eligible for a receipt.
4. Select the store's configured printer.
5. Create or retrieve a persistent print intent.
6. Build the receipt from server-side order data.
7. Submit the print job.

A print intent is your application's record of one intended receipt output. Store its identifier, order ID, destination printer, submission status, and associated PrintScaler response.

This extra record is important. If a user taps twice or a mobile request times out, your backend needs to recognize the original action rather than inventing another print request.

Never embed a PrintScaler API key in a Dart constant, a bundled configuration file, or an application build. A mobile app is not a secret store for credentials that authorize your backend printing service.

## Step 3: Trigger receipt printing from Flutter

Add the HTTP client dependency from your Flutter project directory:

```bash
flutter pub add http
```

The following client calls your own backend. It assumes your login flow has already obtained a valid application session token.

```dart
import 'dart:convert';
import 'package:http/http.dart' as http;

Future<String> requestReceipt({
  required Uri backendOrigin,
  required String orderId,
  required String sessionToken,
}) async {
  final path = '/api/orders/'
      '${Uri.encodeComponent(orderId)}/receipt';

  final response = await http.post(
    backendOrigin.resolve(path),
    headers: {
      'Authorization': 'Bearer $sessionToken',
      'Accept': 'application/json',
    },
  ).timeout(const Duration(seconds: 20));

  if (response.statusCode != 202) {
    throw Exception('Receipt request was not accepted.');
  }

  final body = jsonDecode(response.body)
      as Map<String, dynamic>;
  return body['printIntentId'] as String;
}
```

The `202` response and `printIntentId` field are the contract for your backend, not assumptions about PrintScaler's response format.

Disable the print button while the request is in flight to reduce accidental double taps. However, do not rely on the button alone: users can reopen screens, reconnect after timeouts, or repeat requests from another device.

After acceptance, show something like “Receipt queued” rather than “Receipt printed.” A successful HTTP request does not establish that paper has emerged from the printer.

## Step 4: Submit an ESC/POS receipt from the backend

PrintScaler accepts RAW content through `POST https://api.printscaler.com/v1/printjobs`. For a generated receipt, encode the command bytes as Base64 and use `raw_base64`.

Here is a Node.js backend helper using the built-in `fetch` available in Node.js 20 and later:

```javascript
export async function submitReceipt({
  printerId,
  receiptText,
  printIntentId,
}) {
  const apiKey = process.env.PRINTSCALER_API_KEY;
  if (!apiKey) throw new Error('Missing printing API key');

  // This example deliberately supports printable ASCII only.
  if (/[^\x09\x0A\x0D\x20-\x7E]/.test(receiptText)) {
    throw new Error('Receipt contains unsupported characters');
  }

  const bytes = Buffer.concat([
    Buffer.from([0x1b, 0x40]), // ESC @: initialize
    Buffer.from(receiptText, 'ascii'),
    Buffer.from('\n\n\n', 'ascii'),
  ]);

  const response = await fetch(
    'https://api.printscaler.com/v1/printjobs',
    {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${apiKey}`,
        'Content-Type': 'application/json',
        'X-Idempotency-Key': printIntentId,
      },
      body: JSON.stringify({
        printerId,
        contentType: 'raw_base64',
        content: bytes.toString('base64'),
        title: `Receipt ${printIntentId}`,
      }),
      signal: AbortSignal.timeout(15000),
    }
  );

  if (!response.ok) {
    throw new Error(`Print API returned ${response.status}`);
  }

  return response.text();
}
```

Call this helper only after authentication, authorization, and printer selection. The arguments must come from trusted backend records, not directly from a client request body.

For an initial test, use a small receipt:

```javascript
const receiptText = [
  'COUNTER RECEIPT',
  'Order: 8421',
  '----------------------------',
  'Coffee                 3.50',
  'Sandwich               8.00',
  '----------------------------',
  'TOTAL USD             11.50',
  '',
  'Thank you!',
].join('\n');
```

Persist the print intent before submission. Reuse its identifier and original payload when retrying an uncertain submission; do not generate a new identifier in the retry loop.

The helper returns the API response body so your backend can parse and store it according to the documented response schema. Do not send raw infrastructure errors or credentials back to the Flutter client.

## Format receipts for the actual printer

ESC/POS is a command family, not a guarantee that every printer implements every feature identically. Start with initialization, plain text, and line feeds before adding logos, QR codes, cutting, or cash-drawer commands.

### Match line width to the printer

Do not assume a universal character count for 58 mm or 80 mm rolls. Print a test line in your selected font, determine the usable width, and format item names and amounts accordingly.

Wrap long product names rather than letting them push prices onto unpredictable lines. Calculate currency totals on the backend using an appropriate money representation; receipt formatting should display totals, not independently recalculate the sale.

### Handle character encoding deliberately

The example rejects non-ASCII text. That is intentional: encoding a receipt as UTF-8 does not automatically make an ESC/POS printer render accented characters, Arabic, Chinese, or emoji correctly.

For international receipts, verify the printer's code pages and language support. If text encoding becomes impractical, consider a PDF workflow with the correct paper dimensions, while testing the resulting speed and output quality.

### Add printer-specific commands cautiously

Automatic cutting requires a compatible cutter and command. Cash-drawer pulses require the correct hardware connection and settings. Leave these commands out of the initial smoke test, then add them against the printer's command reference.

PrintScaler supports RAW ESC/POS receipt output, including cutting and cash-drawer commands. See the [receipt printing documentation](https://printscaler.com/docs#receipts) for the service-side workflow, or the related [Node.js ESC/POS guide](https://printscaler.com/blog/nodejs-escpos-printing-local-printers) for more backend-focused implementation guidance.

## Handle offline printers, retries, and reprints separately

These situations look similar in a mobile interface but need different behavior.

### The API request times out

Your server may not know whether PrintScaler accepted the request. Retry the same stored print intent with the same `X-Idempotency-Key`, rather than creating another intent.

Keep the receipt content and destination unchanged for that retry. Idempotency protects repeated API submissions; it is not a substitute for recording business actions in your own database.

### The agent computer is offline

PrintScaler queues jobs while the computer is offline and sends them when it reconnects, subject to configurable expiration. Choose an expiration policy appropriate to the workflow: a receipt arriving hours later may be more confusing than useful.

The Flutter device also needs connectivity to reach your backend. An offline printer queue does not give the mobile app an offline connection to a cloud service.

### The cashier explicitly requests another copy

Treat an intentional reprint as a new action with a new print intent and idempotency key. Record who requested it and why, and consider labeling the receipt as a copy.

For a deeper retry design, see [how to prevent duplicate print jobs](https://printscaler.com/blog/prevent-duplicate-print-jobs).

## Track progress without promising physical delivery

PrintScaler exposes job states including `new`, `sent_to_client`, `queued`, `in_progress`, `done`, `error`, `cancelled`, and `expired`. Your backend can use job history and signed `printjob.state` webhooks to update its records and expose progress to Flutter.

Keep the distinction between service state and physical confirmation clear. Do not treat `done` as universal sensor-level proof that a readable receipt reached the customer's hand; visibility depends on the printer and printing path.

A practical app can show “Submitting,” “Queued,” “Processing,” and an error or completion state, with an explicit reprint action. Support staff should be able to correlate the order, print intent, printer, and service job when investigating a missing receipt.

## Test the whole checkout workflow before rollout

Test more than a successful first receipt:

- A double tap and a repeated request from another device.
- An API timeout after submission.
- A disconnected agent computer and subsequent reconnection.
- A printer with no paper.
- Long item names and non-ASCII customer data.
- An authorized cashier attempting to print another store's order.
- An intentional reprint after the original completes.

For agent-based deployments, start with one counter before expanding. PrintScaler pricing is per print request rather than per page; the Free plan includes 100 prints per month and one computer. Check the [current plans](https://printscaler.com/pricing) against your expected receipt and reprint volume.

## Build printing around the sale, not the mobile device

Reliable Flutter receipt printing starts with a clear separation: the app requests the receipt, your backend authorizes and records the action, and the printing service delivers it to the configured printer. That keeps API credentials out of the mobile app and gives you a consistent place to handle routing, retries, and support.

[Create a free PrintScaler account](https://printscaler.com/signup), connect one test printer, and validate a short receipt before adding the workflow to your checkout screen.

## Frequently asked questions

### Can Flutter print to a thermal receipt printer?

Yes. Flutter apps can use a compatible printer plugin or manufacturer SDK, or send an authenticated request to a backend that submits a cloud print job. Choose based on the printer model, connection method, operating systems, and offline requirements.

### Can I print receipts from Flutter on both Android and iOS?

A backend-based printing workflow can serve both Android and iOS apps because the mobile app communicates with your server over HTTPS. The printer connection is handled separately by a local agent or supported direct-connect printer.

### Should I put my printing API key in the Flutter app?

No. Keep the PrintScaler API key on your backend and authenticate Flutter requests using your application's session mechanism. The backend should authorize the order and select the printer before submitting a job.

### Do I need a computer for Flutter receipt printing with PrintScaler?

For the agent-based approach, you need a Windows, macOS, Linux, or Raspberry Pi device at the printer location. Supported Epson printers with Server Direct Print can connect directly to PrintScaler without a computer.

### Will cloud receipt printing work when the Flutter device is offline?

The Flutter device needs connectivity to send a new request to your backend. Separately, PrintScaler can queue an accepted job while an agent computer is offline, subject to job expiration. If printing must work without internet access, evaluate a direct local printer integration.

### How do I prevent duplicate receipts when a request times out?

Create a persistent print intent on your backend and reuse its X-Idempotency-Key when retrying the same submission. Keep the destination and receipt content unchanged. An intentional reprint should create a separate print intent and key.
