102 lines
3.1 KiB
Dart
102 lines
3.1 KiB
Dart
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';
|
|
import '../../controller/functions/crud.dart';
|
|
import '../../print.dart';
|
|
|
|
class AdminLoginPage extends StatefulWidget {
|
|
const AdminLoginPage({super.key});
|
|
@override
|
|
State<AdminLoginPage> createState() => _AdminLoginPageState();
|
|
}
|
|
|
|
class _AdminLoginPageState extends State<AdminLoginPage> {
|
|
final _phoneController = TextEditingController();
|
|
final _formKey = GlobalKey<FormState>();
|
|
bool _isLoading = false;
|
|
Future<void> _submit() async {
|
|
final allowedPhones = Env.ALLOWED_ADMIN_PHONES;
|
|
Log.print('allowedPhones: ${allowedPhones}');
|
|
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
|
|
void initState() {
|
|
super.initState();
|
|
_initializeToken(); // استدعاء دالة async بدون await
|
|
}
|
|
|
|
void _initializeToken() async {
|
|
await CRUD().getJWT();
|
|
}
|
|
|
|
@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('إرسال رمز التحقق'),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|