Initial commit for intaleq_admin
This commit is contained in:
@@ -1,223 +1,302 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
// تأكد من استيراد مكتبة الاتصال إذا أردت تفعيل زر الاتصال فعلياً
|
||||
// import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../constant/colors.dart';
|
||||
import '../../../constant/style.dart';
|
||||
import '../../../controller/admin/captain_admin_controller.dart';
|
||||
import '../../../controller/functions/encrypt_decrypt.dart';
|
||||
import '../../widgets/elevated_btn.dart';
|
||||
import '../../../constant/box_name.dart';
|
||||
import '../../../controller/functions/launch.dart';
|
||||
import '../../../main.dart';
|
||||
import '../../widgets/my_scafold.dart';
|
||||
import '../../widgets/my_textField.dart';
|
||||
import '../../widgets/mycircular.dart';
|
||||
import '../../../constant/style.dart';
|
||||
import '../../../controller/admin/captain_admin_controller.dart';
|
||||
import 'captain_details.dart';
|
||||
import 'form_captain.dart';
|
||||
|
||||
class Captain extends StatelessWidget {
|
||||
Captain({super.key});
|
||||
final CaptainAdminController captainAdminController =
|
||||
class CaptainsPage extends StatelessWidget {
|
||||
CaptainsPage({super.key});
|
||||
|
||||
final CaptainAdminController captainController =
|
||||
Get.put(CaptainAdminController());
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
|
||||
// 🔴 هام جداً: قم بتغيير هذا المتغير بناءً على حالة تسجيل الدخول الحقيقية في تطبيقك
|
||||
// مثال: bool isAdmin = Get.find<AuthController>().isAdmin;
|
||||
// final bool isAdmin = true; // اجعلها false لتجربة وضع المستخدم العادي
|
||||
String myPhone = box.read(BoxName.adminPhone).toString();
|
||||
|
||||
// 2. تحديد من هو "السوبر أدمن" الذي يرى كل شيء
|
||||
// يمكنك إضافة المزيد من الأرقام هنا باستخدام || أو قائمة
|
||||
bool isSuperAdmin = false;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
isSuperAdmin = myPhone == '963942542053' || myPhone == '963992952235';
|
||||
|
||||
return MyScafolld(
|
||||
title: 'Captain'.tr,
|
||||
body: [
|
||||
GetBuilder<CaptainAdminController>(
|
||||
builder: (captainAdminController) => Column(
|
||||
children: [
|
||||
captainAdminController.isLoading
|
||||
? const MyCircularProgressIndicator()
|
||||
: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
captainAdmin(
|
||||
captainAdminController,
|
||||
'Captains Count',
|
||||
'countPassenger',
|
||||
),
|
||||
MyElevatedButton(
|
||||
title: 'Add Prize to Gold Captains',
|
||||
onPressed: () {
|
||||
var date = DateTime.now();
|
||||
var day = date.weekday;
|
||||
|
||||
if (day == 6) {
|
||||
// Saturday is 6
|
||||
Get.defaultDialog(
|
||||
title:
|
||||
'Add Prize to Gold Captains',
|
||||
titleStyle: AppStyle.title,
|
||||
content: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Add Points to their wallet as prize'
|
||||
.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Form(
|
||||
key: captainAdminController
|
||||
.formCaptainPrizeKey,
|
||||
child: MyTextForm(
|
||||
controller:
|
||||
captainAdminController
|
||||
.captainPrizeController,
|
||||
label:
|
||||
'Count of prize'
|
||||
.tr,
|
||||
hint: 'Count of prize'
|
||||
.tr,
|
||||
type: TextInputType
|
||||
.number))
|
||||
],
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Add',
|
||||
onPressed: () async {
|
||||
if (captainAdminController
|
||||
.formCaptainPrizeKey
|
||||
.currentState!
|
||||
.validate()) {
|
||||
captainAdminController
|
||||
.addCaptainsPrizeToWalletSecure();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title:
|
||||
'This day is not allowed',
|
||||
titleStyle: AppStyle.title,
|
||||
middleText:
|
||||
'Saturday only Allowed day',
|
||||
middleTextStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
//todo search
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(3),
|
||||
child: Container(
|
||||
width: Get.width,
|
||||
height: 110,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
width: 2,
|
||||
color: AppColor.greenColor)),
|
||||
child: formSearchCaptain()
|
||||
// ],
|
||||
// ),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: Get.height * .5,
|
||||
child: ListView.builder(
|
||||
itemCount: captainAdminController
|
||||
.captainData['message'].length,
|
||||
itemBuilder: (context, index) {
|
||||
final user = captainAdminController
|
||||
.captainData['message'][index];
|
||||
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Get.to(const CaptainsDetailsPage(),
|
||||
arguments: {
|
||||
'data': user,
|
||||
});
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(3),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(width: 2)),
|
||||
child: ListTile(
|
||||
title: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment
|
||||
.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Name : ${(user['first_name'])} ${(user['last_name'])}',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
'Rating : ${user['ratingPassenger']}',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment
|
||||
.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Count Trip : ${user['countPassengerRide']}',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
'Count Driver Rate : ${user['countDriverRate']}',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
))
|
||||
],
|
||||
title: 'Search for Captain'.tr,
|
||||
isleading: true,
|
||||
body: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height, // لضمان أخذ المساحة
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// --- شريط البحث المحسن ---
|
||||
_buildSearchSection(context),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// --- قائمة النتائج ---
|
||||
Expanded(
|
||||
child: GetBuilder<CaptainAdminController>(
|
||||
builder: (controller) {
|
||||
if (controller.isLoading) {
|
||||
return const Center(child: MyCircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (controller.captainData['message'] == null ||
|
||||
controller.captainData['message'].isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
itemCount: controller.captainData['message'].length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) {
|
||||
final captain =
|
||||
controller.captainData['message'][index];
|
||||
return _buildCaptainCard(context, captain);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
// مساحة إضافية في الأسفل لتجنب تداخل المحتوى مع الحواف
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Container captainAdmin(CaptainAdminController captainAdminController,
|
||||
String title, String jsonField) {
|
||||
// --- ودجت البحث ---
|
||||
Widget _buildSearchSection(BuildContext context) {
|
||||
return Container(
|
||||
height: Get.height * .1,
|
||||
decoration: BoxDecoration(border: Border.all(width: 2)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
title.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
captainAdminController.captainData['message'][0][jsonField]
|
||||
.toString(),
|
||||
style: AppStyle.title,
|
||||
),
|
||||
],
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: MyTextForm(
|
||||
controller: searchController,
|
||||
label: 'Captain Phone Number'.tr,
|
||||
hint: 'Enter phone number...'.tr,
|
||||
type: TextInputType.phone,
|
||||
// يمكنك إزالة الحواف من الـ TextField الأصلي إذا أردت ليتناسب مع الكونتينر
|
||||
),
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).primaryColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.search, size: 28, color: Colors.white),
|
||||
onPressed: () {
|
||||
final phone = searchController.text;
|
||||
if (phone.isNotEmpty) {
|
||||
captainController.find_driver_by_phone(phone);
|
||||
} else {
|
||||
Get.snackbar(
|
||||
'Error'.tr,
|
||||
'Please enter a phone number to search.'.tr,
|
||||
backgroundColor: Colors.red.withOpacity(0.8),
|
||||
colorText: Colors.white,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- بطاقة الكابتن المحسنة ---
|
||||
Widget _buildCaptainCard(BuildContext context, dynamic captain) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.08),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
border: Border.all(color: Colors.grey.withOpacity(0.1)),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: () {
|
||||
Get.to(() => const CaptainDetailsPage(),
|
||||
arguments: {'data': captain});
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// صورة الكابتن أو أيقونة
|
||||
CircleAvatar(
|
||||
radius: 28,
|
||||
backgroundColor:
|
||||
Theme.of(context).primaryColor.withOpacity(0.1),
|
||||
child: Icon(
|
||||
Icons.person,
|
||||
color: Theme.of(context).primaryColor,
|
||||
size: 30,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
|
||||
// المعلومات النصية
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// الاسم
|
||||
Text(
|
||||
'${captain['first_name']} ${captain['last_name']}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// رقم الهاتف (مع المنطق)
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.phone_iphone,
|
||||
size: 14, color: Colors.grey[600]),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
_formatPhoneNumber(captain['phone'].toString()),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey[700],
|
||||
fontFamily:
|
||||
'monospace', // لجعل الأرقام والنجوم متناسقة
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// الإيميل (يظهر فقط للأدمن)
|
||||
if (isSuperAdmin && captain['email'] != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.email_outlined,
|
||||
size: 14, color: Colors.grey[600]),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
captain['email'],
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// أزرار الإجراءات
|
||||
Column(
|
||||
children: [
|
||||
// زر الاتصال (فقط للأدمن)
|
||||
if (isSuperAdmin)
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// منطق الاتصال
|
||||
makePhoneCall('+' + captain['phone']);
|
||||
// Get.snackbar(
|
||||
// 'Call', 'Calling ${captain['phone']}...');
|
||||
},
|
||||
icon: const Icon(Icons.call, color: Colors.green),
|
||||
tooltip: 'Call Captain',
|
||||
),
|
||||
|
||||
if (!isSuperAdmin)
|
||||
const Icon(Icons.arrow_forward_ios,
|
||||
size: 16, color: Colors.grey),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- دالة تنسيق الرقم (المنطق المطلوب) ---
|
||||
String _formatPhoneNumber(String phone) {
|
||||
if (isSuperAdmin) {
|
||||
return phone; // للأدمن: إظهار الرقم كاملاً
|
||||
} else {
|
||||
// للمستخدم العادي: إظهار آخر 4 أرقام فقط
|
||||
if (phone.length <= 4) return phone;
|
||||
String lastFour = phone.substring(phone.length - 4);
|
||||
String maskedPart = '*' * (phone.length - 4);
|
||||
return '$maskedPart$lastFour'; // النتيجة: *******1234
|
||||
}
|
||||
}
|
||||
|
||||
// --- تصميم الحالة الفارغة ---
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.search_off_rounded, size: 80, color: Colors.grey[300]),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
'No captains found.'.tr,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey[500],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user