25-10-2/1

This commit is contained in:
Hamza-Ayed
2025-10-02 01:19:38 +03:00
parent f08ee61a7e
commit 95fb065bdb
43 changed files with 13917 additions and 13426 deletions

View File

@@ -1,19 +1,36 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
// --- Placeholder Imports ---
// Assuming these files exist in your project structure.
import '../../../constant/box_name.dart';
import '../../../constant/colors.dart';
import '../../../controller/auth/captin/phone_helper_controller.dart';
import '../../../controller/local/phone_intel/intl_phone_field.dart';
import '../../../main.dart';
import '../../../print.dart';
// Assuming you have an AppColor class defined in your project.
// import 'path/to/your/app_color.dart';
// --- Placeholder AppColor Class ---
// This is used to make the code runnable.
// You should use the one from your project.
// class AppColor {
// static const Color primaryColor = Color(0xFF1DA1F2);
// static const Color greenColor = Color(0xFF34A853); // Google Green
// static const Color secondaryColor = Colors.white;
// }
// --- End of Placeholder ---
/// A visually revamped authentication screen with a light, glassy effect,
/// themed for the driver application using a green primary color.
class AuthScreen extends StatelessWidget {
final String title;
final String subtitle;
final Widget form;
// Using a more neutral, tech-themed animated logo
final String logoUrl = 'assets/images/logo.gif';
const AuthScreen({
super.key,
@@ -22,176 +39,258 @@ class AuthScreen extends StatelessWidget {
required this.form,
});
/// Shows a dialog for testers to log in using email and password.
void _showTesterLoginDialog(
BuildContext context, LoginDriverController controller) {
final testerEmailController = TextEditingController();
final testerPasswordController = TextEditingController();
final testerFormKey = GlobalKey<FormState>();
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext dialogContext) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: AlertDialog(
backgroundColor: Colors.white.withOpacity(0.85),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
title: const Text(
'App Tester Login',
textAlign: TextAlign.center,
style:
TextStyle(fontWeight: FontWeight.bold, color: Colors.black87),
),
content: Form(
key: testerFormKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
controller: testerEmailController,
keyboardType: TextInputType.emailAddress,
style: const TextStyle(color: Colors.black),
decoration: InputDecoration(
labelText: 'Email',
prefixIcon: const Icon(Icons.email_outlined),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(
color: AppColor.greenColor, width: 2),
),
),
validator: (value) => value == null || !value.contains('@')
? 'Enter a valid email'.tr
: null,
),
const SizedBox(height: 16),
TextFormField(
controller: testerPasswordController,
obscureText: true,
style: const TextStyle(color: Colors.black),
decoration: InputDecoration(
labelText: 'Password',
prefixIcon: const Icon(Icons.lock_outline),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(
color: AppColor.greenColor, width: 2),
),
),
validator: (value) => value == null || value.isEmpty
? 'Enter a password'
: null,
),
],
),
),
actions: [
TextButton(
child: const Text('Cancel'),
onPressed: () => Navigator.of(dialogContext).pop(),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.greenColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child:
const Text('Login', style: TextStyle(color: Colors.white)),
onPressed: () {
if (testerFormKey.currentState!.validate()) {
controller.logintest(
testerPasswordController.text.trim(),
testerEmailController.text.trim(),
);
Navigator.of(dialogContext).pop();
}
},
),
],
),
);
},
);
}
@override
Widget build(BuildContext context) {
final controller = Get.put(LoginDriverController());
// Controller for the driver's login logic
final loginController = Get.put(LoginDriverController());
return Scaffold(
body: Container(
// UPDATED: Changed gradient colors to a green theme
// NEW: Light and airy gradient with green accents
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.teal.shade700, Colors.green.shade600],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.white,
Colors.green.shade50,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(logoUrl, height: 120),
const SizedBox(height: 20),
Text(
title,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white),
child: Stack(
children: [
// Subtle background shapes with the new primary color
Positioned(
top: -80,
left: -100,
child: Container(
width: 250,
height: 250,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColor.greenColor.withOpacity(0.1),
),
const SizedBox(height: 10),
Text(
subtitle,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16, color: Colors.white.withOpacity(0.8)),
),
),
Positioned(
bottom: -120,
right: -150,
child: Container(
width: 350,
height: 350,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: AppColor.greenColor.withOpacity(0.15),
),
const SizedBox(height: 30),
GetBuilder<LoginDriverController>(builder: (context) {
return box.read(BoxName.isTest).toString() == '0'
? Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.symmetric(
horizontal: 24, vertical: 32),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// GestureDetector for tester login
GestureDetector(
onLongPress: () {
_showTesterLoginDialog(context, loginController);
},
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white.withOpacity(0.5),
border: Border.all(
color: Colors.white.withOpacity(0.8), width: 2),
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 12,
offset: const Offset(0, 6),
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
spreadRadius: 5)
]),
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.asset('assets/images/logo.gif',
height: 100)),
),
),
const SizedBox(height: 20),
Text(
title,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.black87),
),
const SizedBox(height: 10),
Text(
subtitle,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16,
color: Colors.black54,
),
),
const SizedBox(height: 30),
// Glassmorphism Container for the form with a whiter look
ClipRRect(
borderRadius: BorderRadius.circular(25.0),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: Container(
padding: const EdgeInsets.all(24.0),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.6),
borderRadius: BorderRadius.circular(25.0),
border: Border.all(
color: Colors.white.withOpacity(0.8),
width: 1.5,
),
),
child: form,
),
),
),
const SizedBox(height: 20),
// Button for app testers, adapted to the light theme
Material(
color: Colors.black.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
child: InkWell(
onTap: () =>
_showTesterLoginDialog(context, loginController),
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 16),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.admin_panel_settings_outlined,
color: Colors.black.withOpacity(0.6)),
const SizedBox(width: 8),
Text(
'For App Reviewers / Testers',
style: TextStyle(
color: Colors.black.withOpacity(0.6),
fontWeight: FontWeight.w600,
),
),
],
),
child: Form(
key: controller.formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Title
Text(
'Please login to continue',
style: TextStyle(
fontSize: 16,
color: Colors.grey[600],
),
textAlign: TextAlign.center,
),
const SizedBox(height: 32),
// Email Field
TextFormField(
keyboardType: TextInputType.emailAddress,
controller: controller.emailController,
decoration: InputDecoration(
labelText: 'Email'.tr,
hintText: 'Enter your email address'.tr,
prefixIcon:
const Icon(Icons.email_outlined),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
validator: (value) => value == null ||
value.isEmpty ||
!value.contains('@') ||
!value.contains('.')
? 'Enter a valid email'.tr
: null,
),
const SizedBox(height: 20),
// Password Field
TextFormField(
obscureText: true,
controller: controller.passwordController,
decoration: InputDecoration(
labelText: 'Password'.tr,
hintText: 'Enter your password'.tr,
prefixIcon: const Icon(Icons.lock_outline),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
validator: (value) =>
value == null || value.isEmpty
? 'Enter your password'.tr
: null,
),
const SizedBox(height: 24),
// Submit Button
GetBuilder<LoginDriverController>(
builder: (controller) => controller.isloading
? const Center(
child: CircularProgressIndicator())
: SizedBox(
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Colors.blueAccent,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(12),
),
),
onPressed: () {
if (controller
.formKey.currentState!
.validate()) {
controller.logintest(
controller
.passwordController.text
.trim(),
controller
.emailController.text
.trim(),
);
}
},
child: Text(
'Login'.tr,
style:
const TextStyle(fontSize: 16),
),
),
),
),
const SizedBox(height: 16),
// Optional: Forgot Password / Create Account
],
),
),
)
: Card(
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16)),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: form,
),
);
})
],
),
),
),
],
),
),
),
),
],
),
),
);
@@ -233,75 +332,66 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// TextFormField(
// controller: _phoneController,
// decoration: InputDecoration(
// labelText: 'phone number label'.tr,
// prefixIcon:
// Icon(Icons.phone_android, color: Colors.teal.shade400),
// border:
// OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
// ),
// keyboardType: TextInputType.phone,
// validator: (v) => v!.isEmpty ? 'phone number required'.tr : null,
// ),
Padding(
padding: const EdgeInsets.all(16.0),
child: IntlPhoneField(
// languageCode: 'ar',
showCountryFlag: false,
flagsButtonMargin: EdgeInsets.only(right: 8),
flagsButtonPadding: EdgeInsets.all(4),
dropdownDecoration:
BoxDecoration(borderRadius: BorderRadius.circular(8)),
// controller: _phoneController,
decoration: InputDecoration(
labelText: 'Phone Number'.tr,
border: const OutlineInputBorder(
borderSide: BorderSide(),
),
),
initialCountryCode: 'SY',
onChanged: (phone) {
// Properly concatenate country code and number
_phoneController.text = phone.completeNumber.toString();
Log.print(' phone.number: ${phone.number}');
print("Formatted phone number: ${_phoneController.text}");
},
validator: (phone) {
// Check if the phone number is not null and is valid
if (phone == null || phone.completeNumber.isEmpty) {
return 'Please enter your phone number';
}
// Extract the phone number (excluding the country code)
final number = phone.completeNumber.toString();
// Check if the number length is exactly 11 digits
if (number.length != 13) {
return 'Phone number must be exactly 11 digits long';
}
// If all validations pass, return null
return null;
},
),
Text(
'Enter your phone number'.tr,
style: TextStyle(color: Colors.black87, fontSize: 16),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
IntlPhoneField(
showCountryFlag: false,
searchText: 'Search country'.tr,
languageCode: 'ar',
style: const TextStyle(color: Colors.black),
dropdownTextStyle: const TextStyle(color: Colors.black87),
decoration: InputDecoration(
labelText: 'Phone Number'.tr,
labelStyle: const TextStyle(color: Colors.black54),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.black.withOpacity(0.1)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide:
const BorderSide(color: AppColor.greenColor, width: 2),
),
),
initialCountryCode: 'SY',
onChanged: (phone) {
_phoneController.text = phone.completeNumber;
},
validator: (phone) {
if (phone == null || phone.number.isEmpty) {
return 'Please enter your phone number';
}
if (phone.completeNumber.length < 10) {
return 'Phone number seems too short';
}
return null;
},
),
const SizedBox(height: 24),
_isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _submit,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
minimumSize: const Size(double.infinity, 50),
? const CircularProgressIndicator(color: AppColor.greenColor)
: SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _submit,
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.greenColor,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
),
child: Text(
'send otp button'.tr,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
child: Text('send otp button'.tr),
),
],
),
@@ -319,61 +409,17 @@ class OtpVerificationScreen extends StatefulWidget {
class _OtpVerificationScreenState extends State<OtpVerificationScreen> {
final _formKey = GlobalKey<FormState>();
final TextEditingController _otpControllers = TextEditingController();
// final List<FocusNode> _focusNodes = List.generate(5, (_) => FocusNode());
final _otpController = TextEditingController();
bool _isLoading = false;
@override
void dispose() {
// for (var controller in _otpControllers) {
// controller.dispose();
// }
// for (var node in _focusNodes) {
// node.dispose();
// }
super.dispose();
}
void _submit() async {
if (_formKey.currentState!.validate()) {
setState(() => _isLoading = true);
final otp = _otpControllers.text;
await PhoneAuthHelper.verifyOtp(widget.phoneNumber, otp);
await PhoneAuthHelper.verifyOtp(widget.phoneNumber, _otpController.text);
if (mounted) setState(() => _isLoading = false);
}
}
Widget _buildOtpInput() {
return Form(
key: _formKey,
child: Container(
width: 200,
height: 50,
decoration: BoxDecoration(
color: Colors.grey.shade200,
shape: BoxShape.circle,
),
child: Center(
child: TextFormField(
controller: _otpControllers,
// focusNode: _focusNodes[index],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 5,
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
decoration: const InputDecoration(
counterText: "",
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
),
onChanged: (value) {},
validator: (v) => v!.isEmpty ? '' : null,
),
),
),
);
}
@override
Widget build(BuildContext context) {
return AuthScreen(
@@ -383,20 +429,59 @@ class _OtpVerificationScreenState extends State<OtpVerificationScreen> {
form: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildOtpInput(),
const Text(
'Enter the 5-digit code',
style: TextStyle(color: Colors.black87, fontSize: 16),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Form(
key: _formKey,
child: TextFormField(
controller: _otpController,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 5,
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.black87,
letterSpacing: 18,
),
decoration: InputDecoration(
counterText: "",
hintText: '-----',
hintStyle: TextStyle(
color: Colors.black.withOpacity(0.2),
letterSpacing: 18,
fontSize: 28),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 10),
),
validator: (v) => v == null || v.length < 5 ? '' : null,
),
),
const SizedBox(height: 30),
_isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _submit,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
foregroundColor: Colors.white,
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
? const CircularProgressIndicator(color: AppColor.greenColor)
: SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _submit,
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.greenColor,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
),
child: Text(
'verify and continue button'.tr,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
child: Text('verify and continue button'.tr),
),
],
),
@@ -431,6 +516,32 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
}
}
Widget _buildTextFormField({
required TextEditingController controller,
required String label,
TextInputType keyboardType = TextInputType.text,
String? Function(String?)? validator,
}) {
return TextFormField(
controller: controller,
style: const TextStyle(color: Colors.black87),
decoration: InputDecoration(
labelText: label,
labelStyle: const TextStyle(color: Colors.black54),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.black.withOpacity(0.1)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: AppColor.greenColor, width: 2),
),
),
keyboardType: keyboardType,
validator: validator,
);
}
@override
Widget build(BuildContext context) {
return AuthScreen(
@@ -441,45 +552,44 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
_buildTextFormField(
controller: _firstNameController,
decoration: InputDecoration(
labelText: 'first name label'.tr,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12)))),
label: 'first name label'.tr,
validator: (v) => v!.isEmpty ? 'first name required'.tr : null,
),
const SizedBox(height: 16),
TextFormField(
_buildTextFormField(
controller: _lastNameController,
decoration: InputDecoration(
labelText: 'last name label'.tr,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12)))),
label: 'last name label'.tr,
validator: (v) => v!.isEmpty ? 'last name required'.tr : null,
),
const SizedBox(height: 16),
TextFormField(
_buildTextFormField(
controller: _emailController,
decoration: InputDecoration(
labelText: 'email optional label'.tr,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12)))),
label: 'email optional label'.tr,
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 24),
_isLoading
? const CircularProgressIndicator()
: ElevatedButton(
onPressed: _submit,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
foregroundColor: Colors.white,
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
? const CircularProgressIndicator(color: AppColor.greenColor)
: SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _submit,
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.greenColor,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
),
child: Text(
'complete registration button'.tr,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
child: Text('complete registration button'.tr),
),
],
),