icash 0.1.1 icash: ^0.1.1 copied to clipboard
icash.io is flutter plugin that let's developer to integrate native icash payment method into their flutter application.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:icash/icash.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> implements IcashInterface {
TextEditingController textFieldController = TextEditingController();
String _icashResult = "Pending";
String _testPay = "";
@override
void initState() {
super.initState();
_testPay =
"{vendor_key:'production_c2c0f0fa-061a-4745-a447-867d165cefc6',amount:10000,title:'Icash Test',description:'This is only for test',transaction_id:" +
textFieldController.text +
"}";
}
@override
void onIcashSuccess(Map<String, String> _res) {
print(_res);
setState(() {
_icashResult = _res.toString();
});
}
@override
void onIcashError(String _action) {
print(_action + "_error");
setState(() {
_icashResult = _action;
});
}
void doPayment(BuildContext _ctx) {
try {
iCashPayment _ipayment = iCashPayment(this);
_ipayment.doPayment(_ctx,
vendor_key: "production_f2df1e1c-640b-4508-90e0-ba1d2811a23c",
amount: "1000",
title: "Icash Test",
description: "This is only for test",
transaction_id: textFieldController.text);
} on PlatformException {
_icashResult = "Error 1";
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('iCash Payment Test App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(32.0),
child: Text(_icashResult),
),
Padding(
padding: const EdgeInsets.all(32.0),
child: TextField(
controller: textFieldController,
style: TextStyle(
fontSize: 24,
color: Colors.black,
),
onChanged: (value) {
setState(() {
_testPay =
"{vendor_key:'production_f2df1e1c-640b-4508-90e0-ba1d2811a23c',amount:10000,title:'Icash Test',description:'This is only for test',transaction_id:" +
textFieldController.text +
"}";
});
},
),
),
Builder(
builder: (context) => RaisedButton(
onPressed: () {
doPayment(context);
},
child: Text('Pay 10'),
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Text(_testPay),
),
],
),
),
),
);
}
}