Files
Neo_wallet/neowallet_mobile/lib/GetPaid/GetPaidShop.dart
Manasit.K 43c32ef6cf init
2024-10-31 15:57:57 +07:00

302 lines
11 KiB
Dart

import 'dart:convert';
import 'package:cathaypay_mobile/GetPaid/GetPaidByAmount.dart';
import 'package:cathaypay_mobile/TopUp/TopUpMenuPage.dart';
import 'package:cathaypay_mobile/model/qrcode.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:qr_flutter/qr_flutter.dart';
import '../Home/HomePage.dart';
import '../api/api.dart';
import '../utils/utils.dart';
import 'GetPaidShopByAmount.dart';
class GetPaidShopPage extends StatefulWidget {
const GetPaidShopPage({Key? key}) : super(key: key);
@override
State<GetPaidShopPage> createState() => _GetPaidPageState();
}
class _GetPaidPageState extends State<GetPaidShopPage> {
bool _is_history = false;
@override
void initState() {
initMyQr(context);
super.initState();
}
QrCodeModel? myQrCode;
initMyQr(BuildContext context) {
var param = jsonEncode(<dynamic, dynamic>{
"PayerPhoneNumber": profile?.phoneNumber,
"InvoiceId": "${profile?.phoneNumber}${Utils.getTimestamp()}",
"REFERENCE1": "string",
"REFERENCE2": "string",
"REFERENCE3": "string",
"PaymentChannel": "PAYMENTC2B",
"Amount": 0,
"Note": "string"
});
Api.post(context, Api.c2bCreate, param).then((value) => {
if (value != null) {initQrCode(value)} else {}
});
}
initQrCode(value) {
setState(() {
myQrCode = QrCodeModel.fromJson(value["data"]);
});
}
saveQrCode() {
ImageGallerySaver.saveImage(base64Decode(myQrCode?.qrCodeImage ?? ""));
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(
"รับเงิน",
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(
"ทำรายการ",
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(
"ประวัติ",
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
? TopUpHistory()
: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
"แสดง QR Code เพื่อรับเงิน",
textAlign: TextAlign.justify,
style: TextStyle(
color: Color(0xff2d2d2d),
fontSize: 20,
),
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: InkWell(
onTap: () {
// showModalBottomSheet<void>(
// 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<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return GetPaidShopByAmount();
});
},
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: 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(
"บันทึก QR",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
),
),
],
)
],
),
],
),
),
);
}
}