Update: 2026-05-16 01:40:56

This commit is contained in:
Hamza-Ayed
2026-05-16 01:40:56 +03:00
parent aceb7d324f
commit 9ad361e992
4 changed files with 126 additions and 25 deletions

View File

@@ -11,6 +11,7 @@ class SubscriptionController extends GetxController {
var isLoading = true.obs;
var isCreatingPayment = false.obs;
var activePaymentRequest = Rxn<Map<String, dynamic>>();
var isAnnual = true.obs; // Toggle between Monthly and Annual
@override
void onInit() {
@@ -69,7 +70,11 @@ class SubscriptionController extends GetxController {
Future<Map<String, dynamic>?> createPaymentRequest(String planId) async {
try {
isCreatingPayment.value = true;
final res = await DioClient().client.post('payments/create', data: {'plan_id': planId});
final cycle = isAnnual.value ? 'annual' : 'monthly';
final res = await DioClient().client.post('payments/create', data: {
'plan_id': planId,
'billing_cycle': cycle,
});
if (res.data['success'] == true && res.data['data'] != null) {
final result = Map<String, dynamic>.from(res.data['data']);
activePaymentRequest.value = result;

View File

@@ -44,25 +44,93 @@ class SubscriptionView extends StatelessWidget {
// Plans Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Icon(Icons.diamond_rounded, color: Color(0xFFD4AF37), size: 22),
const SizedBox(width: 8),
Text(
'اختر باقتك',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : const Color(0xFF0F172A),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.diamond_rounded, color: Color(0xFFD4AF37), size: 22),
const SizedBox(width: 8),
Text(
'اختر باقتك',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: isDark ? Colors.white : const Color(0xFF0F172A),
),
),
],
),
const SizedBox(height: 4),
Text(
'ادفع عبر CliQ — بدون عمولة!',
style: TextStyle(fontSize: 13, color: isDark ? Colors.white38 : Colors.grey),
),
],
),
],
),
const SizedBox(height: 4),
Text(
'ادفع عبر CliQ — بدون عمولة!',
style: TextStyle(fontSize: 13, color: isDark ? Colors.white38 : Colors.grey),
const SizedBox(height: 20),
// Toggle
Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: isDark ? Colors.white.withOpacity(0.05) : Colors.black.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => controller.isAnnual.value = false,
child: Obx(() => Container(
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: !controller.isAnnual.value ? const Color(0xFF0F4C81) : Colors.transparent,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'دفع شهري',
style: TextStyle(
color: !controller.isAnnual.value ? Colors.white : (isDark ? Colors.white60 : Colors.black54),
fontWeight: FontWeight.bold,
fontSize: 13,
),
),
),
)),
),
),
Expanded(
child: GestureDetector(
onTap: () => controller.isAnnual.value = true,
child: Obx(() => Container(
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: controller.isAnnual.value ? const Color(0xFF0F4C81) : Colors.transparent,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
'دفع سنوي (توفير ✨)',
style: TextStyle(
color: controller.isAnnual.value ? Colors.white : (isDark ? Colors.white60 : Colors.black54),
fontWeight: FontWeight.bold,
fontSize: 13,
),
),
),
)),
),
),
],
),
),
const SizedBox(height: 16),
const SizedBox(height: 20),
// Plans Grid
...controller.plans.map((plan) => _buildPlanCard(plan, controller, isDark)),
@@ -228,9 +296,19 @@ class SubscriptionView extends StatelessWidget {
Widget _buildPlanCard(Map<String, dynamic> plan, SubscriptionController ctrl, bool isDark) {
final isPopular = plan['is_popular'] == true;
final price = (plan['price_jod'] ?? 0).toString();
final features = (plan['features'] as List?)?.cast<String>() ?? [];
final nameAr = plan['name_ar'] ?? plan['name_en'] ?? 'باقة';
return Obx(() {
final bool annual = ctrl.isAnnual.value;
final price = annual
? (plan['price_annual_jod'] ?? (plan['price_jod'] * 10)).toString()
: (plan['price_monthly_jod'] ?? plan['price_jod']).toString();
final features = (plan['features'] as List?)?.cast<String>() ?? [];
final invoiceLimit = annual
? (plan['max_invoices_month'] * 12).toString()
: (plan['max_invoices_month']).toString();
final cycleText = annual ? 'سنة' : 'شهر';
return Container(
margin: const EdgeInsets.only(bottom: 16),
@@ -271,7 +349,7 @@ class SubscriptionView extends StatelessWidget {
text: TextSpan(
children: [
TextSpan(text: price, style: TextStyle(fontSize: 28, fontWeight: FontWeight.w900, color: isDark ? const Color(0xFF5EEAD4) : const Color(0xFF0F4C81))),
TextSpan(text: ' JOD', style: TextStyle(fontSize: 12, color: isDark ? Colors.white38 : Colors.grey)),
TextSpan(text: ' JOD / $cycleText', style: TextStyle(fontSize: 12, color: isDark ? Colors.white38 : Colors.grey)),
],
),
),
@@ -302,7 +380,7 @@ class SubscriptionView extends StatelessWidget {
children: [
_buildPlanStat(Icons.business, '${plan['max_companies'] ?? 0} شركات'),
const SizedBox(width: 8),
_buildPlanStat(Icons.receipt_long, '${plan['max_invoices_month'] ?? 0} فاتورة/سنة'),
_buildPlanStat(Icons.receipt_long, '$invoiceLimit فاتورة/$cycleText'),
const SizedBox(width: 8),
_buildPlanStat(Icons.people, '${plan['max_users'] ?? 0} مستخدمين'),
],
@@ -338,6 +416,7 @@ class SubscriptionView extends StatelessWidget {
],
),
);
});
}
Widget _buildPlanStat(IconData icon, String text) {