Files
driver_tripz/lib/views/home/my_wallet/card_wallet_widget.dart
Hamza-Ayed 5aeb3cf685 11/17/1
2024-11-17 22:13:31 +02:00

218 lines
8.9 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../constant/box_name.dart';
import '../../../constant/colors.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 Center(
child: GetBuilder<CaptainWalletController>(
builder: (captainWalletController) {
return GestureDetector(
onTap: () async {
final now = DateTime.now();
DateTime? lastRequestTime =
box.read(BoxName.lastTimeCaptainWalletCashOut);
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(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.account_balance_wallet,
color: AppColor.primaryColor),
const SizedBox(width: 10),
Text(
'Total wallet: '.tr,
style: AppStyle.title.copyWith(fontSize: 16),
),
Text(
'${Get.find<CaptainWalletController>().totalAmountVisa} \$',
style: AppStyle.number.copyWith(fontSize: 16),
),
],
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Wallet Type: '.tr,
style: AppStyle.title.copyWith(fontSize: 16),
),
const SizedBox(width: 10),
MyDropDown1(),
],
),
const SizedBox(height: 20),
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);
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 {
// Replacing Get.snackbar with CupertinoAlertDialog
showCupertinoDialog(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text("Alert".tr),
content: Text(
'${'The Amount is less than'.tr}${box.read(BoxName.countryCode) == 'Egypt' ? '20' : '20'}',
),
actions: <Widget>[
CupertinoDialogAction(
isDefaultAction: true,
child: Text("OK".tr),
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
},
),
],
);
},
);
}
},
child: Container(
width: Get.width * .85,
height: Get.height * .22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
gradient: LinearGradient(
colors: [
AppColor.secondaryColor.withOpacity(0.85),
AppColor.primaryColor.withOpacity(0.85),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.15),
blurRadius: 10,
offset: const Offset(0, 5),
),
],
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
// '${AppInformation.appName} Wallet',
'SEFER Wallet',
style: AppStyle.headTitle.copyWith(
color: AppColor.writeColor, fontSize: 26),
),
const Icon(Icons.account_balance_wallet,
color: AppColor.writeColor, size: 24),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'${Get.find<CaptainWalletController>().totalAmountVisa} ${'L.E'.tr}' ??
'0.0 ${'L.E'.tr}',
style: AppStyle.headTitle2.copyWith(
color: AppColor.writeColor, fontSize: 28),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
box.read(BoxName.nameDriver),
style: AppStyle.title.copyWith(
color: AppColor.writeColor.withOpacity(0.9)),
),
Text(
"Cash Out".tr,
style: AppStyle.title.copyWith(
color: AppColor.writeColor.withOpacity(0.9)),
),
],
),
],
),
),
),
);
},
),
);
}
}