ezetap_sdk 0.1.4 copy "ezetap_sdk: ^0.1.4" to clipboard
ezetap_sdk: ^0.1.4 copied to clipboard

outdated

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: 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")),
            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;
    });
  }
}
4
likes
0
points
72
downloads

Publisher

unverified uploader

Weekly Downloads

Integrating the SDK will allow you to access Ezetap services in your application

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ezetap_sdk

Packages that implement ezetap_sdk