ezetap_sdk 0.1.9
ezetap_sdk: ^0.1.9 copied to clipboard
Integrating the SDK will allow you to access Ezetap services in your application
example/lib/main.dart
import 'dart:async';
import 'dart:convert';
import 'package:eze_sdk_flutter_example/bill_widget.dart';
import 'package:ezetap_sdk/ezetap_sdk.dart';
import 'package:flutter/material.dart';
import 'package:screenshot/screenshot.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _result = 'Unknown';
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initSdk() async {
var json = {};
String? result = await EzetapSdk.initialize(jsonEncode(json));
if (!mounted) return;
setState(() {
_result = result;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Ezetap Sample'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(onPressed: initSdk, child: const Text("SDK Init")),
ElevatedButton(
onPressed: onPreparePressed,
child: const Text("Prepare Device")),
ElevatedButton(
onPressed: onPressed, child: const Text("Print Bitmap")),
ElevatedButton(
onPressed: onBarcodePressed, child: const Text("Scan Barcode")),
ElevatedButton(
onPressed: checkPrinterStatus, child: const Text("Printer Status")),
ElevatedButton(
onPressed: printTextReceipt, child: const Text("Print Text Receipt")),
Expanded(
flex: 1,
child: SingleChildScrollView(
scrollDirection: Axis.vertical, child: Text(_result)),
),
],
),
),
),
);
}
Future<void> onBarcodePressed() async {
String? result = await EzetapSdk.scanBarcode();
if (!mounted) return;
setState(() {
_result = result;
});
}
Future<void> onPressed() async {
final controller = ScreenshotController();
///@author TIJO THOMAS
///BillWidget is a dummy receipt widget to create base64
final bytes =
await controller.captureFromWidget(const BillWidget(), pixelRatio: 2.0);
var base64Image = base64Encode(bytes);
await EzetapSdk.printBitmap(base64Image);
}
Future<void> onPreparePressed() async {
String? result = await EzetapSdk.prepareDevice();
if (!mounted) return;
setState(() {
_result = result;
});
}
Future<void> checkPrinterStatus() async {
String? result = await EzetapSdk.checkPrinterStatus();
if (!mounted) return;
setState(() {
_result = result;
});
}
Future<void> printTextReceipt() async {
var txtReceipt = "-----------------------------------\n" +
" Receipt\n" +
"-----------------------------------\n" +
"\n" +
"Date: January 9, 2024\n" +
"Time: 12:30 PM\n" +
"\n" +
"-----------------------------------\n" +
"\n" +
"Items Purchased:\n" +
"1. Item Name 10.00\n" +
"2. Another Item 15.50\n" +
"3. Yet Another Item 8.75\n" +
"\n" +
"-----------------------------------\n" +
"\n" +
"Subtotal: 34.25\n" +
"Tax (8%): 2.74\n" +
"Total Amount: 36.99\n" +
"\n" +
"-----------------------------------\n" +
"\n" +
"Payment Method: Credit Card\n" +
"\n" +
"Card Number: **** **** **** 1234\n" +
"Expiry Date: 12/25\n" +
"Authorization Code: 56789\n" +
"\n" +
"-----------------------------------\n" +
"\n" +
"Thank you for your purchase!\n" +
"Please come again.\n" +
"\n" +
"-----------------------------------";
String? result = await EzetapSdk.printTextReceipt(txtReceipt);
if (!mounted) return;
setState(() {
_result = result;
});
}
}