import 'dart:convert'; import 'package:cathaypay_mobile/GetPaid/GetPaidByAmount.dart'; import 'package:cathaypay_mobile/TopUp/TopUpMenuPage.dart'; import 'package:cathaypay_mobile/TransferMoney/transfer_history.dart'; import 'package:cathaypay_mobile/model/qrcode.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:qr_flutter/qr_flutter.dart'; import 'package:saver_gallery/saver_gallery.dart'; import '../Home/HomePage.dart'; import '../Home/home_bottom_menu_widget.dart'; import '../api/api.dart'; import '../utils/color_custom.dart'; import '../utils/utils.dart'; import 'GetPaidHistory.dart'; class GetPaidPage extends StatefulWidget { const GetPaidPage({Key? key}) : super(key: key); @override State createState() => _GetPaidPageState(); } class _GetPaidPageState extends State { bool _is_history = false; @override void initState() { initMyQr(context); super.initState(); } QrCodeModel? myQrCode; initMyQr(BuildContext context) { var param = jsonEncode({"MobileDeviceNo": profile?.phoneNumber ?? "", "Note": "myQr"}); Api.post(context, Api.myQrCode, param).then((value) => { if (value != null) {initQrCode(value)} else {} }); } initQrCode(value) { setState(() { myQrCode = QrCodeModel.fromJson(value["data"]); }); } saveQrCode() { // ImageGallerySaver.saveImage(base64Decode(myQrCode?.qrCodeImage ?? "")); String fileName = "neopay_${DateTime.now().millisecondsSinceEpoch}.jpg"; SaverGallery.saveImage(base64Decode(myQrCode?.qrCodeImage ?? ""), fileName: fileName, skipIfExists: false); Utils.showAlertDialog(context, "บันทึกสำเร็จ"); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.transparent, flexibleSpace: Image( image: AssetImage('images/home/Head.png'), fit: BoxFit.cover, ), leading: CupertinoButton( onPressed: () { Navigator.pop(context); }, child: const Icon( Icons.chevron_left, color: Colors.white, ), ), elevation: 0, title: Text( "Receive Money".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: Colors.white, fontSize: 20, ), ), ), body: Container( width: MediaQuery.of(context).size.width, child: Column( children: [ Padding( padding: const EdgeInsets.only(top: 15), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ InkWell( onTap: () { setState(() { _is_history = false; }); }, child: Column( children: [ Text( "Create Transaction".tr(), style: GoogleFonts.kanit( color: Colors.black, fontSize: 14, fontWeight: FontWeight.w300, ), ), Container( width: 63, height: 2, decoration: BoxDecoration( border: Border.all( color: _is_history ? Colors.transparent : Color(0xffd0315a), width: 2, ), ), ) ], ), ), InkWell( onTap: () { setState(() { _is_history = true; }); }, child: Column( children: [ Text( "Transaction History".tr(), style: GoogleFonts.kanit( color: Color(0xff565656), fontSize: 14, fontWeight: FontWeight.w300, ), ), Container( width: 63, height: 2, decoration: BoxDecoration( border: Border.all( color: _is_history ? Color(0xffd0315a) : Colors.transparent, width: 2, ), ), ) ], ), ), ], ), ), Divider( color: Color.fromRGBO(196, 196, 196, 1), thickness: 1, height: 1, ), _is_history ? Expanded(child: GetPaidHistory()) : Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Padding( padding: const EdgeInsets.all(20.0), child: Text( "Show QR Code to get paid".tr(), textAlign: TextAlign.justify, style: TextStyle( color: Color(0xff2d2d2d), fontSize: 20, ), ), ), Padding( padding: const EdgeInsets.only(top: 20), child: InkWell( onTap: () { // showModalBottomSheet( // context: context, // // isScrollControlled: true, // builder: (BuildContext context) { // return PayQrPage(); // }); }, child: myQrCode != null ? Container( margin: EdgeInsets.symmetric(horizontal: 15), // child: Image.memory( // base64Decode(myQrCode?.qrCodeImage ?? ""), // fit: BoxFit.fitWidth, // ), child: QrImageView( data: '${myQrCode?.qrText}|${profile?.phoneNumber}|${profile?.fullName}', version: QrVersions.auto, size: 200.0, ), ) : Container(), ), ), SizedBox( height: 30, ), Text( profile?.fullName ?? "", textAlign: TextAlign.justify, style: TextStyle( color: Color(0xff050505), fontSize: 16, ), ), SizedBox( height: 30, ), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ /*InkWell( onTap: () { showModalBottomSheet( context: context, isScrollControlled: true, useSafeArea: true, builder: (BuildContext context) { return GetPaidByAmount(); }); }, child: Container( width: 147, height: 44, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), boxShadow: [ BoxShadow( color: Color(0x19000000), blurRadius: 2, offset: Offset(0.75, 1), ), ], color: Color(0xff9d001b), ), child: Center( child: Text( "ระบุจำนวนเงิน", textAlign: TextAlign.center, style: TextStyle( color: Colors.white, fontSize: 20, ), ), ), ), ),*/ InkWell( onTap: () { saveQrCode(); }, child: SizedBox( width: 147, child: Card( color: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(40), ), child: Container( padding: EdgeInsets.all(10), child: Text( "Save QR".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: ColorCustom.greyBorder, fontSize: 20, fontWeight: FontWeight.w500, ), ), ), ), ), ), ], ) ], ), _is_history ?Container(): Expanded(child: Container()), HomeBottomMenuWidget() ], ), ), ); } }