116 lines
4.5 KiB
Dart
116 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../controllers/auth_controller.dart';
|
|
|
|
class PhoneInputView extends StatelessWidget {
|
|
PhoneInputView({super.key});
|
|
|
|
final AuthController controller = Get.put(AuthController());
|
|
final TextEditingController phoneController = TextEditingController();
|
|
final TextEditingController passwordController = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('تسجيل الدخول')),
|
|
body: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Image.asset(
|
|
'assets/images/logo.jpg',
|
|
height: 100,
|
|
errorBuilder: (context, error, stackTrace) => const Icon(
|
|
Icons.security,
|
|
size: 80,
|
|
color: Color(0xFF0F4C81),
|
|
),
|
|
),
|
|
const SizedBox(height: 32),
|
|
const Text(
|
|
'أهلاً بك في مُصادَق',
|
|
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'أدخل رقم هاتفك أو البريد الإلكتروني لتسجيل الدخول',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 32),
|
|
TextField(
|
|
controller: phoneController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
textDirection: TextDirection.ltr,
|
|
onChanged: (val) => controller.phone.value = val,
|
|
decoration: InputDecoration(
|
|
labelText: 'رقم الهاتف أو البريد الإلكتروني',
|
|
prefixIcon: const Icon(Icons.person_outline),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Obx(() {
|
|
final isEmail = controller.phone.value.contains('@');
|
|
if (!isEmail) return const SizedBox.shrink();
|
|
|
|
return Column(
|
|
children: [
|
|
TextField(
|
|
controller: passwordController,
|
|
obscureText: true,
|
|
textDirection: TextDirection.ltr,
|
|
decoration: InputDecoration(
|
|
labelText: 'كلمة المرور',
|
|
prefixIcon: const Icon(Icons.lock_outline),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
],
|
|
);
|
|
}),
|
|
Obx(() => ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
onPressed: controller.isLoading.value
|
|
? null
|
|
: () {
|
|
if (controller.phone.value.contains('@')) {
|
|
controller.loginWithEmail(
|
|
controller.phone.value,
|
|
passwordController.text
|
|
);
|
|
} else {
|
|
controller.requestOtp(phoneController.text);
|
|
}
|
|
},
|
|
child: controller.isLoading.value
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: Text(
|
|
controller.phone.value.contains('@')
|
|
? 'تسجيل الدخول'
|
|
: 'إرسال رمز التحقق',
|
|
style: const TextStyle(fontSize: 16)
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|