- GeminiService (integrations/gemini, @Global): extractDocument (OCR fields) + faceMatch; graceful if no GEMINI_API_KEY - documents: face-match now real via Gemini; POST /admin/documents/:id/ocr extracts fields for CS auto-fill - roles: PATCH /admin/users/:id/role (admin) + POST /platform/users/role (bootstrap via x-platform-secret) - config: gemini + platform.secret; .env.example entries Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
560 lines
19 KiB
Dart
Executable File
560 lines
19 KiB
Dart
Executable File
import 'dart:io';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_font_icons/flutter_font_icons.dart';
|
|
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
// تأكد من صحة المسارات في مشروعك
|
|
import '../../../constant/box_name.dart';
|
|
import '../../../constant/colors.dart';
|
|
import '../../../constant/info.dart';
|
|
import '../../../constant/links.dart';
|
|
import '../../../constant/style.dart';
|
|
import '../../../controller/auth/apple_sigin.dart';
|
|
import '../../../controller/auth/captin/login_captin_controller.dart';
|
|
import '../../../controller/auth/google_sign.dart';
|
|
import '../../../main.dart';
|
|
import 'contact_us_page.dart';
|
|
// import 'otp_page.dart';
|
|
|
|
class LoginCaptin extends StatefulWidget {
|
|
const LoginCaptin({super.key});
|
|
|
|
@override
|
|
State<LoginCaptin> createState() => _LoginCaptinState();
|
|
}
|
|
|
|
class _LoginCaptinState extends State<LoginCaptin> with WidgetsBindingObserver {
|
|
final AuthController authController = Get.put(AuthController());
|
|
final LoginDriverController controller = Get.put(LoginDriverController());
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
controller.getLocationPermission();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
if (state == AppLifecycleState.resumed) {
|
|
controller.getLocationPermission();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetBuilder<LoginDriverController>(
|
|
builder: (controller) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white, // خلفية نظيفة
|
|
body: SafeArea(
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: _buildBodyContent(context, controller),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildBodyContent(
|
|
BuildContext context, LoginDriverController controller) {
|
|
// 1. صفحة الشروط
|
|
if (box.read(BoxName.agreeTerms) != 'agreed') {
|
|
return _buildAgreementPage(context, controller);
|
|
}
|
|
|
|
// 2. صفحة إذن الموقع
|
|
if (box.read(BoxName.locationPermission) != 'true') {
|
|
return _buildLocationPermissionPage(context, controller);
|
|
}
|
|
|
|
// 3. صفحة تسجيل الدخول (التصميم الجديد)
|
|
return Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
child: _buildSocialLoginOptions(context, controller),
|
|
),
|
|
);
|
|
}
|
|
|
|
// --- 1. Agreement Page ---
|
|
Widget _buildAgreementPage(
|
|
BuildContext context, LoginDriverController controller) {
|
|
return Column(
|
|
children: [
|
|
const SizedBox(height: 20),
|
|
// Header ثابت
|
|
const Icon(Icons.policy_outlined,
|
|
size: 50, color: AppColor.primaryColor),
|
|
const SizedBox(height: 10),
|
|
Text('Driver Agreement'.tr,
|
|
textAlign: TextAlign.center, style: AppStyle.headTitle2),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
// منطقة المحتوى القابلة للتمرير (Expanded لتأخذ المساحة المتبقية)
|
|
Expanded(
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[50],
|
|
border: Border.all(color: Colors.grey.shade300),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Scrollbar(
|
|
thumbVisibility: true,
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: HtmlWidget(
|
|
box.read(BoxName.lang).toString() == 'ar'
|
|
? AppInformation.privacyPolicyArabic
|
|
: AppInformation.privacyPolicy,
|
|
textStyle: const TextStyle(
|
|
fontSize: 14, height: 1.6), // تنسيق نص مريح
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
// منطقة الإجراءات السفلية
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, -5),
|
|
)
|
|
],
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
CheckboxListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: Text(
|
|
'I have read and agree to the Terms of Use and Privacy Policy'
|
|
.tr,
|
|
style: const TextStyle(
|
|
fontSize: 14, fontWeight: FontWeight.w600),
|
|
),
|
|
value: controller.isAgreeTerms,
|
|
onChanged: (value) => controller.changeAgreeTerm(),
|
|
activeColor: AppColor.primaryColor,
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
),
|
|
const SizedBox(height: 10),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 50,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColor.primaryColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
elevation: 0,
|
|
),
|
|
onPressed: controller.isAgreeTerms
|
|
? () => controller.saveAgreementTerms()
|
|
: null,
|
|
child: Text(
|
|
'Accept & Continue'.tr,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// --- 2. Location Permission Page ---
|
|
Widget _buildLocationPermissionPage(
|
|
BuildContext context, LoginDriverController controller) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(30.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Image.asset('assets/images/map.png',
|
|
height: 150,
|
|
errorBuilder: (c, o, s) => const Icon(Icons.location_on,
|
|
size: 100, color: AppColor.primaryColor)),
|
|
const SizedBox(height: 30),
|
|
Text(
|
|
'Enable Location'.tr,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'We need your location to receive nearby ride requests and navigation.'
|
|
.tr,
|
|
textAlign: TextAlign.center,
|
|
style:
|
|
TextStyle(color: Colors.grey[600], fontSize: 16, height: 1.5),
|
|
),
|
|
const SizedBox(height: 40),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 50,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColor.greenColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
),
|
|
onPressed: () async {
|
|
box.write(BoxName.locationPermission, 'true');
|
|
controller.update();
|
|
var status = await Permission.location.request();
|
|
if (status.isGranted) {
|
|
var bgStatus = await Permission.locationAlways.request();
|
|
if (bgStatus.isGranted) {
|
|
// Granted
|
|
}
|
|
} else if (status.isPermanentlyDenied) {
|
|
openAppSettings();
|
|
}
|
|
controller.update();
|
|
},
|
|
child: Text("Allow Access".tr,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold)),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () => openAppSettings(),
|
|
child: Text("Open Settings".tr,
|
|
style: const TextStyle(color: Colors.grey)),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// --- 3. Social Login Options (RE-DESIGNED) ---
|
|
Widget _buildSocialLoginOptions(
|
|
BuildContext context, LoginDriverController controller) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
// Header Logo
|
|
InkWell(
|
|
onLongPress: () {
|
|
_showTesterLoginDialog(context);
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.white,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
blurRadius: 20,
|
|
offset: const Offset(0, 5))
|
|
]),
|
|
child: Image.asset('assets/images/logo.gif',
|
|
height: 80, width: 80, fit: BoxFit.contain),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Text(
|
|
'Welcome Captain!'.tr,
|
|
style: const TextStyle(
|
|
fontSize: 26, fontWeight: FontWeight.bold, color: Colors.black87),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Login to manage your rides and earnings'.tr,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[600]),
|
|
),
|
|
const SizedBox(height: 40),
|
|
|
|
// Google Button
|
|
_buildSocialCard(
|
|
label: 'Continue with Google'.tr,
|
|
icon: FontAwesome.google,
|
|
iconColor: Colors.red,
|
|
onTap: () {
|
|
GoogleSignInHelper().signInFromLogin();
|
|
},
|
|
),
|
|
|
|
// Apple Button (IOS Only)
|
|
if (Platform.isIOS) ...[
|
|
const SizedBox(height: 16),
|
|
_buildSocialCard(
|
|
label: 'Continue with Apple'.tr,
|
|
icon: FontAwesome.apple,
|
|
iconColor: Colors.black,
|
|
onTap: () async {
|
|
User? user = await authController.signInWithApple();
|
|
if (user != null) {
|
|
box.write(BoxName.emailDriver, user.email.toString());
|
|
box.write(BoxName.driverID, user.uid);
|
|
controller.loginWithGoogleCredential(
|
|
user.uid,
|
|
user.email.toString(),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
// Divider
|
|
Row(
|
|
children: [
|
|
Expanded(child: Divider(color: Colors.grey[300])),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text("OR".tr,
|
|
style: TextStyle(
|
|
color: Colors.grey[400],
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold)),
|
|
),
|
|
Expanded(child: Divider(color: Colors.grey[300])),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
// Manual Email Button
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 55,
|
|
child: OutlinedButton(
|
|
onPressed: () => controller.isPhoneVerified(),
|
|
style: OutlinedButton.styleFrom(
|
|
side: BorderSide(color: AppColor.primaryColor.withOpacity(0.5)),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
),
|
|
child: Text(
|
|
'Use Email & Password'.tr,
|
|
style: const TextStyle(
|
|
color: AppColor.primaryColor,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 40),
|
|
|
|
// Support Link
|
|
GestureDetector(
|
|
onTap: () => Get.to(() => ContactUsPage()),
|
|
child: Text(
|
|
'Need help? Contact Support'.tr,
|
|
style: TextStyle(
|
|
color: Colors.grey[500],
|
|
fontSize: 13,
|
|
decoration: TextDecoration.underline),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// Helper Widget for Social Cards
|
|
Widget _buildSocialCard({
|
|
required String label,
|
|
required IconData icon,
|
|
required Color iconColor,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.grey.shade300),
|
|
borderRadius: BorderRadius.circular(12),
|
|
color: Colors.white,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.05),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, color: iconColor, size: 24),
|
|
const SizedBox(width: 24),
|
|
Expanded(
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
),
|
|
const Icon(Icons.arrow_forward_ios_rounded,
|
|
size: 16, color: Colors.grey),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showTesterLoginDialog(BuildContext context) {
|
|
final controller = Get.put(LoginDriverController());
|
|
final emailController = TextEditingController();
|
|
final passwordController = TextEditingController();
|
|
final formKey = GlobalKey<FormState>();
|
|
|
|
showGeneralDialog(
|
|
context: context,
|
|
barrierDismissible: true,
|
|
barrierLabel: '',
|
|
transitionDuration: const Duration(milliseconds: 300),
|
|
pageBuilder: (ctx, anim1, anim2) => Container(),
|
|
transitionBuilder: (ctx, anim1, anim2, child) {
|
|
return ScaleTransition(
|
|
scale: CurvedAnimation(parent: anim1, curve: Curves.easeOutBack),
|
|
child: AlertDialog(
|
|
shape:
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
backgroundColor: Colors.white,
|
|
surfaceTintColor: Colors.white,
|
|
title: Column(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: AppColor.primaryColor.withOpacity(0.1),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(Icons.admin_panel_settings_rounded,
|
|
color: AppColor.primaryColor, size: 30),
|
|
),
|
|
const SizedBox(height: 10),
|
|
const Text(
|
|
'Tester Access',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColor.writeColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
content: Form(
|
|
key: formKey,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextFormField(
|
|
controller: emailController,
|
|
style: const TextStyle(color: AppColor.writeColor),
|
|
decoration: InputDecoration(
|
|
labelText: 'Tester Email',
|
|
prefixIcon:
|
|
const Icon(Icons.email_outlined, color: Colors.grey),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide:
|
|
const BorderSide(color: AppColor.primaryColor),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 12),
|
|
),
|
|
validator: (v) => v!.contains('@') ? null : 'Invalid Email',
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: passwordController,
|
|
style: const TextStyle(color: AppColor.writeColor),
|
|
obscureText: true,
|
|
decoration: InputDecoration(
|
|
labelText: 'Password',
|
|
prefixIcon:
|
|
const Icon(Icons.lock_outline, color: Colors.grey),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
borderSide:
|
|
const BorderSide(color: AppColor.primaryColor),
|
|
),
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 12),
|
|
),
|
|
validator: (v) => v!.isEmpty ? 'Required' : null,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Get.back(),
|
|
child: Text('Cancel',
|
|
style: TextStyle(color: Colors.grey.shade600)),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColor.primaryColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10)),
|
|
elevation: 0,
|
|
),
|
|
onPressed: () {
|
|
if (formKey.currentState!.validate()) {
|
|
controller.logintest(
|
|
passwordController.text.trim(),
|
|
emailController.text.trim(),
|
|
);
|
|
Get.back();
|
|
}
|
|
},
|
|
child:
|
|
const Text('Login', style: TextStyle(color: Colors.white)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|