25-10-2/1
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
import 'package:Intaleq/controller/auth/login_controller.dart';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../controller/auth/otp_controller.dart';
|
||||
// --- placeholder imports ---
|
||||
// These are assumed to exist from your original code.
|
||||
// Make sure to have these files and controllers properly set up in your project.
|
||||
import 'package:Intaleq/controller/auth/login_controller.dart';
|
||||
import '../../controller/auth/otp_controller.dart'; // Assumed to be PhoneAuthHelper
|
||||
import '../../controller/local/phone_intel/intl_phone_field.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
// --- end of placeholder imports ---
|
||||
|
||||
/// A visually revamped authentication screen with a glassmorphism effect.
|
||||
/// It provides a consistent and beautiful UI for all authentication steps.
|
||||
///
|
||||
/// A hidden feature for testers is included: a long-press on the logo
|
||||
/// will open a dialog for email/password login, suitable for app reviews.
|
||||
class AuthScreen extends StatelessWidget {
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final Widget form;
|
||||
// Using a more neutral, tech-themed animated logo
|
||||
// final String logoUrl = 'https://i.gifer.com/ZZ5H.gif';
|
||||
|
||||
const AuthScreen({
|
||||
super.key,
|
||||
@@ -22,175 +27,269 @@ class AuthScreen extends StatelessWidget {
|
||||
required this.form,
|
||||
});
|
||||
|
||||
/// Shows a dialog for testers to log in using email and password.
|
||||
/// This is triggered by a long-press on the logo or the explicit tester button.
|
||||
void _showTesterLoginDialog(
|
||||
BuildContext context, LoginController 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: const Color(0xFF162232).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.white),
|
||||
),
|
||||
content: Form(
|
||||
key: testerFormKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: testerEmailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Email',
|
||||
labelStyle:
|
||||
TextStyle(color: Colors.white.withOpacity(0.7)),
|
||||
prefixIcon: Icon(Icons.email_outlined,
|
||||
color: Colors.white.withOpacity(0.7)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide:
|
||||
BorderSide(color: Colors.white.withOpacity(0.3)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF00BFFF)),
|
||||
),
|
||||
),
|
||||
validator: (value) => value == null || !value.contains('@')
|
||||
? 'Enter a valid email'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: testerPasswordController,
|
||||
obscureText: true,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password',
|
||||
labelStyle:
|
||||
TextStyle(color: Colors.white.withOpacity(0.7)),
|
||||
prefixIcon: Icon(Icons.lock_outline,
|
||||
color: Colors.white.withOpacity(0.7)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide:
|
||||
BorderSide(color: Colors.white.withOpacity(0.3)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF00BFFF)),
|
||||
),
|
||||
),
|
||||
validator: (value) => value == null || value.isEmpty
|
||||
? 'Enter a password'
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel',
|
||||
style: TextStyle(color: Colors.white70)),
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00BFFF),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child:
|
||||
const Text('Login', style: TextStyle(color: Colors.black)),
|
||||
onPressed: () {
|
||||
if (testerFormKey.currentState!.validate()) {
|
||||
// Use the main controller to perform login
|
||||
controller.emailController.text =
|
||||
testerEmailController.text;
|
||||
controller.passwordController.text =
|
||||
testerPasswordController.text;
|
||||
controller.login();
|
||||
Navigator.of(dialogContext).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = Get.find<LoginController>();
|
||||
// We still need the controller for the hidden tester login
|
||||
final loginController = Get.find<LoginController>();
|
||||
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
// UPDATED: Changed gradient colors to a green theme
|
||||
decoration: BoxDecoration(
|
||||
// NEW: AI-inspired, brighter, and more dynamic color gradient
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.teal.shade700, Colors.green.shade600],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF00122E), Color(0xFF00285F)],
|
||||
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('assets/images/logo.gif', height: 120),
|
||||
const SizedBox(height: 20),
|
||||
// IconButton(
|
||||
// onPressed: () {
|
||||
// Get.find<LoginController>().getJWT();
|
||||
// },
|
||||
// icon: const Icon(Icons.add),
|
||||
// ),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Background shapes for a more dynamic feel
|
||||
Positioned(
|
||||
top: -100,
|
||||
left: -100,
|
||||
child: Container(
|
||||
width: 250,
|
||||
height: 250,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: const Color(0xFF00BFFF).withOpacity(0.15),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
subtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 16, color: Colors.white.withOpacity(0.8)),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: -150,
|
||||
right: -100,
|
||||
child: Container(
|
||||
width: 350,
|
||||
height: 350,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: const Color(0xFF00BFFF).withOpacity(0.1),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
GetBuilder<LoginController>(builder: (context) {
|
||||
return box.read(BoxName.isTest).toString() == '0'
|
||||
? Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 32),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// GestureDetector to handle long-press 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.1),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
width: 2)),
|
||||
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.white,
|
||||
shadows: [
|
||||
Shadow(
|
||||
blurRadius: 10.0,
|
||||
color: Colors.black26,
|
||||
offset: Offset(2, 2)),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
subtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Glassmorphism Container for the form
|
||||
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,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black12,
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 6),
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(25.0),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
child:
|
||||
form, // The form from the specific screen is placed here
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// A more distinct button for app testers
|
||||
Material(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
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.white.withOpacity(0.8)),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'For App Reviewers / Testers',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
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<LoginController>(
|
||||
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.login();
|
||||
}
|
||||
},
|
||||
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,
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -198,6 +297,8 @@ class AuthScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
// --- UI Screens ---
|
||||
// Note: These screens now use the new AuthScreen wrapper and have updated styling
|
||||
// for their form elements to match the new design.
|
||||
|
||||
class PhoneNumberScreen extends StatefulWidget {
|
||||
const PhoneNumberScreen({super.key});
|
||||
@@ -213,16 +314,12 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
|
||||
void _submit() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
// إزالة + من بداية الرقم
|
||||
// PRODUCTION READY: Using the actual PhoneAuthHelper
|
||||
final rawPhone = _phoneController.text.trim().replaceFirst('+', '');
|
||||
|
||||
final success = await PhoneAuthHelper.sendOtp(rawPhone);
|
||||
|
||||
if (success && mounted) {
|
||||
Get.to(() => OtpVerificationScreen(phoneNumber: rawPhone));
|
||||
}
|
||||
|
||||
if (mounted) setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
@@ -237,74 +334,67 @@ class _PhoneNumberScreenState extends State<PhoneNumberScreen> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
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.white.withOpacity(0.9), fontSize: 16),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
IntlPhoneField(
|
||||
showCountryFlag: false,
|
||||
searchText: 'Search country'.tr,
|
||||
languageCode: 'ar',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
dropdownTextStyle: const TextStyle(color: Colors.black87),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Phone Number'.tr,
|
||||
labelStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.white.withOpacity(0.3)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF00BFFF)),
|
||||
),
|
||||
),
|
||||
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) {
|
||||
// Example validation
|
||||
return 'Phone number seems too short';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
// 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,
|
||||
// ),
|
||||
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: Colors.white)
|
||||
: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00BFFF),
|
||||
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.black),
|
||||
),
|
||||
),
|
||||
child: Text('send otp button'.tr),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -322,61 +412,18 @@ 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);
|
||||
// PRODUCTION READY: Using the actual PhoneAuthHelper
|
||||
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(
|
||||
@@ -386,20 +433,60 @@ class _OtpVerificationScreenState extends State<OtpVerificationScreen> {
|
||||
form: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildOtpInput(),
|
||||
Text(
|
||||
'Enter the 5-digit code'.tr,
|
||||
style:
|
||||
TextStyle(color: Colors.white.withOpacity(0.9), 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.white,
|
||||
letterSpacing: 18, // Visually separates the digits
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
counterText: "",
|
||||
hintText: '-----',
|
||||
hintStyle: TextStyle(
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
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: Colors.white)
|
||||
: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00BFFF),
|
||||
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.black),
|
||||
),
|
||||
),
|
||||
child: Text('verify and continue button'.tr),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -424,6 +511,7 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
|
||||
void _submit() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
setState(() => _isLoading = true);
|
||||
// PRODUCTION READY: Using the actual PhoneAuthHelper
|
||||
await PhoneAuthHelper.registerUser(
|
||||
phoneNumber: widget.phoneNumber,
|
||||
firstName: _firstNameController.text.trim(),
|
||||
@@ -434,6 +522,33 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to create styled text form fields
|
||||
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.white),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.white.withOpacity(0.3)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Color(0xFF00BFFF)),
|
||||
),
|
||||
),
|
||||
keyboardType: keyboardType,
|
||||
validator: validator,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AuthScreen(
|
||||
@@ -444,45 +559,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: Colors.white)
|
||||
: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00BFFF),
|
||||
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.black),
|
||||
),
|
||||
),
|
||||
child: Text('complete registration button'.tr),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -25,7 +25,7 @@ class _OtpVerificationPageState extends State<OtpVerificationPage> {
|
||||
late final OtpVerificationController controller;
|
||||
final List<FocusNode> _focusNodes = List.generate(6, (index) => FocusNode());
|
||||
final List<TextEditingController> _textControllers =
|
||||
List.generate(6, (index) => TextEditingController());
|
||||
List.generate(5, (index) => TextEditingController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
||||
@@ -6,11 +6,9 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'dart:ui'; // مهم لإضافة تأثير الضبابية
|
||||
|
||||
import '../../../constant/colors.dart';
|
||||
import '../../../controller/auth/login_controller.dart';
|
||||
import '../../../controller/functions/tts.dart';
|
||||
import '../../../controller/home/map_passenger_controller.dart';
|
||||
import '../../../controller/home/vip_waitting_page.dart';
|
||||
import '../../auth/otp_page.dart';
|
||||
|
||||
// --- الدالة الرئيسية بالتصميم الجديد ---
|
||||
GetBuilder<MapPassengerController> leftMainMenuIcons() {
|
||||
@@ -128,24 +126,7 @@ class TestPage extends StatelessWidget {
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
Get.put(LoginController());
|
||||
Get.to(() => PhoneNumberScreen());
|
||||
// firebaseMessagesController.sendNotificationToDriverMAP(
|
||||
// 'title',
|
||||
// DateTime.now().toString(),
|
||||
// 'ffX7xVXpdE_Xq8JBH3lgS4:APA91bGBHp53E-ZuXdlLBpRZohzqR9sazqcn3pwpEDG7JxkVi9MBtFDlCipzLpPCvD6LHEtds88ugGyCty7pEJVyx6tQYvzHVDCh7l3_7axpyriTBs5iv9E',
|
||||
// [],
|
||||
// '');
|
||||
// Get.to(
|
||||
// () => OtpVerificationPage(
|
||||
// phone: '963992952235',
|
||||
// deviceToken: 'abcdefg123456789',
|
||||
// token: 'passengerToken123',
|
||||
// ptoken: 'passengerToken456',
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
onPressed: () async {},
|
||||
child: Text(
|
||||
"Text Button",
|
||||
),
|
||||
|
||||
@@ -7,10 +7,12 @@ import 'package:Intaleq/constant/box_name.dart';
|
||||
import 'package:Intaleq/constant/colors.dart';
|
||||
import 'package:Intaleq/controller/functions/toast.dart';
|
||||
import 'package:Intaleq/controller/payment/payment_controller.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
|
||||
import '../../../main.dart';
|
||||
import '../../widgets/elevated_btn.dart';
|
||||
import '../../widgets/my_textField.dart';
|
||||
import 'payment_screen_sham.dart';
|
||||
|
||||
class PassengerWalletDialog extends StatelessWidget {
|
||||
const PassengerWalletDialog({
|
||||
@@ -32,52 +34,52 @@ class PassengerWalletDialog extends StatelessWidget {
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
controller.updateSelectedAmount(
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 1000 : 10,
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 10000 : 10,
|
||||
);
|
||||
showPaymentOptions(context, controller);
|
||||
},
|
||||
child: Text(
|
||||
box.read(BoxName.countryCode) == 'Syria'
|
||||
? '1000 ${'LE'.tr}'
|
||||
? '10000 ${'LE'.tr}'
|
||||
: '10 ${'SYP'.tr}',
|
||||
),
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
controller.updateSelectedAmount(
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 2000 : 20,
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 20000 : 20,
|
||||
);
|
||||
showPaymentOptions(context, controller);
|
||||
},
|
||||
child: Text(
|
||||
box.read(BoxName.countryCode) == 'Syria'
|
||||
? '2000 ${'LE'.tr} = 2050 ${'LE'.tr}'
|
||||
? '20000 ${'LE'.tr} = 2050 ${'LE'.tr}'
|
||||
: '20 ${'SYP'.tr}',
|
||||
),
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
controller.updateSelectedAmount(
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 4000 : 40,
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 40000 : 40,
|
||||
);
|
||||
showPaymentOptions(context, controller);
|
||||
},
|
||||
child: Text(
|
||||
box.read(BoxName.countryCode) == 'Syria'
|
||||
? '4000 ${'LE'.tr} = 4150 ${'LE'.tr}'
|
||||
? '40000 ${'LE'.tr} = 4150 ${'LE'.tr}'
|
||||
: '40 ${'SYP'.tr}',
|
||||
),
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
controller.updateSelectedAmount(
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 1000 : 50,
|
||||
box.read(BoxName.countryCode) == 'Syria' ? 100000 : 50,
|
||||
);
|
||||
showPaymentOptions(context, controller);
|
||||
},
|
||||
child: Text(
|
||||
box.read(BoxName.countryCode) == 'Syria'
|
||||
? '10000 ${'LE'.tr} = 11000 ${'LE'.tr}'
|
||||
? '100000 ${'LE'.tr} = 11000 ${'LE'.tr}'
|
||||
: '50 ${'SYP'.tr}',
|
||||
),
|
||||
),
|
||||
@@ -149,7 +151,7 @@ void showPaymentBottomSheet(BuildContext context) {
|
||||
_buildPaymentOption(
|
||||
context: context,
|
||||
controller: controller,
|
||||
amount: 100000,
|
||||
amount: 10000,
|
||||
bonusAmount: 0,
|
||||
currency: 'SYP'.tr,
|
||||
),
|
||||
@@ -158,8 +160,8 @@ void showPaymentBottomSheet(BuildContext context) {
|
||||
_buildPaymentOption(
|
||||
context: context,
|
||||
controller: controller,
|
||||
amount: 200000,
|
||||
bonusAmount: 5000,
|
||||
amount: 20000,
|
||||
bonusAmount: 500,
|
||||
currency: 'SYP'.tr,
|
||||
),
|
||||
|
||||
@@ -167,8 +169,8 @@ void showPaymentBottomSheet(BuildContext context) {
|
||||
_buildPaymentOption(
|
||||
context: context,
|
||||
controller: controller,
|
||||
amount: 400000,
|
||||
bonusAmount: 25000,
|
||||
amount: 40000,
|
||||
bonusAmount: 2500,
|
||||
currency: 'SYP'.tr,
|
||||
),
|
||||
|
||||
@@ -176,8 +178,8 @@ void showPaymentBottomSheet(BuildContext context) {
|
||||
_buildPaymentOption(
|
||||
context: context,
|
||||
controller: controller,
|
||||
amount: 1000000,
|
||||
bonusAmount: 40000,
|
||||
amount: 100000,
|
||||
bonusAmount: 4000,
|
||||
currency: 'SYP'.tr,
|
||||
),
|
||||
|
||||
@@ -442,6 +444,67 @@ void showPaymentOptions(BuildContext context, PaymentController controller) {
|
||||
],
|
||||
),
|
||||
)),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
Get.back();
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'Insert Wallet phone number'.tr,
|
||||
content: Form(
|
||||
key: controller.formKey,
|
||||
child: MyTextForm(
|
||||
controller: controller.walletphoneController,
|
||||
label: 'Insert Wallet phone number'.tr,
|
||||
hint: '963941234567',
|
||||
type: TextInputType.phone)),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'OK'.tr,
|
||||
onPressed: () async {
|
||||
Get.back();
|
||||
if (controller.formKey.currentState!.validate()) {
|
||||
box.write(BoxName.phoneWallet,
|
||||
controller.walletphoneController.text);
|
||||
// await payWithSyriaTelWallet(
|
||||
// context, pricePoint.toString(), 'SYP');
|
||||
bool isAuthSupported =
|
||||
await LocalAuthentication().isDeviceSupported();
|
||||
if (isAuthSupported) {
|
||||
bool didAuthenticate =
|
||||
await LocalAuthentication().authenticate(
|
||||
localizedReason:
|
||||
'استخدم بصمة الإصبع أو الوجه لتأكيد الدفع',
|
||||
);
|
||||
if (!didAuthenticate) {
|
||||
if (Get.isDialogOpen ?? false) Get.back();
|
||||
print(
|
||||
"❌ User did not authenticate with biometrics");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Get.to(() => PaymentScreenSmsProvider(
|
||||
amount: controller.selectedAmount!.toDouble()));
|
||||
}
|
||||
}));
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Pay by Sham Cash'.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Image.asset(
|
||||
'assets/images/shamCash.png',
|
||||
width: 70,
|
||||
height: 70,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
child: Text('Cancel'.tr),
|
||||
|
||||
402
lib/views/home/my_wallet/payment_screen_sham.dart
Normal file
402
lib/views/home/my_wallet/payment_screen_sham.dart
Normal file
@@ -0,0 +1,402 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:Intaleq/views/widgets/mydialoug.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_core/src/get_main.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../constant/box_name.dart';
|
||||
import '../../../constant/links.dart';
|
||||
import '../../../controller/functions/crud.dart';
|
||||
import '../../../main.dart';
|
||||
|
||||
class PaymentService {
|
||||
final String _baseUrl = "${AppLink.seferPaymentServer}/sms_webhook";
|
||||
|
||||
Future<String?> createInvoice({
|
||||
required String userPhone,
|
||||
required double amount,
|
||||
}) async {
|
||||
final url = "$_baseUrl/create_invoice_passenger.php";
|
||||
try {
|
||||
final response = await CRUD().postWallet(
|
||||
link: url,
|
||||
payload: {
|
||||
'user_phone': userPhone.toString(),
|
||||
'passengerID': box.read(BoxName.passengerID),
|
||||
'amount': amount.toString(),
|
||||
},
|
||||
).timeout(const Duration(seconds: 15)); // إضافة مهلة للطلب
|
||||
|
||||
if (response != 'failure') {
|
||||
final data = (response);
|
||||
if (data['status'] == 'success' && data['invoice_number'] != null) {
|
||||
debugPrint(
|
||||
"تم إنشاء الفاتورة بنجاح. الرقم: ${data['invoice_number']}");
|
||||
return data['invoice_number'].toString();
|
||||
} else {
|
||||
debugPrint("فشل في إنشاء الفاتورة من السيرفر: ${data['message']}");
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
debugPrint("خطأ في السيرفر عند إنشاء الفاتورة: ${response.statusCode}");
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("حدث استثناء عند إنشاء الفاتورة: $e");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// دالة للتحقق من حالة فاتورة واحدة
|
||||
Future<bool> checkInvoiceStatus(String invoiceNumber) async {
|
||||
final url = "$_baseUrl/check_invoice_status_passenger.php";
|
||||
try {
|
||||
final response = await CRUD().postWallet(link: url, payload: {
|
||||
'invoice_number': invoiceNumber,
|
||||
}).timeout(const Duration(seconds: 10)); // مهلة للشبكة
|
||||
|
||||
if (response != 'failure') {
|
||||
final data = (response);
|
||||
return data['status'] == 'success' &&
|
||||
data['invoice_status'] == 'completed';
|
||||
}
|
||||
return false;
|
||||
} catch (e) {
|
||||
debugPrint("خطأ أثناء التحقق من الفاتورة: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PaymentStatus {
|
||||
creatingInvoice,
|
||||
waitingForPayment,
|
||||
paymentSuccess,
|
||||
paymentTimeout,
|
||||
paymentError
|
||||
}
|
||||
|
||||
class PaymentScreenSmsProvider extends StatefulWidget {
|
||||
final double amount;
|
||||
final String providerName;
|
||||
final String providerLogo;
|
||||
final String paymentPhoneNumber;
|
||||
|
||||
const PaymentScreenSmsProvider({
|
||||
super.key,
|
||||
required this.amount,
|
||||
this.providerName = 'شام كاش',
|
||||
this.providerLogo = 'assets/images/shamCash.png',
|
||||
this.paymentPhoneNumber = '963942542053',
|
||||
});
|
||||
|
||||
@override
|
||||
_PaymentScreenSmsProviderState createState() =>
|
||||
_PaymentScreenSmsProviderState();
|
||||
}
|
||||
|
||||
class _PaymentScreenSmsProviderState extends State<PaymentScreenSmsProvider> {
|
||||
final PaymentService _paymentService = PaymentService();
|
||||
Timer? _pollingTimer;
|
||||
PaymentStatus _status = PaymentStatus.creatingInvoice;
|
||||
String? _invoiceNumber;
|
||||
final String phone = box.read(BoxName.phoneWallet);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_createAndPollInvoice();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pollingTimer?.cancel(); // مهم جداً: إلغاء المؤقت عند الخروج من الشاشة
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _createAndPollInvoice() async {
|
||||
setState(() => _status = PaymentStatus.creatingInvoice);
|
||||
|
||||
final invoiceNumber = await _paymentService.createInvoice(
|
||||
userPhone: phone,
|
||||
amount: widget.amount,
|
||||
);
|
||||
|
||||
if (invoiceNumber != null && mounted) {
|
||||
setState(() {
|
||||
_invoiceNumber = invoiceNumber;
|
||||
_status = PaymentStatus.waitingForPayment;
|
||||
});
|
||||
_startPolling(invoiceNumber);
|
||||
} else if (mounted) {
|
||||
setState(() => _status = PaymentStatus.paymentError);
|
||||
}
|
||||
}
|
||||
|
||||
void _startPolling(String invoiceNumber) {
|
||||
const timeoutDuration = Duration(minutes: 3);
|
||||
var elapsed = Duration.zero;
|
||||
|
||||
_pollingTimer = Timer.periodic(const Duration(seconds: 5), (timer) async {
|
||||
elapsed += const Duration(seconds: 5);
|
||||
if (elapsed >= timeoutDuration) {
|
||||
timer.cancel();
|
||||
if (mounted) setState(() => _status = PaymentStatus.paymentTimeout);
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint("Polling... Checking invoice status for: $invoiceNumber");
|
||||
final isCompleted =
|
||||
await _paymentService.checkInvoiceStatus(invoiceNumber);
|
||||
if (isCompleted && mounted) {
|
||||
timer.cancel();
|
||||
setState(() => _status = PaymentStatus.paymentSuccess);
|
||||
// TODO: تحديث رصيد المستخدم أو تنفيذ الإجراءات اللازمة
|
||||
MyDialog().getDialog(
|
||||
'Payment Successful!'.tr,
|
||||
''.tr,
|
||||
() {
|
||||
Get.back();
|
||||
Get.back();
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// دالة جديدة لمعالجة محاولة الرجوع للخلف
|
||||
void _onPopInvoked(bool didPop) async {
|
||||
// إذا كان الرجوع قد تم بالفعل (مثلاً من خلال Navigator.pop)، لا تفعل شيئاً
|
||||
if (didPop) return;
|
||||
|
||||
// إذا كان المستخدم ينتظر الدفع، أظهر له حوار التأكيد
|
||||
if (_status == PaymentStatus.waitingForPayment) {
|
||||
final shouldPop = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('هل أنت متأكد؟'),
|
||||
content: const Text('إذا خرجت الآن، سيتم إلغاء عملية الدفع الحالية.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('البقاء'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('الخروج'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
// إذا وافق المستخدم على الخروج، قم بإغلاق الشاشة
|
||||
if (shouldPop ?? false) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// استخدام PopScope بدلاً من WillPopScope
|
||||
return PopScope(
|
||||
// منع الرجوع التلقائي فقط في حالة انتظار الدفع
|
||||
canPop: _status != PaymentStatus.waitingForPayment,
|
||||
// استدعاء دالة التحقق عند محاولة الرجوع
|
||||
onPopInvoked: _onPopInvoked,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(title: Text("الدفع عبر ${widget.providerName}")),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Center(
|
||||
child: _buildContentByStatus(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContentByStatus() {
|
||||
switch (_status) {
|
||||
case PaymentStatus.creatingInvoice:
|
||||
return const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 20),
|
||||
Text("جاري إنشاء فاتورة الدفع...", style: TextStyle(fontSize: 16)),
|
||||
],
|
||||
);
|
||||
case PaymentStatus.waitingForPayment:
|
||||
return _buildWaitingForPaymentUI();
|
||||
case PaymentStatus.paymentSuccess:
|
||||
return _buildSuccessUI();
|
||||
case PaymentStatus.paymentTimeout:
|
||||
case PaymentStatus.paymentError:
|
||||
return _buildErrorUI();
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildWaitingForPaymentUI() {
|
||||
final currencyFormat = NumberFormat.decimalPattern('ar_SY');
|
||||
final invoiceText = _invoiceNumber ?? '------';
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Image.asset(widget.providerLogo, width: 96),
|
||||
const SizedBox(height: 16),
|
||||
Text("تعليمات الدفع", style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 12),
|
||||
Card(
|
||||
elevation: 1.5,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_StepTile(number: 1, text: "افتح تطبيق محفظتك الإلكترونية."),
|
||||
_StepTile(number: 2, text: "اختر خدمة تحويل الأموال."),
|
||||
_StepTile(
|
||||
number: 3,
|
||||
text:
|
||||
"أدخل المبلغ المطلوب: ${currencyFormat.format(widget.amount)} ل.س"),
|
||||
_StepTile(number: 4, text: "حوّل إلى الرقم التالي:"),
|
||||
// --- التعديل هنا ---
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
widget.paymentPhoneNumber,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1.2),
|
||||
),
|
||||
trailing: OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: widget.paymentPhoneNumber));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("تم نسخ رقم الهاتف")));
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.copy, size: 18),
|
||||
label: const Text("نسخ"),
|
||||
),
|
||||
),
|
||||
// --- نهاية التعديل ---
|
||||
const SizedBox(height: 8),
|
||||
_StepTile(
|
||||
number: 5,
|
||||
text: "هام: انسخ رقم القسيمة والصقه في خانة \"البيان\"."),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(invoiceText,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1.5)),
|
||||
trailing: OutlinedButton.icon(
|
||||
onPressed: _invoiceNumber == null
|
||||
? null
|
||||
: () async {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: invoiceText));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("تم نسخ رقم القسيمة")));
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.copy, size: 18),
|
||||
label: const Text("نسخ"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const LinearProgressIndicator(minHeight: 2),
|
||||
const SizedBox(height: 12),
|
||||
Text("بانتظار تأكيد الدفع...",
|
||||
style: TextStyle(color: Colors.grey.shade700)),
|
||||
const SizedBox(height: 4),
|
||||
const Text("هذه الشاشة ستتحدث تلقائيًا",
|
||||
style: TextStyle(color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSuccessUI() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.check_circle, color: Colors.green, size: 80),
|
||||
const SizedBox(height: 20),
|
||||
const Text("تم الدفع بنجاح!",
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text("العودة"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorUI() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.error, color: Colors.red, size: 80),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
_status == PaymentStatus.paymentTimeout
|
||||
? "انتهى الوقت المحدد للدفع"
|
||||
: "حدث خطأ ما",
|
||||
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text("يرجى المحاولة مرة أخرى.", style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: _createAndPollInvoice,
|
||||
child: const Text("المحاولة مرة أخرى"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ويدجت مساعد لعرض خطوات التعليمات بشكل أنيق
|
||||
class _StepTile extends StatelessWidget {
|
||||
final int number;
|
||||
final String text;
|
||||
const _StepTile({required this.number, required this.text});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: CircleAvatar(
|
||||
radius: 12,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
child: Text("$number",
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold)),
|
||||
),
|
||||
title: Text(text),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user