import 'dart:convert'; import 'package:aman_kassa_flutter/core/models/aman_dao.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class BankView extends StatefulWidget { BankView(); @override _BankViewState createState() => _BankViewState(); } class _BankViewState extends State { static const MethodChannel _channel = MethodChannel('channel:com.amanKassa/bank'); static const MethodChannel _activity = MethodChannel('channel:com.amanKassa/activity'); String? initValue; String? connectionValue; String? authValue; String? payValue; String? cancelValue; String? shutdownValue; String? versionValue; String? transactionValue; String? closeDayValue; String? getValue; String? errorValue; bool loading = false; @override void initState() { super.initState(); //load(); } initialize() async { String result = await _channel.invokeMethod('init', { 'serverUrl': 'http://195.200.74.83:5000', }); setState(() { initValue = result; }); } version() async { String result = await _channel.invokeMethod('version'); setState(() { versionValue = result; }); } transaction() async { String result = await _channel.invokeMethod('transaction'); setState(() { transactionValue = result ; }); } connect() async { String result = await _channel.invokeMethod("connection"); setState(() { connectionValue = result; }); } auth() async { String result = await _channel.invokeMethod("auth", {'login': 'uvaissov@gmail.com', 'password': '8147'}); setState(() { authValue = result; }); } pay() async { String result; try { result = await _channel.invokeMethod("pay", {'amount': 100}); } catch (e) { result = (e.toString()); } setState(() { payValue = result; }); } cancel() async { String result; try { result = await _channel.invokeMethod("cancel"); } catch (e) { result = (e.toString()); } setState(() { cancelValue = result; }); } shutdown() async { String result; try { result = await _channel.invokeMethod("shutdown"); } catch (e) { result = (e.toString()); } setState(() { shutdownValue = result; }); } get() async { String result; try { String response = await _channel.invokeMethod("get"); AmanDao dao = AmanDao.fromJson(json.decode(response)); result = '${dao.data} - ${dao.msg}'; } catch (e) { result = (e.toString()); } setState(() { getValue = result; }); } closeDay() async { String result; try { String response = await _channel.invokeMethod("closeDay"); AmanDao dao = AmanDao.fromJson(json.decode(response)); result = '${dao.data} - ${dao.msg}'; } catch (e) { result = (e.toString()); } setState(() { closeDayValue = result; }); } error() async { String result; try { String json = await _channel.invokeMethod("error"); dynamic data = JsonDecoder().convert(json); result = data["msg"]; } catch (e) { result = (e.toString()); } setState(() { errorValue = result; }); } activity() async { String result = await _activity.invokeMethod("start"); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( centerTitle: true, title: Text('Банковская страница'), ), body: loading ? Container(child: Center(child: CircularProgressIndicator())) : SingleChildScrollView( child: Container( margin: const EdgeInsets.symmetric(horizontal: 14.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ RaisedButton( child: Text('Activity m4Bank'), onPressed: activity), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('version: $versionValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Version'), onPressed: version), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('init: $initValue' , overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Init'), onPressed: initialize), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('connection: $connectionValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Connect'), onPressed: connect), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('auth: $authValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton(child: Text('Auth'), onPressed: auth), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('cancel: $cancelValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton(child: Text('Cancel'), onPressed: cancel), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('shutdown: $shutdownValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Shutdown'), onPressed: shutdown), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('transaction: $transactionValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Transaction'), onPressed: transaction), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('get: $getValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Get'), onPressed: get), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('error: $errorValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('Error'), onPressed: error), ], ), Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('error: $closeDayValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton( child: Text('CloseDay'), onPressed: closeDay), ], ), Text('pay: $payValue', overflow: TextOverflow.clip, maxLines: 2, softWrap: false), RaisedButton(child: Text('Payment'), onPressed: pay), ], ), ), ), ); } }