144 lines
5.2 KiB
Dart
144 lines
5.2 KiB
Dart
// org_create_page.dart — إضافة مؤسسة جديدة (لوحة إدارة سيرو)
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../constant/colors.dart';
|
|
import '../../controller/transit/transit_admin_controller.dart';
|
|
|
|
class TransitOrgCreatePage extends StatefulWidget {
|
|
const TransitOrgCreatePage({super.key});
|
|
|
|
@override
|
|
State<TransitOrgCreatePage> createState() => _TransitOrgCreatePageState();
|
|
}
|
|
|
|
class _TransitOrgCreatePageState extends State<TransitOrgCreatePage> {
|
|
final _nameAr = TextEditingController();
|
|
final _nameEn = TextEditingController();
|
|
final _city = TextEditingController();
|
|
final _adminName = TextEditingController();
|
|
final _adminPhone = TextEditingController();
|
|
|
|
String _type = 'university';
|
|
String _country = 'JO';
|
|
|
|
final _types = const {
|
|
'university': 'جامعة',
|
|
'school': 'مدرسة',
|
|
'hotel': 'فندق',
|
|
'company': 'شركة',
|
|
'transporter': 'ناقل',
|
|
};
|
|
final _countries = const {'JO': 'الأردن', 'SY': 'سوريا', 'EG': 'مصر'};
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetBuilder<TransitAdminController>(
|
|
builder: (c) => Scaffold(
|
|
backgroundColor: AppColor.bg,
|
|
appBar: AppBar(
|
|
backgroundColor: AppColor.bg,
|
|
elevation: 0,
|
|
title: const Text('إضافة مؤسسة', style: TextStyle(color: AppColor.textPrimary)),
|
|
),
|
|
body: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
_dropdown('نوع المؤسسة', _type, _types, (v) => setState(() => _type = v!)),
|
|
const SizedBox(height: 12),
|
|
_dropdown('الدولة', _country, _countries, (v) => setState(() => _country = v!)),
|
|
const SizedBox(height: 12),
|
|
_field(_nameAr, 'اسم المؤسسة (عربي)'),
|
|
const SizedBox(height: 12),
|
|
_field(_nameEn, 'اسم المؤسسة (إنجليزي)'),
|
|
const SizedBox(height: 12),
|
|
_field(_city, 'المدينة'),
|
|
const SizedBox(height: 20),
|
|
const Divider(color: AppColor.surfaceElevated),
|
|
const SizedBox(height: 8),
|
|
const Text('أول مشرف (owner) لهذه المؤسسة',
|
|
style: TextStyle(color: AppColor.textSecondary)),
|
|
const SizedBox(height: 12),
|
|
_field(_adminName, 'اسم المشرف'),
|
|
const SizedBox(height: 12),
|
|
_field(_adminPhone, 'هاتف المشرف', keyboardType: TextInputType.phone),
|
|
const SizedBox(height: 24),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColor.accent,
|
|
minimumSize: const Size.fromHeight(50),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
),
|
|
onPressed: c.isCreating ? null : _submit,
|
|
child: c.isCreating
|
|
? const SizedBox(
|
|
height: 20, width: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
|
: const Text('إنشاء', style: TextStyle(color: Colors.white)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _field(TextEditingController ctrl, String label, {TextInputType? keyboardType}) {
|
|
return TextField(
|
|
controller: ctrl,
|
|
keyboardType: keyboardType,
|
|
style: const TextStyle(color: AppColor.textPrimary),
|
|
decoration: InputDecoration(
|
|
labelText: label,
|
|
labelStyle: const TextStyle(color: AppColor.textSecondary),
|
|
filled: true,
|
|
fillColor: AppColor.surface,
|
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _dropdown(String label, String value, Map<String, String> options,
|
|
void Function(String?) onChanged) {
|
|
return DropdownButtonFormField<String>(
|
|
initialValue: value,
|
|
dropdownColor: AppColor.surface,
|
|
style: const TextStyle(color: AppColor.textPrimary),
|
|
decoration: InputDecoration(
|
|
labelText: label,
|
|
labelStyle: const TextStyle(color: AppColor.textSecondary),
|
|
filled: true,
|
|
fillColor: AppColor.surface,
|
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
|
|
),
|
|
items: options.entries
|
|
.map((e) => DropdownMenuItem(value: e.key, child: Text(e.value)))
|
|
.toList(),
|
|
onChanged: onChanged,
|
|
);
|
|
}
|
|
|
|
Future<void> _submit() async {
|
|
if (_nameAr.text.trim().isEmpty ||
|
|
_nameEn.text.trim().isEmpty ||
|
|
_city.text.trim().isEmpty ||
|
|
_adminName.text.trim().isEmpty ||
|
|
_adminPhone.text.trim().isEmpty) {
|
|
Get.snackbar('مواصلاتي', 'الرجاء تعبئة كل الحقول');
|
|
return;
|
|
}
|
|
|
|
final c = Get.find<TransitAdminController>();
|
|
final ok = await c.createOrg(
|
|
type: _type,
|
|
country: _country,
|
|
city: _city.text.trim(),
|
|
nameAr: _nameAr.text.trim(),
|
|
nameEn: _nameEn.text.trim(),
|
|
adminName: _adminName.text.trim(),
|
|
adminPhone: _adminPhone.text.trim(),
|
|
);
|
|
|
|
if (ok && mounted) Get.back(result: true);
|
|
}
|
|
}
|