flutter_itl_bank_dispenser 0.0.11 copy "flutter_itl_bank_dispenser: ^0.0.11" to clipboard
flutter_itl_bank_dispenser: ^0.0.11 copied to clipboard

outdated

Unofficial ITL Bank Dispenser

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_itl_bank_dispenser/flutter_itl_bank_dispenser.dart';
import 'package:flutter_itl_bank_dispenser/ssp_command/status_code_helper.dart';
import 'package:flutter_itl_bank_dispenser_example/get_output_info_model.dart';
import 'package:flutter_itl_bank_dispenser_example/polling_result_model.dart';

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

enum BOX_TYPE { CASHBOX, SMARTPAYOUT }

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  /// Payout
  bool isPayOutEnable = false;
  bool isPayOutLoading = false;

  /// Payout
  bool isInitPayOutLoading = false;

  /// Connect Com Port
  int? selectedComPort;
  bool isConnectComPortLoading = false;
  Map<dynamic, dynamic>? result;

  /// Disconnect Com Port
  bool isDisconnectComPortLoading = false;

  /// SetPayOutStatus
  bool isSetPayOutStatusLoading = false;

  /// SetPolling
  bool isSetPollingLoading = false;

  /// SetEmpty
  bool isSetEmptyLoading = false;

  /// Dispose
  bool isDisposeLoading = false;

  /// GetOutputLevelInfo
  bool isGetOutputLevelInfoLoading = false;
  List<GetOutputInfoModel> getOutputInfoModels = [];

  /// GetChannelNumber
  bool isGetChannelNumberLoading = false;
  List<GetOutputInfoModel> getChannelNumberModels = [];
  List<BOX_TYPE> boxTypes = [];

  /// Called getComPorts
  List<Map<dynamic,dynamic>> comPorts =[];
  bool isGetComPortsLoading = false;

  /// SetRouting
  bool isSetRoutingLoading = false;

  /// Payout
  bool isPayoutLoading = false;
  TextEditingController textEditingController = TextEditingController();


  List<PollingResultModel> pollingResultModels = [];
  ScrollController scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(milliseconds: 1000),(){
      initPlatformState();
    });

  }

  // 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 {
    //   platformVersion =
    //       await FlutterItlBankDispenser.test ?? 'Unknown platform version';
    // } 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 ?? "";
    });

    FlutterItlBankDispenser.eventChannelStream().listen((event) {
      // print(event[FlutterItlBankDispenser.getComPortsEvent]);
      if(event[FlutterItlBankDispenser.getComPortsEvent] != null){
        isGetComPortsLoading = false;
        comPorts = List<Map<dynamic,dynamic>>.from(event[FlutterItlBankDispenser.getComPortsEvent]);
        setState(() {

        });
      }
      else if(event[FlutterItlBankDispenser.pollingCallBackEvent] != null){
        Map<String,dynamic> pollingCallback = Map<String,dynamic>.from(event[FlutterItlBankDispenser.pollingCallBackEvent]);
        PollingResultModel pollingResultModel = PollingResultModel.fromJson(pollingCallback);
        pollingResultModels.add(pollingResultModel);
        scrollController.jumpTo(scrollController.position.maxScrollExtent);
        setState(() {

        });
        print(pollingResultModelToJson(pollingResultModel));
      }
      print("event: ${event}");
    });

    // isInit();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scrollBehavior: MaterialScrollBehavior().copyWith(
        dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch, PointerDeviceKind.stylus, PointerDeviceKind.unknown},
      ),
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: SingleChildScrollView(
              padding: EdgeInsets.all(16.0),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "Init Payout Status : ${isPayOutEnable}",
                          style: TextStyle(

                          ),
                        ),
                        getSpace(),
                        Row(
                          children: [
                            ElevatedButton(
                                onPressed: isPayOutLoading ? null :(){
                                  initialize();
                                },
                                child: Row(
                                  children: [
                                    Text(
                                      "Init Payout",
                                      style: TextStyle(

                                      ),
                                    ),
                                    if(isPayOutLoading)
                                      Container(
                                        margin: EdgeInsets.all(6.0),
                                        width: 15.0,
                                        height: 15.0,
                                        child: CircularProgressIndicator(
                                          strokeWidth: 3.0,
                                        ),
                                      )
                                  ],
                                )
                            ),
                          ],
                        ),
                        getSpace(),
                        Row(
                          children: [
                            ElevatedButton(
                                onPressed: isInitPayOutLoading ? null :(){
                                  isInit();
                                },
                                child: Row(
                                  children: [
                                    Text(
                                      "isInit Payout",
                                      style: TextStyle(

                                      ),
                                    ),
                                    if(isInitPayOutLoading)
                                      Container(
                                        margin: EdgeInsets.all(6.0),
                                        width: 15.0,
                                        height: 15.0,
                                        child: CircularProgressIndicator(
                                          strokeWidth: 3.0,
                                        ),
                                      )
                                  ],
                                )
                            ),
                          ],
                        ),
                        if(comPorts.isEmpty)
                          Text(
                              "Empty COM ports"
                          ),
                        ListView.separated(
                            shrinkWrap: true,
                            itemBuilder: (BuildContext context, int index){
                              return GestureDetector(
                                onTap: (){
                                  setState(() {
                                    selectedComPort = index;
                                  });
                                },
                                behavior: HitTestBehavior.translucent,
                                child: Container(
                                  padding: EdgeInsets.all(10.0),
                                  child: Row(
                                    children: [
                                      Text("${index+1}. ${comPorts[index]["port"]}")
                                    ],
                                  ),
                                ),
                              );
                            },
                            separatorBuilder: (BuildContext context, int index){
                              return Container(
                                height: 1.0,
                                color: Colors.grey.withOpacity(0.6),
                              );
                            },
                            itemCount: comPorts.length
                        ),
                        getSpace(),
                        Row(
                          children: [
                            ElevatedButton(
                                onPressed: !isEnable(isGetComPortsLoading) ? null :(){
                                  getComPorts();
                                },
                                child: Row(
                                  children: [
                                    Text(
                                      "Get Com Ports",
                                      style: TextStyle(

                                      ),
                                    ),
                                    if(isGetComPortsLoading)
                                      Container(
                                        margin: EdgeInsets.all(6.0),
                                        width: 15.0,
                                        height: 15.0,
                                        child: CircularProgressIndicator(
                                          strokeWidth: 3.0,
                                        ),
                                      )
                                  ],
                                )
                            ),
                          ],
                        ),
                        getSpace(),
                        if(selectedComPort!=null)
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                  "Selected : ${comPorts[selectedComPort!]["port"].toString()}"
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isConnectComPortLoading) ? null :(){
                                        connectComPort();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Connect to Com Port and Payout",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isConnectComPortLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              if(result!=null)
                                Text(
                                  "${result!["result"]==true ? "${result!["returnMsg"]}" : "${result!["errorMsg"]}"}",
                                  style: TextStyle(

                                  ),
                                ),
                            ],
                          ),
                        getSpace(),
                        if(result!=null && result!["result"]==true)
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isDisconnectComPortLoading) ? null :(){
                                        disconnectComPort();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Disconnect Com Port",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isDisconnectComPortLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetPayOutStatusLoading) ? null :(){
                                        setPayoutStatus(true);
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Enable Payout",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetPayOutStatusLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetPayOutStatusLoading) ? null :(){
                                        setPayoutStatus(false);
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Disable Payout",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetPayOutStatusLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetPollingLoading) ? null :(){
                                        setPolling(true);
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Enable Polling",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetPollingLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetPollingLoading) ? null :(){
                                        setPolling(false);
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Disable Polling",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetPollingLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetEmptyLoading) ? null :(){
                                        setEmpty(FlutterItlBankDispenser.normalEmptyMode);
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Normal Empty",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetEmptyLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetEmptyLoading) ? null :(){
                                        setEmpty(FlutterItlBankDispenser.smartEmptyMode);
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Smart Empty",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetEmptyLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: (){
                                        returnNote();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Return Note",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isPayOutLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isGetOutputLevelInfoLoading) ? null :(){
                                        getOutputLevelInfo();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Get Output Level Info",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isGetOutputLevelInfoLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isGetChannelNumberLoading) ? null :(){
                                        getChannelNumbers();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Get Channel Numbers",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isGetChannelNumberLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              TextFormField(
                                controller: textEditingController,
                                keyboardType: TextInputType.number,
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isSetRoutingLoading) ? null :(){
                                        payout(int.parse(textEditingController.text),"MYR");
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Payout",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isSetRoutingLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isDisposeLoading) ? null :(){
                                        disposePayout();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Dispose Payout",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isDisposeLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                            ],
                          )
                      ],
                    ),
                  ),
                  Expanded(
                      child: Column(
                        children: [
                          Container(
                            height: 300.0,
                            color: Colors.grey.withOpacity(0.5),
                            child: ListView.separated(
                                controller: scrollController,
                                itemBuilder: (BuildContext context, int index){
                                  PollingResultModel pollResultModel = pollingResultModels[index];
                                  String errorMsg = StatusCodeHelper.getErrorString(pollResultModel.code ?? "");
                                  if(errorMsg.isNotEmpty){
                                    print(errorMsg);
                                  }
                                  return Container(
                                    padding: EdgeInsets.all(6.0),
                                    child: Text(
                                        "${pollResultModel.returnMsg}"
                                    ),
                                  );
                                },
                                separatorBuilder: (BuildContext context, int index){
                                  return Container();
                                },
                                itemCount: pollingResultModels.length
                            ),
                          ),
                          getSpace(),
                          Container(
                              height: 300.0,
                              child: Row(
                                children: [
                                  Expanded(
                                    child: Container(
                                      color: Colors.grey.withOpacity(0.5),
                                      child: ListView.separated(
                                          itemBuilder: (BuildContext context, int index){
                                            GetOutputInfoModel getOutputInfoModel = getOutputInfoModels[index];
                                            return Container(
                                                padding: EdgeInsets.all(6.0),
                                                child: Row(
                                                  children: [
                                                    Text(
                                                        "${getOutputInfoModel.numNotes} x ${getOutputInfoModel.currency} ${getOutputInfoModel.amount}"
                                                    )
                                                  ],
                                                )
                                            );
                                          },
                                          separatorBuilder: (BuildContext context, int index){
                                            return Container();
                                          },
                                          itemCount: getOutputInfoModels.length
                                      ),
                                    ),
                                  ),
                                  SizedBox(width: 10.0,),
                                  Expanded(
                                    child: ListView.separated(
                                        itemBuilder: (BuildContext context, int index){
                                          GetOutputInfoModel getChannelNumberModel = getChannelNumberModels[index];
                                          return Container(
                                              padding: EdgeInsets.all(6.0),
                                              child: Column(
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: [
                                                  Text(
                                                    "${getChannelNumberModel.currency} ${getChannelNumberModel.amount}",
                                                    style: TextStyle(
                                                        fontWeight: FontWeight.bold
                                                    ),
                                                  ),
                                                  getCheckBoxContainer(index)
                                                ],
                                              )
                                          );
                                        },
                                        separatorBuilder: (BuildContext context, int index){
                                          return Container();
                                        },
                                        itemCount: getChannelNumberModels.length
                                    ),
                                  )
                                ],
                              )
                          )
                        ],
                      )
                  )
                ],
              )

          )
      ),
    );
  }

  Widget getCheckBoxContainer(int index){
    BOX_TYPE boxType = boxTypes[index];

    return Row(
      children: [
        Container(
          width: 150.0,
          child: RadioListTile<BOX_TYPE>(
            title: Text("Cashbox"),
            value: BOX_TYPE.CASHBOX,
            groupValue: boxType,
            onChanged: isSetRoutingLoading ? null : (newValue) {
              if(newValue != null){
                boxTypes[index] = newValue;
                GetOutputInfoModel getChannelNumberModel = getChannelNumberModels[index];
                setRouting(FlutterItlBankDispenser.cashMode,getChannelNumberModel.amount?.toInt() ?? 0,getChannelNumberModel.currency ?? "");
                setState(() {

                });
              }

            },
            controlAffinity: ListTileControlAffinity.leading,  //  <-- leading Checkbox
          ),
        ),
        Container(
          width: 150.0,
          child: RadioListTile<BOX_TYPE>(
            title: Text("SmartPayout"),
            value: BOX_TYPE.SMARTPAYOUT,
            groupValue: boxType,
            onChanged: isSetRoutingLoading ? null : (newValue) {
              if(newValue != null){
                boxTypes[index] = newValue;
                GetOutputInfoModel getChannelNumberModel = getChannelNumberModels[index];
                setRouting(FlutterItlBankDispenser.smartPayMode,getChannelNumberModel.amount?.toInt() ?? 0,getChannelNumberModel.currency ?? "");
                setState(() {

                });
              }
            },
            controlAffinity: ListTileControlAffinity.leading,  //  <-- leading Checkbox
          ),
        )
      ],
    );
  }

  void initialize()async{
    try {
      isPayOutEnable = await FlutterItlBankDispenser.initialize(FlutterItlBankDispenser.baudRate, FlutterItlBankDispenser.timeout, FlutterItlBankDispenser.retryLevel) ?? false;
      isPayOutLoading = false;
      setState(() {

      });
    } on PlatformException {
      print("initialize Error");
    }
  }

  void isInit()async{
    try {
      isPayOutEnable = await FlutterItlBankDispenser.isInit() == true;
      isInitPayOutLoading = false;
      Future.delayed(Duration.zero,(){
        setState(() {

        });
      });
    } on PlatformException {
      print("initialize Error");
    }
  }

  void setRouting(int routingMode, int amount, String currency)async{
    try {
      await FlutterItlBankDispenser.setRouting(routingMode, amount, currency);
      isSetRoutingLoading = true;
      setState(() {

      });
    } on PlatformException {
      print("setRouting Error");
    }

    setState(() {
      isSetRoutingLoading = false;
    });
  }

  void getComPorts()async{
    try {
      await FlutterItlBankDispenser.getComPorts;
      isGetComPortsLoading = true;
      setState(() {

      });
    } on PlatformException {
      print("GetComPorts Error");
    }
  }

  void returnNote()async{
    try {
      await FlutterItlBankDispenser.returnNote();

    } on PlatformException {
      print("returnNote Error");
    }
  }

  void connectComPort()async{
    try {
      var comPort = comPorts[selectedComPort!]["port"].toString();
      setState(() {
        isConnectComPortLoading = true;
      });
      result = await FlutterItlBankDispenser.connectComPort(int.parse(comPort[comPort.length-1]));

    } on PlatformException {
      print("connectComPort Error");
    }
    setState(() {
      isConnectComPortLoading = false;
    });
  }

  void disconnectComPort()async{
    try {
      setState(() {
        isDisconnectComPortLoading = true;
      });
      await FlutterItlBankDispenser.disconnectComPort();
      result = null;

    } on PlatformException {
      print("disconnectComPort Error");
    }
    setState(() {
      isDisconnectComPortLoading = false;
    });

  }

  void setPayoutStatus(bool isEnable)async{
    try {
      setState(() {
        isSetPayOutStatusLoading = true;
      });
      await FlutterItlBankDispenser.setPayoutStatus(isEnable);

    } on PlatformException {
      print("setPayoutStatus Error");
    }
    setState(() {
      isSetPayOutStatusLoading = false;
    });
  }

  void setPolling(bool isEnable)async{
    try {
      setState(() {
        isSetPollingLoading = true;
      });
      await FlutterItlBankDispenser.setPolling(isEnable);

    } on PlatformException {
      print("setPolling Error");
    }
    setState(() {
      isSetPollingLoading = false;
    });
  }

  void setEmpty(int mode)async{
    try {
      setState(() {
        isSetEmptyLoading = true;
      });
      await FlutterItlBankDispenser.empty(mode);

    } on PlatformException {
      print("setPolling Error");
    }
    setState(() {
      isSetEmptyLoading = false;
    });
  }

  void disposePayout()async{
    try {
      setState(() {
        isDisposeLoading = true;
      });
      var disposeStatus = await FlutterItlBankDispenser.disposePayout();
      if(disposeStatus){
        isPayOutEnable = false;
      }
      comPorts = [];
      selectedComPort = null;
      result = null;

    } on PlatformException {
      print("disposePayout Error");
    }
    setState(() {
      isDisposeLoading = false;
    });
  }

  void reset(){

  }

  void getOutputLevelInfo() async{
    try {
      setState(() {
        isGetOutputLevelInfoLoading = true;
      });

      List<Map<dynamic, dynamic>> outputLevelInfo = await FlutterItlBankDispenser.getOutputLevelInfo();
      getOutputInfoModels.clear();
      for (var element in outputLevelInfo) {
        getOutputInfoModels.add(GetOutputInfoModel.fromJson(Map<String, dynamic>.from(element)));
      }
    } on PlatformException {
      print("getOutputLevelInfo Error");
    }
    setState(() {
      isGetOutputLevelInfoLoading = false;
    });
  }

  void getChannelNumbers() async{
    try {
      setState(() {
        isGetChannelNumberLoading = true;
      });

      List<Map<dynamic, dynamic>> getChannelNumberModel = await FlutterItlBankDispenser.getNumChannel();
      getChannelNumberModels.clear();
      boxTypes.clear();
      for (var element in getChannelNumberModel) {
        GetOutputInfoModel getOutputInfoModel = GetOutputInfoModel.fromJson(Map<String, dynamic>.from(element));
        getChannelNumberModels.add(getOutputInfoModel);
        boxTypes.add(getOutputInfoModel.isRecycling == false? BOX_TYPE.CASHBOX : BOX_TYPE.SMARTPAYOUT);
      }
    } on PlatformException {
      print("getChannelNumbers Error");
    }
    setState(() {
      isGetChannelNumberLoading = false;
    });
  }

  void payout(int amount, String currency) async{
    try {
      setState(() {
        isPayoutLoading = true;
      });
      print(amount);
      await FlutterItlBankDispenser.payout(amount,currency);
    } on PlatformException {
      print("payout Error");
    }
    setState(() {
      isPayoutLoading = false;
    });
  }

  bool isEnable(bool isLoading){
    return isPayOutEnable && !isLoading;
  }

  Widget getText(bool isSuccess){
    return Container(
      margin: EdgeInsets.only(left: 16.0),
      child: Text(
        "${isSuccess}",
        style: TextStyle(
            color: isSuccess ? Colors.green : Colors.red
        ),
      ),
    );
  }

  Widget getSpace(){
    return SizedBox(height: 10.0,);
  }
}
0
likes
0
points
186
downloads

Publisher

unverified uploader

Weekly Downloads

Unofficial ITL Bank Dispenser

License

unknown (license)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on flutter_itl_bank_dispenser

Packages that implement flutter_itl_bank_dispenser