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; bool loading = false; @override void initState() { super.initState(); //load(); } initialize() async { String result = await _channel.invokeMethod('init', { 'serverUrl': 'http://185.98.84.231:2000', }); setState(() { initValue = result ?? 'none'; }); } version() async { String result = await _channel.invokeMethod('version'); setState(() { versionValue = result ?? 'none'; }); } transaction() async { String result = await _channel.invokeMethod('transaction'); setState(() { transactionValue = result ?? 'none'; }); } connect() async { String result = await _channel.invokeMethod("connection"); setState(() { connectionValue = result; }); } auth() async { String result = await _channel.invokeMethod("auth", {'login': 'uvaissov@gmail.com', 'password': '1234'}); 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; }); } 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), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('version: $versionValue'), RaisedButton( child: Text('Version'), onPressed: version), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('init: $initValue'), RaisedButton( child: Text('Init'), onPressed: initialize), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('connection: $connectionValue'), RaisedButton( child: Text('Connect'), onPressed: connect), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('auth: $authValue'), RaisedButton(child: Text('Auth'), onPressed: auth), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('cancel: $cancelValue'), RaisedButton(child: Text('Cancel'), onPressed: cancel), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('shutdown: $shutdownValue'), RaisedButton(child: Text('Shutdown'), onPressed: shutdown), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Text('transaction: $transactionValue'), RaisedButton(child: Text('Transaction'), onPressed: transaction), ], ), Text('pay: $payValue'), RaisedButton(child: Text('Payment'), onPressed: pay), ], ), ), ), ); } }