Update: 2026-06-14 04:27:17
This commit is contained in:
@@ -5,6 +5,8 @@ import 'package:siro_driver/constant/links.dart';
|
||||
import 'package:siro_driver/controller/functions/crud.dart';
|
||||
import 'package:siro_driver/views/widgets/error_snakbar.dart';
|
||||
|
||||
import '../../views/widgets/mycircular.dart';
|
||||
|
||||
class InvitesRewardsController extends GetxController {
|
||||
bool isLoading = false;
|
||||
String? referralCode;
|
||||
@@ -23,7 +25,7 @@ class InvitesRewardsController extends GetxController {
|
||||
update();
|
||||
|
||||
var res = await CRUD().get(link: AppLink.getDriverReferrals);
|
||||
|
||||
|
||||
if (res != 'failure' && res != 'token_expired' && res != 'no_internet') {
|
||||
try {
|
||||
var jsonData = jsonDecode(res);
|
||||
@@ -44,8 +46,9 @@ class InvitesRewardsController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> claimReward(int referralId, String claimType) async {
|
||||
Get.dialog(const Center(child: CircularProgressIndicator()), barrierDismissible: false);
|
||||
|
||||
Get.dialog(const Center(child: CircularProgressIndicator()),
|
||||
barrierDismissible: false);
|
||||
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.claimDriverReward,
|
||||
payload: {
|
||||
@@ -76,28 +79,58 @@ class InvitesRewardsController extends GetxController {
|
||||
Future<void> claimUnifiedReward(int referralId) async {
|
||||
// Show dialog to choose wallet or cash
|
||||
Get.defaultDialog(
|
||||
title: "Choose Claim Method".tr,
|
||||
content: Text("How would you like to receive your reward?".tr),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
claimReward(referralId, 'wallet');
|
||||
},
|
||||
child: Text("Wallet".tr),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
claimReward(referralId, 'cash');
|
||||
},
|
||||
child: Text("Cash".tr),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: Text("Cancel".tr, style: TextStyle(color: Colors.red)),
|
||||
)
|
||||
]
|
||||
);
|
||||
title: "Choose Claim Method".tr,
|
||||
content: Text("How would you like to receive your reward?".tr),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
claimReward(referralId, 'wallet');
|
||||
},
|
||||
child: Text("Wallet".tr),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
claimReward(referralId, 'cash');
|
||||
},
|
||||
child: Text("Cash".tr),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: Text("Cancel".tr, style: TextStyle(color: Colors.red)),
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> linkInviteCode(String inviteCode) async {
|
||||
Get.dialog(const Center(child: MyCircularProgressIndicator()),
|
||||
barrierDismissible: false);
|
||||
|
||||
try {
|
||||
var response =
|
||||
await CRUD().post(link: AppLink.addUnifiedInvite, payload: {
|
||||
"inviter_code": inviteCode,
|
||||
});
|
||||
|
||||
Get.back(); // close loading
|
||||
|
||||
if (response != 'failure') {
|
||||
var data = response is String ? jsonDecode(response) : response;
|
||||
if (data['status'] == 'success') {
|
||||
Get.snackbar("Success".tr, "You have been successfully referred!".tr,
|
||||
backgroundColor: Colors.green, colorText: Colors.white);
|
||||
await getReferralStats(); // Refresh stats
|
||||
} else {
|
||||
Get.snackbar(
|
||||
"Notice".tr, data['message'] ?? "Could not add invite".tr);
|
||||
}
|
||||
} else {
|
||||
Get.snackbar("Error".tr, "Network error occurred".tr);
|
||||
}
|
||||
} catch (e) {
|
||||
Get.back(); // close loading
|
||||
Get.snackbar("Error".tr, "Network error occurred".tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user