t6_pos_sdk 0.0.1 copy "t6_pos_sdk: ^0.0.1" to clipboard
t6_pos_sdk: ^0.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin for the Topwise T6 POS device SDK.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:t6_pos_sdk/t6_pos_sdk.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _isLoading = false;
  // Function to initialize the printer
  Future<void> initialize() async {
    try {
      await T6PosSdk.initSDK();
      await T6PosSdk.initPrinter();
      print("Initialized Successfully");
    } catch (e) {
      print("Failed to initialize: $e");
    }
  }


  String _trackData = "No data read yet";

  Future<void> _startMagstripeSwipe() async {
    setState(() {
      _isLoading = true;
    });

    try {
      // Start the magstripe card swipe
      // await T6PosPrinterPlugin.startMagstripeSwipe();

      // Get the track data
      final Map<String, dynamic> trackData = await T6PosSdk.getTrackData();
      setState(() {
        _trackData = "Track 1: ${trackData['track1']}\n"
            "Track 2: ${trackData['track2']}\n"
            "Track 3: ${trackData['track3']}\n"
            "Card Number: ${trackData['cardNumber']}\n"
            "Expiry Date: ${trackData['expiryDate']}\n"
            "Service Code: ${trackData['serviceCode']}";
      });
    } catch (e) {
      setState(() {
        _trackData = "Error: $e";
      });
    } finally {
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    initialize();
  }

  Future<void> addReceiptText() async {
    await T6PosSdk.initPrinter();
    // await _printImage();
    // await T6PosSdk.addText("\n\n", 24, "LEFT");
    await T6PosSdk.addText(
        "--------------------------------", 24, "CENTER");
    await T6PosSdk.addText("Receipt", 30, "CENTER",
        bold: true, underline: false, letterSpacing: 2, lineSpacing: 2);
    await T6PosSdk.addText(
        "--------------------------------", 24, "CENTER");
    await T6PosSdk.addText("\n\n", 24, "LEFT");
    // await T6PosSdk.addTwoTexts(
    //     "DATE:",
    //     22,
    //     "LEFT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2, // First text
    //     "${DateTime.now().day}/${DateTime.now().month}/${DateTime.now().year}",
    //     22,
    //     "RIGHT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2 // Second text
    // );
    // await T6PosSdk.addTwoTexts(
    //     "TIME:",
    //     22,
    //     "LEFT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2, // First text
    //     "${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}",
    //     22,
    //     "RIGHT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2 // Second text
    // );
    // await T6PosSdk.addTwoTexts(
    //     "AMOUNT:",
    //     22,
    //     "LEFT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2, // First text
    //     "K200.00",
    //     22,
    //     "RIGHT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2 // Second text
    // );
    // await T6PosSdk.addTwoTexts(
    //     "CUSTOMER:",
    //     22,
    //     "LEFT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2, // First text
    //     "John Banda",
    //     22,
    //     "RIGHT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2 // Second text
    // );
    // await T6PosSdk.addTwoTexts(
    //     "CITY:",
    //     22,
    //     "LEFT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2, // First text
    //     "LUSAKA",
    //     22,
    //     "RIGHT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2 // Second text
    // );
    // await T6PosSdk.addTwoTexts(
    //     "DISTRICT:",
    //     22,
    //     "LEFT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2, // First text
    //     "LUSAKA",
    //     22,
    //     "RIGHT",
    //     false,
    //     false,
    //     false,
    //     5,
    //     2 // Second text
    // );
    await T6PosSdk.addText("\n\n", 24, "LEFT");
    await T6PosSdk.addText(
        "--------------------------------", 24, "CENTER");
    await T6PosSdk.addText("THANK YOU.", 24, "CENTER");
    await T6PosSdk.addText(
        "--------------------------------", 24, "CENTER");
    await T6PosSdk.addText("", 24, "LEFT");
    await T6PosSdk.addText("", 24, "LEFT");
    await T6PosSdk.addText("", 24, "LEFT");
    await T6PosSdk.addText("\n\n", 24, "LEFT");
    // Print the receipt after all text has been added
    print('printing receipt');
    await T6PosSdk.printReceipt();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('T6 POS Plugin')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: addReceiptText,
                child: const Text("Print Receipt"),
              ),
              const SizedBox(height: 15,),
              _isLoading?const CircularProgressIndicator():ElevatedButton(
                onPressed: _startMagstripeSwipe,
                child: const Text("Swipe Card"),
              ),
              Center(child: Text('Card data: $_trackData')),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for the Topwise T6 POS device SDK.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on t6_pos_sdk

Packages that implement t6_pos_sdk