Flutter ECR Plugin
Purpose
The Flutter ECR Plugin (ecrlib) provides cross‑platform integration for Android and iOS applications. It wraps the native SDKs to expose Dart APIs, enabling developers to build POS apps in Flutter without directly handling native socket communication.
Prerequisites
- Flutter SDK 2.0+
ecrlibpackage added topubspec.yaml- Native Android/iOS SDKs configured in the project
Installation
# pubspec.yaml
dependencies:
ecrlib:
path: ./plugins/ecrlib
TCP/IP Connection Example
import 'package:ecrlib/ecrlib.dart';
final tcp = TcpConnect();
int status = await tcp.connectTCP("192.168.0.102", 8888, "ECR001");
tcp.doTransaction(
reqData: requestString,
txnType: 0, // Purchase
signature: signatureData,
listener: ComEventListener(
onEvent: (event) => print("Event: $event"),
onSuccess: (response) => print("Success: $response"),
onFailure: (error, code) => print("Error: $error"),
),
);
tcp.disconnect();
App‑to‑App Connection Example (Android Only)
final a2a = AppToAppConnect();
int? status = await a2a.connect("ECR001");
a2a.doTransaction(
reqData: requestString,
txnType: 0, // Purchase
signature: signatureData,
listener: ComEventListenerss(
onEvent: (event) => print("Event: $event"),
onSuccess: (response) => print("Success: $response"),
onFailure: (error, code) => print("Error: $error"),
),
);
Transaction Flow
connectTCP() / connect() → Register (17) → Start Session (18) → doTransaction() → ComEventListener
⚠️ Legacy vs Adapter Separation
- Legacy ECR integrations require Register (17) and Start Session (18).
- Adapter/Middleware integrations (Local REST API, Cloud REST API) do not require these steps.
Request and Response Details
When performing a transaction, include:
- Date (
ddMMyyHHmmss) - ECR Reference Number
- Amount (Integer in halalas, e.g.,
100 = SAR 1.00)
Responses return:
- Response Code (Approved/Failed)
- Approval Code
- Receipt Data
Transaction Type Codes
| Code | Transaction Type |
|---|---|
| 0 | Purchase |
| 1 | Purchase with Naqd/Cashback |
| 2 | Refund |
| 3 | Authorization |
| 4 | Purchase Advice (Full) |
| 5 | Purchase Advice (Partial) |
| 6 | Auth Extension |
| 7 | Auth Void |
| 9 | Cash Advance |
| 10 | Reconciliation |
| 11 | Reversal |
| 15 | Bill Payment |
| 17 | Register (Legacy only) |
| 18 | Start Session (Legacy only) |
| 19 | End Session |
| 23 | Duplicate / Previous Txn |
| 24 | Check Status |
| 25 | Health Check |
Updated 10 days ago
