Update: 2026-08-08 16:55:39

This commit is contained in:
Hamza-Ayed
2026-08-08 16:55:39 +03:00
parent dd44b84e81
commit 8c9f729ecd
27 changed files with 2030 additions and 1798 deletions
@@ -3,6 +3,7 @@ import 'package:get/get.dart';
import '../../../constant/colors.dart';
import '../../../controller/insurance/driver_insurance_controller.dart';
import '../../widgets/ui/siro_ui.dart';
/// شاشة التأمين: الوثيقة النشطة ودفترها، أو الخطط المتاحة.
///
@@ -16,18 +17,20 @@ class DriverInsurancePage extends StatelessWidget {
Widget build(BuildContext context) {
final c = Get.put(DriverInsuranceController());
return Scaffold(
appBar: AppBar(title: Text('Insurance'.tr), centerTitle: true),
return SiroPage(
title: 'Insurance'.tr,
body: Obx(() {
if (c.isLoading.value) {
return const Center(child: CircularProgressIndicator());
return const SiroLoading();
}
return RefreshIndicator(
onRefresh: c.refreshAll,
color: SiroUi.interactive(context),
child: ListView(
padding: const EdgeInsets.all(16),
children: c.hasPolicy ? _policyView(context, c) : _plansView(context, c),
padding: SiroUi.pageInsets,
children:
c.hasPolicy ? _policyView(context, c) : _plansView(context, c),
),
);
}),
@@ -39,29 +42,34 @@ class DriverInsurancePage extends StatelessWidget {
final p = c.policy.value!;
return [
Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
SiroCard(
accent: AppColor.greenColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.verified_user, color: Colors.green),
const SizedBox(width: 8),
const SiroIconBadge(Icons.verified_user_rounded,
color: AppColor.greenColor),
const SizedBox(width: 10),
Expanded(
child: Text(
'${p['plan'] ?? ''}',
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.bold),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${p['plan'] ?? ''}',
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(fontWeight: FontWeight.bold),
),
Text('${p['provider'] ?? ''}',
style: Theme.of(context).textTheme.bodySmall),
],
),
),
],
),
const SizedBox(height: 4),
Text('${p['provider'] ?? ''}',
style: TextStyle(color: Colors.grey.shade600)),
const Divider(height: 24),
_row('Premium'.tr,
'${p['premium']} ${p['currency']} / '
@@ -72,28 +80,25 @@ class DriverInsurancePage extends StatelessWidget {
if ((p['coverage'] ?? '').toString().isNotEmpty) ...[
const SizedBox(height: 12),
Text('${p['coverage']}',
style: TextStyle(color: Colors.grey.shade700)),
style: Theme.of(context).textTheme.bodySmall),
],
],
),
),
),
const SizedBox(height: 16),
// ── دفتر الأقساط ──
// يظهر في نفس الشاشة لا في أخرى: الخصم الذي لا يرى السائق مقابله
// مفاجأة تُفقد الثقة، مهما كان مشروحاً في مكان آخر.
Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
SiroCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Premium ledger'.tr,
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(height: 8),
_row('Outstanding'.tr,
'${c.pendingTotal.toStringAsFixed(2)} ${c.currency}'),
_row('Settled'.tr,
@@ -106,13 +111,13 @@ class DriverInsurancePage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('${e['charge_date']}',
style: TextStyle(color: Colors.grey.shade700)),
style: Theme.of(context).textTheme.bodySmall),
Text('${e['amount']} ${e['currency']}',
style: TextStyle(
color: e['status'] == 'settled'
? Colors.green
: Colors.orange.shade800,
fontWeight: FontWeight.w600,
? AppColor.greenColor
: AppColor.yellowColor,
fontWeight: FontWeight.w700,
)),
],
),
@@ -120,20 +125,21 @@ class DriverInsurancePage extends StatelessWidget {
],
],
),
),
),
const SizedBox(height: 24),
const SizedBox(height: 12),
OutlinedButton.icon(
onPressed: c.isSubmitting.value ? null : () => _confirmCancel(context, c),
icon: const Icon(Icons.cancel_outlined, color: Colors.red),
label: Text('Cancel policy'.tr,
style: const TextStyle(color: Colors.red)),
onPressed:
c.isSubmitting.value ? null : () => _confirmCancel(context, c),
icon: const Icon(Icons.cancel_outlined, size: 18),
label: Text('Cancel policy'.tr),
style: OutlinedButton.styleFrom(
side: const BorderSide(color: Colors.red),
foregroundColor: AppColor.redColor,
side: const BorderSide(color: AppColor.redColor),
minimumSize: const Size.fromHeight(48),
),
),
const SizedBox(height: 16),
];
}
@@ -144,34 +150,15 @@ class DriverInsurancePage extends StatelessWidget {
// ‏الحالة الحقيقية: لا خطط مُفعّلة بعد لدى الشركاء — لا خطأ ولا
// ‏نقص أهلية — ونقولها صراحة حتى لا يظن الكابتن أن التطبيق خربان.
return [
const SizedBox(height: 72),
Icon(Icons.health_and_safety_outlined,
size: 80, color: Colors.grey.shade400),
const SizedBox(height: 16),
Text('No insurance plans available yet'.tr,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
color: Colors.grey)),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(
'Insurance plans have not been launched in your area yet. Once a partner plan is available it will appear here automatically.'
.tr,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14, height: 1.5, color: Colors.grey.shade600),
),
),
const SizedBox(height: 20),
Center(
child: TextButton.icon(
onPressed: c.isLoading.value ? null : () => c.refreshAll(),
icon: const Icon(Icons.refresh_rounded, size: 18),
label: Text('Refresh'.tr),
),
const SizedBox(height: 48),
SiroEmptyState(
icon: Icons.health_and_safety_outlined,
title: 'No insurance plans available yet'.tr,
message:
'Insurance plans have not been launched in your area yet. Once a partner plan is available it will appear here automatically.'
.tr,
actionLabel: 'Refresh'.tr,
onAction: c.isLoading.value ? null : () => c.refreshAll(),
),
];
}
@@ -182,46 +169,58 @@ class DriverInsurancePage extends StatelessWidget {
final progress = (plan['progress_rides'] ?? 0) as num;
final required = (plan['required_rides'] ?? 0) as num;
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
margin: const EdgeInsets.only(bottom: 16),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
return SiroCard(
accent: eligible ? AppColor.greenColor : null,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('${plan['name'] ?? ''}',
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.bold)),
Row(
children: [
Expanded(
child: Text('${plan['name'] ?? ''}',
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(fontWeight: FontWeight.bold)),
),
if (eligible)
SiroTag('Eligible'.tr,
color: AppColor.greenColor,
icon: Icons.check_circle_rounded),
],
),
Text('${plan['provider'] ?? ''}',
style: TextStyle(color: Colors.grey.shade600)),
style: Theme.of(context).textTheme.bodySmall),
const SizedBox(height: 8),
Text(
'${plan['premium']} ${plan['currency']} / '
'${plan['billing_cycle'] == 'monthly' ? 'Monthly'.tr : 'Daily'.tr}',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: AppColor.primaryColor),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
color: SiroUi.interactive(context),
),
),
if ((plan['coverage'] ?? '').toString().isNotEmpty) ...[
const SizedBox(height: 8),
Text('${plan['coverage']}',
style: TextStyle(color: Colors.grey.shade700)),
style: Theme.of(context).textTheme.bodySmall),
],
// شريط التقدّم نحو الشرط — الرقم وحده لا يحرّك أحداً،
// ورؤية القرب من الهدف تفعل.
if (!eligible && required > 0) ...[
const SizedBox(height: 12),
LinearProgressIndicator(
value: required == 0 ? 0 : (progress / required).clamp(0, 1),
backgroundColor: Colors.grey.shade300,
ClipRRect(
borderRadius: BorderRadius.circular(999),
child: LinearProgressIndicator(
minHeight: 7,
value: required == 0 ? 0 : (progress / required).clamp(0, 1),
backgroundColor: SiroUi.border(context),
),
),
const SizedBox(height: 6),
Text('$progress / $required ${'rides'.tr}',
style: TextStyle(
fontSize: 12, color: Colors.grey.shade600)),
style: Theme.of(context).textTheme.bodySmall),
],
if (!eligible && missing.isNotEmpty) ...[
@@ -230,33 +229,31 @@ class DriverInsurancePage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Icon(Icons.lock_outline,
size: 14, color: Colors.orange),
size: 14, color: AppColor.yellowColor),
const SizedBox(width: 6),
Expanded(
child: Text('$m',
style: TextStyle(
style: const TextStyle(
fontSize: 12,
color: Colors.orange.shade900)),
color: AppColor.yellowColor)),
),
],
)),
],
const SizedBox(height: 12),
ElevatedButton(
onPressed: (!eligible || c.isSubmitting.value)
? null
: () => c.subscribe(plan['id'] as int),
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.primaryColor,
foregroundColor: Colors.white,
minimumSize: const Size.fromHeight(44),
const SizedBox(height: 14),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: (!eligible || c.isSubmitting.value)
? null
: () => c.subscribe(plan['id'] as int),
child:
Text(eligible ? 'Subscribe'.tr : 'Not eligible yet'.tr),
),
child: Text(eligible ? 'Subscribe'.tr : 'Not eligible yet'.tr),
),
],
),
),
);
}).toList();
}
@@ -283,7 +280,7 @@ class DriverInsurancePage extends StatelessWidget {
c.cancel();
},
child: Text('Confirm'.tr,
style: const TextStyle(color: Colors.red)),
style: const TextStyle(color: AppColor.redColor)),
),
],
),
@@ -293,18 +290,6 @@ class DriverInsurancePage extends StatelessWidget {
static String ledgerNum(dynamic v) =>
(double.tryParse('${v ?? 0}') ?? 0).toStringAsFixed(2);
Widget _row(String label, String value) => Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: TextStyle(color: Colors.grey.shade700)),
Flexible(
child: Text(value,
textAlign: TextAlign.end,
style: const TextStyle(fontWeight: FontWeight.w600)),
),
],
),
);
Widget _row(String label, String value) =>
SiroDetailRow(label: label, value: value);
}