Files
driver_tripz/lib/views/home/my_wallet/card_wallet_widget.dart
Hamza-Ayed bdb910f3c2 7/20/1
2024-07-20 14:18:06 +03:00

208 lines
8.3 KiB
Dart

import 'package:SEFER/print.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../constant/info.dart';
import '../../../constant/style.dart';
import '../../../controller/home/payment/captain_wallet_controller.dart';
import '../../../controller/home/payment/paymob_payout.dart';
import '../../../main.dart';
import '../../widgets/elevated_btn.dart';
import '../../widgets/my_textField.dart';
import 'walet_captain.dart';
class CardSeferWalletDriver extends StatelessWidget {
const CardSeferWalletDriver({
super.key,
});
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GetBuilder<CaptainWalletController>(builder: (captainWalletController) {
return InkWell(
onTap: () async {
final now = DateTime.now();
DateTime? lastRequestTime =
box.read(BoxName.lastTimeCaptainWalletCashOut);
// if (lastRequestTime == null ||
// now.difference(lastRequestTime).inHours >= 24) {
// // Update the last request time to now
// lastRequestTime = now;
// await box.write(
// BoxName.lastTimeCaptainWalletCashOut, lastRequestTime);
// box.write(BoxName.cvvCode, 1111);
if (double.parse(
Get.find<CaptainWalletController>().totalAmountVisa) >=
20) {
Get.defaultDialog(
barrierDismissible: false,
title: 'Do you want to collect your earnings?'.tr,
titleStyle: AppStyle.title,
content: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Total wallet is '.tr,
style: AppStyle.title,
),
const SizedBox(
width: 5,
),
Text(
Get.find<CaptainWalletController>()
.totalAmountVisa,
style: AppStyle.number,
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Wallet Type'.tr,
style: AppStyle.title,
),
const SizedBox(
width: 5,
),
MyDropDown1(),
],
),
Form(
key: captainWalletController.formKey,
child: MyTextForm(
controller: captainWalletController.phoneWallet,
label: "Enter your wallet number".tr,
hint: "Enter your wallet number".tr,
type: TextInputType.phone,
),
)
],
),
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () async {
if (captainWalletController.formKey.currentState!
.validate()) {
if (double.parse(Get.find<CaptainWalletController>()
.totalAmountVisa) >=
20) {
Get.back();
String amountAfter5LE = (double.parse(
Get.find<CaptainWalletController>()
.totalAmountVisa) -
5)
.toStringAsFixed(0);
// .dropdownValue
// .toString());
// .toString());
await Get.put(PaymobPayout()).payToWalletDriverAll(
amountAfter5LE,
Get.find<PaymobPayout>().dropdownValue.toString(),
captainWalletController.phoneWallet.text
.toString(),
);
} else {
Get.snackbar(
'${'The Amount is less than'.tr}${box.read(BoxName.countryCode) == 'Egypt' ? '100' : '20'}',
'',
backgroundColor: AppColor.yellowColor);
}
}
},
kolor: AppColor.greenColor,
),
cancel: MyElevatedButton(
title: 'cancel'.tr,
onPressed: () {
Get.back();
},
kolor: AppColor.redColor,
));
} else {
{
Get.snackbar(
'${'The Amount is less than'.tr}${box.read(BoxName.countryCode) == 'Egypt' ? '20' : '20'}',
'',
backgroundColor: AppColor.yellowColor);
}
}
// } else {
// // Optionally show a message or handle the throttling case
// final hoursLeft = 24 - now.difference(lastRequestTime).inHours;
// Get.snackbar(
// '${'Please wait'.tr} $hoursLeft ${"hours before trying again.".tr}',
// '');
// }
},
child: Container(
width: Get.width * .85,
height: Get.height * .27,
decoration: BoxDecoration(
color: AppColor.deepPurpleAccent,
borderRadius: const BorderRadius.all(Radius.circular(12)),
gradient: const LinearGradient(
colors: [AppColor.greyColor, AppColor.writeColor]),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
'${AppInformation.appName} Wallet',
style: AppStyle.headTitle
.copyWith(color: AppColor.writeColor),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'${Get.find<CaptainWalletController>().totalAmountVisa}\$' ??
'0.0 \$',
style: AppStyle.headTitle2,
)
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
box.read(BoxName.nameDriver),
style: AppStyle.title,
),
Text(
"Cash Out".tr,
style: AppStyle.title,
)
],
),
)
],
),
),
);
}),
],
);
}
}