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

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_cashbox_payout_operation_data_model.dart';
import 'package:flutter_itl_bank_dispenser_example/get_counter_model.dart';
import 'package:flutter_itl_bank_dispenser_example/get_output_info_model.dart';
import 'package:flutter_itl_bank_dispenser_example/halt_payout_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;

  /// HaltPayout
  bool isHaltPayoutLoading = false;

  /// Get Counters
  bool isGetCountersLoading = false;
  List<GetCountersModel> getCountersModel = [];

  /// 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();
  double payoutAmount = 0.0;

  /// GetCashboxPayoutOpData
  bool isGetCashboxPayoutOpDataLoading = false;
  List<GetCashPayoutOpDataModel> getCashPayoutOpDataModels = [];

  /// Get Last Query Error Code
  bool isGetLastQueryErrorCodeLoading = false;

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

  Stream<Map<dynamic, dynamic>>? eventChannelStream;
  StreamSubscription<Map<dynamic, dynamic>>? _streamSubscription;

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

  }

  Stream<Map<dynamic, dynamic>>? getEventChannelStream(){
    eventChannelStream ??= FlutterItlBankDispenser.eventChannelStream();
    return eventChannelStream;
  }

  void startEventChannelStream({Function(PollingResultModel pollingResultModel)? pollingResultCallback, Function(PollingResultModel pollingResultModel)? statusCodeCallback, Function(List<Map<dynamic,dynamic>> comPorts)? comPortResultCallback}){
    getEventChannelStream();
    // disposeEventChannelStream();
    print("_streamSubscription : ${_streamSubscription}");
    _streamSubscription ??= eventChannelStream?.listen((event) async{
      // 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){
        print(event[FlutterItlBankDispenser.pollingCallBackEvent]);
        Map<String,dynamic> pollingCallback = Map<String,dynamic>.from(event[FlutterItlBankDispenser.pollingCallBackEvent]);
        PollingResultModel pollingResultModel = PollingResultModel.fromJson(pollingCallback);
        if(pollingResultModel.code == "getOutputLevelInfo"){
          getOutputInfoModels.clear();
          List<Map<dynamic,dynamic>> outputLevelInfo = List<Map<dynamic,dynamic>>.from(pollingResultModel.data);
          for (var element in outputLevelInfo) {
            getOutputInfoModels.add(GetOutputInfoModel.fromJson(Map<String, dynamic>.from(element)));
          }
        }
        else if(pollingResultModel.code == "connectComPort"){
          result = pollingResultModel.toJson();
        }
        else if (pollingResultModel.code == StatusCodeHelper.SSP_POLL_HALTED){
          HaltPayoutModel haltPayout = HaltPayoutModel.fromJson(Map<String, dynamic>.from(pollingResultModel.data));
          var remainingAmount = payoutAmount - (haltPayout.amount ?? 0.0);

          if(remainingAmount > 0){
            setPayoutStatus(true);
            await Future.delayed(Duration(milliseconds: 500));
            payout(remainingAmount.toInt(),"MYR");
          }
          print("HALTPAYOUT ");
        }
        else if (pollingResultModel.code == StatusCodeHelper.GETCOUNTERS){
          getCountersModel.clear();
          List<Map<dynamic,dynamic>> getCounter = List<Map<dynamic,dynamic>>.from(pollingResultModel.data);

          for (var element in getCounter) {
            getCountersModel.add(GetCountersModel.fromJson(Map<String, dynamic>.from(element)));
          }
          print("Get Counter");
        }
        else if (pollingResultModel.code == StatusCodeHelper.GETCASHBOX_OP_DATA){
          getCashPayoutOpDataModels.clear();
          List<Map<dynamic,dynamic>> getCounter = List<Map<dynamic,dynamic>>.from(pollingResultModel.data);

          for (var element in getCounter) {
            getCashPayoutOpDataModels.add(GetCashPayoutOpDataModel.fromJson(Map<String, dynamic>.from(element)));
          }
          print("Get Cashbox Op Data");
        }

        pollingResultModels.add(pollingResultModel);
        scrollController.jumpTo(scrollController.position.maxScrollExtent);
        setState(() {

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


  // 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);
    //     if(pollingResultModel.code == "getOutputLevelInfo"){
    //       getOutputInfoModels.clear();
    //       List<Map<dynamic,dynamic>> outputLevelInfo = List<Map<dynamic,dynamic>>.from(pollingResultModel.data);
    //       for (var element in outputLevelInfo) {
    //         getOutputInfoModels.add(GetOutputInfoModel.fromJson(Map<String, dynamic>.from(element)));
    //       }
    //     }else if(pollingResultModel.code == "connectComPort"){
    //       result = pollingResultModel.toJson();
    //     }
    //     pollingResultModels.add(pollingResultModel);
    //     scrollController.jumpTo(scrollController.position.maxScrollExtent);
    //     setState(() {
    //
    //     });
    //     print(pollingResultModelToJson(pollingResultModel));
    //   }
    //   print("event: ${event}");
    // });

    startEventChannelStream();

    // 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: (){
                                        reset();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Reset 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: !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(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isHaltPayoutLoading) ? null :(){
                                        haltPayout();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Halt Payout",
                                            style: TextStyle(

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

                                            ),
                                          ),
                                          if(isGetCountersLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isGetCashboxPayoutOpDataLoading) ? null :(){
                                        getCashboxPayoutOpData();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Get Cashbox Payout Op Data",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isGetCashboxPayoutOpDataLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: const CircularProgressIndicator(
                                                strokeWidth: 3.0,
                                              ),
                                            )
                                        ],
                                      )
                                  ),
                                ],
                              ),
                              getSpace(),
                              Row(
                                children: [
                                  ElevatedButton(
                                      onPressed: !isEnable(isGetLastQueryErrorCodeLoading) ? null :(){
                                        getLastQueryErrorCode();
                                      },
                                      child: Row(
                                        children: [
                                          Text(
                                            "Get Last Query Error Code",
                                            style: TextStyle(

                                            ),
                                          ),
                                          if(isGetLastQueryErrorCodeLoading)
                                            Container(
                                              margin: EdgeInsets.all(6.0),
                                              width: 15.0,
                                              height: 15.0,
                                              child: const 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
                                    ),
                                  )
                                ],
                              )
                          ),
                          getSpace(),
                          Container(
                            height: 300.0,
                            color: Colors.grey.withOpacity(0.5),
                            child: ListView.separated(
                                itemBuilder: (BuildContext context, int index){
                                  GetCountersModel getCounterModel = getCountersModel[index];
                                  var title = "";
                                  if(getCounterModel.id == 0){
                                    title = "Stacked";
                                  }
                                  else if(getCounterModel.id == 1){
                                    title = "Stored";
                                  }
                                  else if(getCounterModel.id == 2){
                                    title = "Dispensed";
                                  }
                                  else if(getCounterModel.id == 3){
                                    title = "Transferred to stack";
                                  }
                                  else if(getCounterModel.id == 4){
                                    title = "Rejected";
                                  }

                                  return Container(
                                      padding: EdgeInsets.all(6.0),
                                      child: Row(
                                        children: [
                                          Text(
                                            "${title} -- ${getCounterModel.value}"
                                          )
                                        ],
                                      )
                                  );
                                },
                                separatorBuilder: (BuildContext context, int index){
                                  return Container();
                                },
                                itemCount: getCountersModel.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 reset()async{
    try {
      var result = await FlutterItlBankDispenser.reset();

    } 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;
      });
      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 {
      startEventChannelStream();
      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;
      });
      disconnectComPort();
      var disposeStatus = await FlutterItlBankDispenser.disposePayout();
      if(disposeStatus){
        isPayOutEnable = false;
      }
      comPorts = [];
      selectedComPort = null;
      result = null;

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

  void haltPayout()async{
    try {
      setState(() {
        isHaltPayoutLoading = true;
      });
      await FlutterItlBankDispenser.haltPayout();

    } on PlatformException {
      print("haltPayout Error");
    }
    setState(() {
      isHaltPayoutLoading = false;
    });
  }

  void getCounters() async{
    try{

      setState(() {
        isGetCountersLoading = true;
      });

      await FlutterItlBankDispenser.getCounters();

    }
    catch (e){
      print("getCounters Error");
    }

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

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

      Map<dynamic, dynamic> outputLevelInfo = await FlutterItlBankDispenser.getOutputLevelInfo();
      print("outputLevelInfo == ${outputLevelInfo.length}");
      // 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);
      payoutAmount = amount.toDouble();
      await FlutterItlBankDispenser.payout(amount,currency);
    } on PlatformException {
      print("payout Error");
    }
    setState(() {
      isPayoutLoading = false;
    });
  }

  void getCashboxPayoutOpData()async{
    try {
      setState(() {
        isGetCashboxPayoutOpDataLoading = true;
      });

      Map<dynamic, dynamic> cashBoxPayoutOpData = await FlutterItlBankDispenser.getCashboxPayoutOpData();
      getCashPayoutOpDataModels.clear();
      print(cashBoxPayoutOpData);
      // for (var element in cashBoxPayoutOpData) {
      //   getCashPayoutOpDataModels.add(GetOutputInfoModel.fromJson(Map<String, dynamic>.from(element)));
      // }
    } on PlatformException {
      print("getCashboxPayoutOpDataLoading Error");
    }
    setState(() {
      isGetCashboxPayoutOpDataLoading = false;
    });

  }

  void getLastQueryErrorCode()async{
    try {
      setState(() {
        isGetLastQueryErrorCodeLoading = true;
      });

      Map<dynamic, dynamic> lastQueryErrorCode = await FlutterItlBankDispenser.getLastQueryErrorCode();
      var pollingResult = PollingResultModel.fromJson(Map<String, Object>.from(lastQueryErrorCode));
      pollingResult.returnMsg = (pollingResult.returnMsg ?? "") + "\n" + (pollingResult.errorMsg ?? "");
      pollingResultModels.add(pollingResult);
      scrollController.jumpTo(scrollController.position.maxScrollExtent);
      setState(() {

      });
      // for (var element in cashBoxPayoutOpData) {
      //   getCashPayoutOpDataModels.add(GetOutputInfoModel.fromJson(Map<String, dynamic>.from(element)));
      // }
    } on PlatformException {
      print("isGetLastQueryErrorCodeLoading Error");
    }
    setState(() {
      isGetLastQueryErrorCodeLoading = 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
110
pub points
1%
popularity

Publisher

unverified uploader

Unofficial ITL Bank Dispenser

Homepage

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on flutter_itl_bank_dispenser