import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:sefer_admin1/env/env.dart'; import '../../controller/auth/login_controller.dart'; import '../../controller/auth/otp_helper.dart'; class AdminLoginPage extends StatefulWidget { const AdminLoginPage({super.key}); @override State createState() => _AdminLoginPageState(); } class _AdminLoginPageState extends State { final _phoneController = TextEditingController(); final _formKey = GlobalKey(); bool _isLoading = false; Future _submit() async { final allowedPhones = Env.ALLOWED_ADMIN_PHONES; allowedPhones.toString().split(','); final phone = _phoneController.text.trim(); if (!allowedPhones.contains(phone)) { Get.snackbar('رفض الدخول', 'رقم الهاتف غير مخوّل بالدخول إلى الإدارة'); return; } setState(() => _isLoading = true); final otpSent = await OtpHelper.sendOtp(phone); if (otpSent) { Get.to(() => OtpVerificationAdmin(phone: phone)); } setState(() => _isLoading = false); } @override Widget build(BuildContext context) { Get.put(OtpHelper()); return Scaffold( appBar: AppBar(title: const Text('دخول الإدارة')), body: Padding( padding: const EdgeInsets.all(20.0), child: Form( key: _formKey, child: Column( children: [ // IntlPhoneField( // initialCountryCode: 'SY', // decoration: const InputDecoration(labelText: 'رقم الهاتف'), // onChanged: (phone) { // _phoneController.text = phone.completeNumber; // }, // validator: (phone) { // if (phone == null || phone.completeNumber.isEmpty) { // return 'الرجاء إدخال رقم الهاتف'; // } // return null; // }, // ), TextFormField( controller: _phoneController, keyboardType: TextInputType.phone, decoration: const InputDecoration(labelText: 'رقم الهاتف'), validator: (value) { if (value == null || value.isEmpty) { return 'الرجاء إدخال رقم الهاتف'; } return null; }, ), const SizedBox(height: 20), _isLoading ? const CircularProgressIndicator() : ElevatedButton( onPressed: _submit, child: const Text('إرسال رمز التحقق'), ) ], ), ), ), ); } }