551 lines
19 KiB
Dart
551 lines
19 KiB
Dart
import 'package:siro_admin/constant/theme.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:siro_admin/constant/links.dart';
|
|
import 'package:siro_admin/controller/employee_controller/employee_controller.dart';
|
|
import 'package:siro_admin/controller/functions/upload_image copy.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class EmployeePage extends StatelessWidget {
|
|
const EmployeePage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Get.put(EmployeeController());
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
body: GetBuilder<EmployeeController>(
|
|
builder: (controller) {
|
|
return CustomScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
slivers: [
|
|
SliverAppBar(
|
|
expandedHeight: 100,
|
|
floating: true,
|
|
pinned: true,
|
|
backgroundColor: cs.surface,
|
|
elevation: 0,
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
titlePadding: const EdgeInsets.only(bottom: 16),
|
|
title: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: cs.primary.withValues(alpha: 0.2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(Icons.badge_rounded,
|
|
color: cs.onSurface, size: 18),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Text(
|
|
'الموظفون',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
color: cs.onSurface,
|
|
fontFamily: 'Segoe UI',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
centerTitle: true,
|
|
background: Container(
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
cs.primary.withValues(alpha: 0.15),
|
|
cs.surface,
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
if (controller.employee.isEmpty)
|
|
SliverFillRemaining(
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.people_outline,
|
|
size: 60, color: cs.onSurface.withValues(alpha: 0.24)),
|
|
const SizedBox(height: 16),
|
|
Text("لا يوجد موظفين حالياً",
|
|
style: TextStyle(color: cs.onSurfaceVariant)),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
else
|
|
SliverPadding(
|
|
padding: const EdgeInsets.all(16),
|
|
sliver: SliverList(
|
|
delegate: SliverChildBuilderDelegate(
|
|
(context, index) {
|
|
final employee = controller.employee[index];
|
|
return _EmployeeCard(
|
|
employee: employee,
|
|
index: index,
|
|
cs: cs,
|
|
);
|
|
},
|
|
childCount: controller.employee.length,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
final controller = Get.find<EmployeeController>();
|
|
controller.id = controller.generateRandomId(8);
|
|
Get.to(() => _EmployeeFormScreen(controller: controller));
|
|
},
|
|
backgroundColor: cs.primary,
|
|
child: Icon(Icons.person_add_rounded, color: cs.onPrimary),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EmployeeCard extends StatelessWidget {
|
|
final Map<String, dynamic> employee;
|
|
final int index;
|
|
final ColorScheme cs;
|
|
|
|
const _EmployeeCard({
|
|
required this.employee,
|
|
required this.index,
|
|
required this.cs,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
bool isExcellent = employee['status'].toString().contains('ممتاز');
|
|
Color statusColor = isExcellent ? cs.success : cs.warning;
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: cs.outline.withValues(alpha: 0.1)),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: cs.shadow.withValues(alpha: 0.2),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: () => Get.to(() => EmployeeDetails(index: index)),
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: cs.outline.withValues(alpha: 0.1),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(Icons.person,
|
|
color: cs.onSurface.withValues(alpha: 0.7), size: 20),
|
|
),
|
|
Flexible(
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 10, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: statusColor.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(8),
|
|
border:
|
|
Border.all(color: statusColor.withValues(alpha: 0.3)),
|
|
),
|
|
child: Text(
|
|
employee['status'] ?? 'Unknown',
|
|
style: TextStyle(
|
|
color: statusColor,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
height: 1.5,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
Text(
|
|
employee['name'] ?? 'Unknown',
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
height: 1.3,
|
|
),
|
|
),
|
|
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
child: Divider(height: 1, color: cs.outline.withValues(alpha: 0.1)),
|
|
),
|
|
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildInfoRow(Icons.phone_iphone_rounded,
|
|
employee['phone'] ?? '', cs.onSurfaceVariant, cs),
|
|
const SizedBox(height: 12),
|
|
_buildInfoRow(
|
|
Icons.school_outlined,
|
|
employee['education'] ?? 'غير محدد',
|
|
cs.primary, cs),
|
|
const SizedBox(height: 12),
|
|
_buildInfoRow(Icons.location_on_outlined,
|
|
employee['site'] ?? 'غير محدد', cs.onSurfaceVariant, cs),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
Material(
|
|
color: cs.success.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: InkWell(
|
|
onTap: () =>
|
|
_makePhoneCall(employee['phone'].toString()),
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(14),
|
|
child: Icon(Icons.call,
|
|
color: cs.success, size: 24),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoRow(IconData icon, String text, Color iconColor, ColorScheme cs) {
|
|
return Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 2),
|
|
child: Icon(icon, size: 16, color: iconColor.withValues(alpha: 0.8)),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Text(
|
|
text,
|
|
style: TextStyle(
|
|
color: cs.onSurface.withValues(alpha: 0.7),
|
|
fontSize: 13,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<void> _makePhoneCall(String phoneNumber) async {
|
|
final Uri launchUri = Uri(scheme: 'tel', path: phoneNumber);
|
|
if (await canLaunchUrl(launchUri)) {
|
|
await launchUrl(launchUri);
|
|
}
|
|
}
|
|
}
|
|
|
|
class _EmployeeFormScreen extends StatelessWidget {
|
|
final EmployeeController controller;
|
|
const _EmployeeFormScreen({required this.controller});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
appBar: AppBar(
|
|
title: Text("إضافة موظف جديد",
|
|
style: TextStyle(color: cs.onSurface)),
|
|
backgroundColor: cs.surface,
|
|
elevation: 0,
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back, color: cs.onSurface),
|
|
onPressed: () => Get.back(),
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Form(
|
|
key: controller.formKey,
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: _UploadButton(
|
|
title: "الهوية (أمام)",
|
|
icon: Icons.credit_card,
|
|
cs: cs,
|
|
onPressed: () async {
|
|
await ImageController().choosImage(AppLink.uploadEgypt,
|
|
'idFrontEmployee', controller.id);
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: _UploadButton(
|
|
title: "الهوية (خلف)",
|
|
icon: Icons.credit_card_outlined,
|
|
cs: cs,
|
|
onPressed: () async {
|
|
await ImageController().choosImage(AppLink.uploadEgypt,
|
|
'idbackEmployee', controller.id);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 24),
|
|
_buildModernTextField(
|
|
controller.name, "الاسم الكامل", Icons.person, cs),
|
|
const SizedBox(height: 16),
|
|
_buildModernTextField(
|
|
controller.phone, "رقم الهاتف", Icons.phone, cs,
|
|
type: TextInputType.phone),
|
|
const SizedBox(height: 16),
|
|
_buildModernTextField(controller.education, "التعليم / الملاحظات",
|
|
Icons.school, cs),
|
|
const SizedBox(height: 16),
|
|
_buildModernTextField(controller.site, "الموقع / العنوان",
|
|
Icons.location_on, cs),
|
|
const SizedBox(height: 16),
|
|
_buildModernTextField(controller.status, "الحالة (مثال: ممتاز)",
|
|
Icons.star, cs),
|
|
const SizedBox(height: 32),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
onPressed: () async {
|
|
if (controller.formKey.currentState!.validate()) {
|
|
await controller.addEmployee();
|
|
Get.back();
|
|
}
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: cs.primary,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
),
|
|
child: Text("حفظ البيانات",
|
|
style: TextStyle(
|
|
color: cs.onPrimary,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildModernTextField(TextEditingController controller, String hint,
|
|
IconData icon, ColorScheme cs,
|
|
{TextInputType type = TextInputType.text}) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: cs.outline.withValues(alpha: 0.1)),
|
|
),
|
|
child: TextFormField(
|
|
controller: controller,
|
|
keyboardType: type,
|
|
style: TextStyle(color: cs.onSurface),
|
|
maxLines: null,
|
|
decoration: InputDecoration(
|
|
labelText: hint,
|
|
labelStyle: TextStyle(color: cs.onSurface.withValues(alpha: 0.5)),
|
|
prefixIcon: Icon(icon, color: cs.onSurfaceVariant, size: 20),
|
|
border: InputBorder.none,
|
|
contentPadding:
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
|
),
|
|
validator: (value) =>
|
|
value == null || value.isEmpty ? 'حقل مطلوب' : null,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _UploadButton extends StatelessWidget {
|
|
final String title;
|
|
final IconData icon;
|
|
final VoidCallback onPressed;
|
|
final ColorScheme cs;
|
|
|
|
const _UploadButton(
|
|
{required this.title, required this.icon, required this.onPressed, required this.cs});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
onTap: onPressed,
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 20),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: cs.primary.withValues(alpha: 0.3),
|
|
style: BorderStyle.solid),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Icon(icon, color: cs.primary, size: 30),
|
|
const SizedBox(height: 8),
|
|
Text(title,
|
|
style: TextStyle(color: cs.onSurface.withValues(alpha: 0.7), fontSize: 12)),
|
|
const SizedBox(height: 4),
|
|
Text("اضغط للرفع",
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 10)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class EmployeeDetails extends StatelessWidget {
|
|
final int index;
|
|
const EmployeeDetails({super.key, required this.index});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
appBar: AppBar(
|
|
title:
|
|
Text('تفاصيل الموظف', style: TextStyle(color: cs.onSurface)),
|
|
backgroundColor: cs.surface,
|
|
iconTheme: IconThemeData(color: cs.onSurface),
|
|
elevation: 0,
|
|
),
|
|
body: GetBuilder<EmployeeController>(
|
|
builder: (controller) {
|
|
final employeeId = controller.employee[index]['id'];
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text("الهوية الأمامية",
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 10),
|
|
_buildImageViewer(
|
|
'${AppLink.server}/card_image/idFrontEmployee-$employeeId.jpg',
|
|
cs,
|
|
),
|
|
const SizedBox(height: 30),
|
|
Text("الهوية الخلفية",
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 10),
|
|
_buildImageViewer(
|
|
'${AppLink.server}/card_image/idbackEmployee-$employeeId.jpg',
|
|
cs,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildImageViewer(String url, ColorScheme cs) {
|
|
return Container(
|
|
width: double.infinity,
|
|
height: 220,
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: cs.outline.withValues(alpha: 0.1)),
|
|
),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: Image.network(
|
|
url,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.broken_image_rounded,
|
|
color: cs.onSurface.withValues(alpha: 0.24), size: 50),
|
|
const SizedBox(height: 8),
|
|
Text("فشل تحميل الصورة",
|
|
style: TextStyle(color: cs.onSurface.withValues(alpha: 0.24))),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
loadingBuilder: (context, child, loadingProgress) {
|
|
if (loadingProgress == null) return child;
|
|
return Center(
|
|
child: CircularProgressIndicator(color: cs.primary));
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|