import 'dart:convert'; import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import '../Home/HomePage.dart'; import '../Pay/PayPromptPay.dart'; import '../PinCodeVadidate.dart'; import '../api/api.dart'; import '../utils/color_custom.dart'; import '../utils/utils.dart'; import 'TransferCathayPayDialog.dart'; import 'TransferPromtptPayDialog.dart'; TextEditingController _phone = TextEditingController(); class TransferCathayPay extends StatefulWidget { const TransferCathayPay({Key? key}) : super(key: key); @override State createState() => _TransferCathayPayState(); } class _TransferCathayPayState extends State { @override Widget build(BuildContext context) { return Scaffold(body: SingleChildScrollView( child: Column( children: [ Row( children: [ IconButton( onPressed: () { Navigator.of(context).pop(); }, icon: Icon( Icons.arrow_back_ios, color: Colors.black, )), Text( "โอนเงินให้สมาชิก NEO PAY".tr(), style: TextStyle( color: Color(0xff050505), fontSize: 20, ), ) ], ), SizedBox(height: 20,), Container( child: TextField( keyboardType: TextInputType.number, inputFormatters: [ FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), ], controller: _phone, decoration: InputDecoration( hintText: 'เบอร์โทรศัพท์ผู้รับ'.tr(), border: InputBorder.none, contentPadding: EdgeInsets.symmetric(horizontal: 16), ), ), margin: EdgeInsets.symmetric(horizontal: 20), height: 48, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), ), SizedBox(height: 20,), InkWell( onTap: () async { showModalBottomSheet( context: context, isScrollControlled: true, useSafeArea: true, shape: RoundedRectangleBorder( borderRadius: BorderRadius.vertical( top: Radius.circular(16), ), ), builder: (BuildContext context) { return TransferCathayPayDetail(); }); }, child: Container( width: double.infinity, margin: const EdgeInsets.symmetric(horizontal: 15), child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(40), ), child: Container( padding: EdgeInsets.all(10), child: Text( "Next".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: ColorCustom.greyBorder, fontSize: 20, fontWeight: FontWeight.w500, ), ), ), ), ), ), SizedBox( height: 20, ) ], ), ),); } } class TransferCathayPayDetail extends StatefulWidget { const TransferCathayPayDetail({Key? key}) : super(key: key); @override State createState() => _TransferCathayPayDetailState(); } class _TransferCathayPayDetailState extends State { @override void initState() { initPromptPay(context); refresh(); setState(() {}); super.initState(); } TextEditingController _price = TextEditingController(); TextEditingController _amount = TextEditingController(); String name =""; String phone =""; String trans =""; initPromptPay (BuildContext context) async { phone = '${_phone.text .substring(0, 3)}-${_phone.text .substring(3, 6)}-${_phone.text .substring(6)}'; var param = jsonEncode({"idCardOrMobileDeviceNo": phone, "amount": 1}); await Api.post(context, Api.transferedPromptPayInitial, param).then((value) => { if (value != null) { name = value['promptPayname'], trans = value['transactionlogid'] // refresh() } else {} }); refresh(); setState(() {}); } confirmPromptPay2 (BuildContext context) { // var trans ; var param = jsonEncode({"idCardOrMobileDeviceNo": phone, "amount": _amount.text}); Api.post(context, Api.transferedPromptPayInitial, param).then((value) => { if (value != null) { name = value['promptPayname'], trans = value['transactionlogid'] // refresh() } else {} }); sleep(new Duration(seconds: 3)); var param2 = jsonEncode({"idCardOrMobileDeviceNo": phone, "amount": _amount.text.replaceAll(",", ""), "transactionID": trans, "note": ""}); Api.post(context, Api.transferedPromptPayConfirm, param2).then((value) => { if (value != null) { showDialog( context: context, builder: (BuildContext context) { return TransferPromtptPayDialog( price: _amount.text, bill: value["data"]["_TranID"], phone: phone, name: name, ); }) } else {} }); } refresh() { setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.white, actions: [ CupertinoButton( onPressed: () { Navigator.pop(context); }, child: IconButton( onPressed: () { Navigator.of(context).pop(); }, icon: const Icon( Icons.clear, color: Colors.grey, ), ), ) ], elevation: 0, title: Text( "Transfer Money".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: Colors.black, fontSize: 20, ), ), ), body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(20.0), child: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ Text( "ชื่อ".tr(), style: TextStyle( color: Color(0xff65676b), fontSize: 16, fontWeight: FontWeight.w300, ), ), SizedBox( height: 20, ), Container( height: 48, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), child: Row( children: [ Spacer(), Text( name, textAlign: TextAlign.right, style: TextStyle( color: Color(0xff65676b), fontSize: 20, ), ), SizedBox( width: 20, ) ], ), ), SizedBox( height: 10, ), Row( children: [ Text( "เบอร์โทรศัพท์".tr(), style: TextStyle( color: Color(0xff65676b), fontSize: 14, fontWeight: FontWeight.w300, ), ), Spacer(), Text( "", textAlign: TextAlign.right, style: TextStyle( color: Color(0xff65676b), fontSize: 16, ), ) ], ), SizedBox( height: 10, ), Text( "จำนวนเงินที่โอน / จ่าย".tr(), style: TextStyle( color: Color(0xff65676b), fontSize: 16, fontWeight: FontWeight.w300, ), ), SizedBox( height: 10, ), Container( child: Row( children: [Spacer(), Expanded( child: TextField(textAlign: TextAlign.end, keyboardType: TextInputType.number, inputFormatters: [ FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), ], controller: _amount, decoration: InputDecoration( // hintText: 'เบอร์โทรศัพท์ผู้รับ'.tr(), border: InputBorder.none, contentPadding: EdgeInsets.symmetric(horizontal: 16), ), ), ), ], ), //margin: EdgeInsets.symmetric(horizontal: 20), height: 48, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), ), // Container( // height: 48, // decoration: BoxDecoration( // borderRadius: BorderRadius.circular(100), // color: Color(0xfff2f2f2), // ), // child: Row( // children: [ // Spacer(), // Text( // "", // textAlign: TextAlign.right, // style: TextStyle( // color: Color(0xff65676b), // fontSize: 20, // ), // ), // SizedBox( // width: 20, // ) // ], // ), // ), SizedBox( height: 10, ), Text( "ใช้แต้ม NEO PAY แทนเงินสด".tr(), style: TextStyle( color: Color(0xff65676b), fontSize: 16, fontWeight: FontWeight.w300, ), ), Text( "${"คะแนนของคุณ".tr()} : ${Utils.moneyFormat(profile?.maxCardMembers.first.pointBalance)} ${"แต้ม".tr()}", style: TextStyle( color: Color(0xff9d001b), fontSize: 14, ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), padding: const EdgeInsets.symmetric( horizontal: 20, vertical: 6, ), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "10 ${"แต้ม".tr()}", textAlign: TextAlign.right, style: TextStyle( color: Color(0xff65676b), ), ), ], ), ), Text( "=", textAlign: TextAlign.right, style: TextStyle( color: Color(0xff65676b), fontSize: 24, ), ), Container( width: 161, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xff9d001b), ), padding: const EdgeInsets.symmetric( horizontal: 20, vertical: 6, ), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "100 ${"Baht".tr()}", textAlign: TextAlign.right, style: TextStyle( color: Colors.white, ), ), ], ), ) ], ), Center( child: Text( "1 แต้ม = 10 สตางค์".tr(), textAlign: TextAlign.center, style: TextStyle( color: Color(0xff65676b), fontSize: 14, fontWeight: FontWeight.w300, ), ), ), Container( height: 136, color: Colors.transparent, child: Column( children: [ SizedBox( height: 20, ), Row( children: [ Text( "ยอดเงินทั้งหมด".tr(), style: TextStyle( color: Color(0xff65676b), fontSize: 16, ), ), Spacer(), Text( "", textAlign: TextAlign.right, style: TextStyle( color: Color(0xff9d001b), fontSize: 16, fontWeight: FontWeight.w600, ), ), Text( " ${"Baht".tr()}", textAlign: TextAlign.right, style: TextStyle( color: Color(0xff65676b), fontSize: 16, ), ) ], ), SizedBox( height: 20, ), InkWell( onTap: () async { final result = await Navigator.push( context, MaterialPageRoute(builder: (context) => PinCodeValidatePage()), ); if (result == true) { // showDialog( // context: context, // builder: (BuildContext context) { // return TransferCathayPayDialog(); return confirmPromptPay2(context); // }); } }, child: SizedBox( width: double.infinity, child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(40), ), child: Container( padding: EdgeInsets.all(10), child: Text( "Confirm".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: ColorCustom.greyBorder, fontSize: 20, fontWeight: FontWeight.w500, ), ), ), ), ), ), SizedBox( height: 10, ), ], ), ), SizedBox( height: 10, ), ], ), ), ), )); } }