pos_sdk 0.1.0 copy "pos_sdk: ^0.1.0" to clipboard
pos_sdk: ^0.1.0 copied to clipboard

unlisted

The implementation of the pos_sdk, specific for v1.1.14 poslink reservation.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:pos_sdk/PaxSdkPlugin.g.dart';
import 'package:pos_sdk/pax_card_payment_gateway.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 _platformVersion = 'Unknown';
  late PaxCardPaymentGateway gw;

  @override
  void initState() {
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      final info = await gw.getTerminalInfo();
      debugPrint('info $info');

      Map<String?, String?> result = await PosPayApi().getTerminalInfo();
      platformVersion =
          "\nMerchant Name: ${result["merchantName"]}\nMerchant ID: ${result["merchantID"]}\nTerminal ID: ${result["terminalID"]}\nDevice Model: ${result["deviceModel"]}\nDevice Serial: ${result["deviceSerial"]}";
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<void>(
        future: initPlatformState(),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(
              child: CircularProgressIndicator(),
            );
          }
          return MaterialApp(
            home: Scaffold(
              appBar: AppBar(
                title: const Text('Plugin example app'),
              ),
              body: Scaffold(
                body: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Text('Result:$_platformVersion\n'),
                      customElevatedButton(
                        width: 300,
                        height: 60,
                        onPressed: () async {
                          final result = await PosPayApi().getTerminalInfo();
                          _platformVersion =
                              '\nMerchant Name: ${result["merchantName"]}\n'
                              'Merchant ID: ${result["merchantID"]}\n'
                              'Terminal ID: ${result["terminalID"]}\n'
                              'Device Model: ${result["deviceModel"]}\n'
                              'Device Serial: ${result["deviceSerial"]}';
                          setState(() {});
                        },
                        icon: Icons.refresh,
                        label: 'Terminal info',
                      ),
                      GridView.count(
                        crossAxisCount: 3,
                        crossAxisSpacing: 8.0,
                        mainAxisSpacing: 8.0,
                        childAspectRatio: 1.5,
                        shrinkWrap: true,
                        children: [
                          //Refund Button
                          customElevatedButton(
                            onPressed: () async {
                              POSResult result =
                                  await PosPayApi().refund("24.99");
                              setState(() {
                                _platformVersion = getResultDetails(result);
                              });
                            },
                            icon: Icons.refresh,
                            label: 'Refund',
                          ),
                          //Inquiry button
                          customElevatedButton(
                            onPressed: () async {
                              POSResult result = await PosPayApi().inquiry();

                              setState(() {
                                _platformVersion = getResultDetails(result);
                              });

                              debugPrint(result.toString());
                            },
                            icon: Icons.question_mark,
                            label: 'Inquiry',
                          ),
                          //reprint button
                          customElevatedButton(
                            onPressed: () async {
                              POSResult result = await PosPayApi().reprint("1");
                              setState(() {
                                _platformVersion = getResultDetails(result);
                              });
                              debugPrint(result.toString());
                            },
                            icon: Icons.receipt,
                            label: 'Reprint',
                          ),

                          // last receipt button
                          customElevatedButton(
                            onPressed: () async {
                              POSResult result =
                                  await PosPayApi().lastReceipt();
                              debugPrint(result.toString());
                              setState(() {
                                _platformVersion = getResultDetails(result);
                              });
                            },
                            icon: Icons.receipt_long,
                            label: 'Last Receipt',
                          ),

                          customElevatedButton(
                            onPressed: () async {
                              try {
                                final printRequest = PrinterRequest(
                                    image: (await rootBundle
                                            .load("assets/logo.png"))
                                        .buffer
                                        .asUint8List(),
                                    address: PrintAddress(
                                      address1: "Unit 4",
                                      address2: "4 karen St",
                                      city: "Sandton",
                                      country: 'South Africa',
                                      postalCode: "1724",
                                      state: "Gauteng",
                                    ),
                                    businessName: "Little Fish",
                                    amountTendered: 1567.00,
                                    currencyCode: "R",
                                    header: "Welcome to little fish",
                                    whatsapp: "+27 81 043 4369",
                                    instagram: "littlefishapp@instagram.com",
                                    tell: "+27 81 043 4369",
                                    items: [
                                      Inventory(
                                          itemDescription: "first item",
                                          price: 5.0,
                                          quantity: 3),
                                      Inventory(
                                          itemDescription: "second item",
                                          price: 7.0,
                                          quantity: 3),
                                      Inventory(
                                          itemDescription: "third item",
                                          price: 3.0,
                                          quantity: 3),
                                    ],
                                    taxValue: 15,
                                    taxCode: "1457",
                                    totalTax: 1567.00 * 0.15,
                                    customerName: "Freedom Mathebula",
                                    customerId:
                                        "12nuoibufbhgfkjwhagfjrahgiourhie34567",
                                    sellerId:
                                        "7654dbwiyeqgfjhegjrwhgfjabjfhgrfjkr321",
                                    sellerName: "Themba Mathebula",
                                    footer: "Please call again!!");

                                final result =
                                    await PosPayApi().print(printRequest);
                                debugPrint(result.toString());
                                setState(() {
                                  _platformVersion = getResultDetails(result);
                                });
                              } catch (e) {
                                if (e is PlatformException) {
                                  debugPrint(e.details['message']);
                                } else {
                                  debugPrint('ERROR $e');
                                }
                              }
                            },
                            icon: Icons.print,
                            label: 'Print',
                          ),

                          //charge button
                          customElevatedButton(
                            onPressed: () async {
                              POSResult result =
                                  await PosPayApi().charge("24.99");
                              setState(() {
                                _platformVersion = getResultDetails(result);
                              });
                              debugPrint(result.toString());
                            },
                            icon: Icons.credit_card,
                            label: 'Charge',
                          ),

                          //camera scan button
                          customElevatedButton(
                            onPressed: () async {
                              ScanResult scanResult = await PosPayApi().scan();
                              debugPrint(scanResult.toString());

                              setState(() {
                                _platformVersion =
                                    "${scanResult.resultString}: ${scanResult.resultFormat}";
                              });
                            },
                            icon: Icons.camera_alt,
                            label: 'Scan camera',
                          ),
                          //infrared scan button
                          customElevatedButton(
                            onPressed: () async {
                              ScanResult scanResult =
                                  await PosPayApi().scanHW();
                              debugPrint(scanResult.toString());
                              setState(() {
                                _platformVersion =
                                    " ${scanResult.resultString}: ${scanResult.resultFormat}";
                              });
                            },
                            icon: Icons.scanner,
                            label: 'Scan laser',
                          ),
                          customElevatedButton(
                            onPressed: () async {
                              int batchNo = await PosPayApi().getBatchNo();
                              debugPrint("BatchNo: $batchNo");
                              setState(() {
                                _platformVersion = "BatchNo: $batchNo";
                              });
                            },
                            icon: Icons.tag,
                            label: 'Batch No',
                          ),
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ),
          );
        });
  }

  String getResultDetails(POSResult result) {
    return "plugin message: ${result.resultMessage} \n"
        "plugin code: ${result.resultCode}\n"
        "device message: ${result.deviceMessage} \n"
        "device code: ${result.deviceCode}\n"
        "batch No: ${result.resultObject?["batchNumber"]}";
  }

  Widget customElevatedButton({
    required void Function()? onPressed,
    String label = '',
    required IconData icon,
    double width = 100,
    double height = 100,
  }) {
    return ElevatedButton(
      onPressed: onPressed,
      style: ElevatedButton.styleFrom(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(16), // Square shape
        ),
        fixedSize: Size(width, height), // Button size
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(icon, size: 24), // Icon
          const SizedBox(height: 4), // Spacing between icon and text
          Text(label, textAlign: TextAlign.center), // Text
        ],
      ),
    );
  }
}
1
likes
0
points
50
downloads

Publisher

verified publisherlittlefishapp.com

Weekly Downloads

The implementation of the pos_sdk, specific for v1.1.14 poslink reservation.

Homepage

License

unknown (license)

Dependencies

dartz, flutter, littlefish_interfaces

More

Packages that depend on pos_sdk

Packages that implement pos_sdk