712 lines
36 KiB
Dart
712 lines
36 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:sefer_driver/views/auth/captin/contact_us_page.dart';
|
|
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 '../../../constant/box_name.dart';
|
|
import '../../../constant/colors.dart';
|
|
import '../../../constant/info.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 '../../../controller/functions/encrypt_decrypt.dart';
|
|
import '../../../controller/functions/overlay_permisssion.dart';
|
|
import '../../../main.dart';
|
|
import '../../../print.dart';
|
|
import '../../widgets/elevated_btn.dart';
|
|
import '../../widgets/my_scafold.dart';
|
|
import '../../widgets/mycircular.dart';
|
|
import '../country_widget.dart';
|
|
|
|
class LoginCaptin extends StatelessWidget {
|
|
// final controller = Get.put(LoginCaptinController());
|
|
|
|
LoginCaptin({super.key});
|
|
final AuthController authController = Get.put(AuthController());
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Get.put(LoginDriverController());
|
|
// Get.put(LocationBackgroundController());
|
|
return GetBuilder<LoginDriverController>(
|
|
builder: (controller) => MyScafolld(
|
|
title: 'Login Driver'.tr,
|
|
isleading: false,
|
|
body: [
|
|
if (box.read(BoxName.agreeTerms).toString() != 'agreed')
|
|
agreedPage()
|
|
else if (box.read(BoxName.countryCode) == null)
|
|
CountryPicker()
|
|
else if (box.read(BoxName.locationPermission) != 'true')
|
|
locationPermissionDialog()
|
|
else
|
|
SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
controller.isGoogleDashOpen
|
|
? registerWitoutGoogle(controller)
|
|
: Padding(
|
|
padding: const EdgeInsets.all(25),
|
|
child: Center(
|
|
child: Container(
|
|
decoration: AppStyle.boxDecoration1,
|
|
height: Get.height * .7,
|
|
width: Get.width * .9,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Image.asset(
|
|
'assets/images/logo.gif',
|
|
height: Get.width * .3,
|
|
width: Get.width * .3,
|
|
fit: BoxFit.fill,
|
|
),
|
|
Platform.isIOS && controller.isTest == 0
|
|
? Container(
|
|
decoration: AppStyle.boxDecoration,
|
|
child: Column(
|
|
children: [
|
|
Form(
|
|
key: controller.formKey,
|
|
child: Padding(
|
|
padding:
|
|
const EdgeInsets.all(16.0),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
TextFormField(
|
|
keyboardType:
|
|
TextInputType
|
|
.emailAddress,
|
|
controller: controller
|
|
.emailController,
|
|
decoration:
|
|
InputDecoration(
|
|
focusedBorder:
|
|
OutlineInputBorder(
|
|
borderSide:
|
|
const BorderSide(
|
|
color: AppColor
|
|
.primaryColor,
|
|
width: 2.0,
|
|
),
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(
|
|
10),
|
|
),
|
|
fillColor: AppColor
|
|
.accentColor,
|
|
hoverColor: AppColor
|
|
.accentColor,
|
|
focusColor: AppColor
|
|
.accentColor,
|
|
border: const OutlineInputBorder(
|
|
borderRadius: BorderRadius
|
|
.all(Radius
|
|
.circular(
|
|
12))),
|
|
labelText: 'Email'.tr,
|
|
hintText:
|
|
'Enter your email address'
|
|
.tr,
|
|
),
|
|
validator: (value) {
|
|
if (value!.isEmpty ||
|
|
(!value.contains(
|
|
'@') ||
|
|
!value.contains(
|
|
'.'))) {
|
|
return 'Please enter Your Email.'
|
|
.tr;
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
const SizedBox(
|
|
height: 15,
|
|
),
|
|
TextFormField(
|
|
obscureText: true,
|
|
keyboardType:
|
|
TextInputType
|
|
.emailAddress,
|
|
controller: controller
|
|
.passwordController,
|
|
decoration:
|
|
InputDecoration(
|
|
focusedBorder:
|
|
OutlineInputBorder(
|
|
borderSide:
|
|
const BorderSide(
|
|
color: AppColor
|
|
.primaryColor,
|
|
width: 2.0,
|
|
),
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(
|
|
10),
|
|
),
|
|
fillColor: AppColor
|
|
.accentColor,
|
|
hoverColor: AppColor
|
|
.accentColor,
|
|
focusColor: AppColor
|
|
.accentColor,
|
|
border: const OutlineInputBorder(
|
|
borderRadius: BorderRadius
|
|
.all(Radius
|
|
.circular(
|
|
12))),
|
|
labelText:
|
|
'Password'.tr,
|
|
hintText:
|
|
'Please enter your phone number.'
|
|
.tr,
|
|
),
|
|
validator: (value) {
|
|
if (value!.isEmpty) {
|
|
return 'Please enter Your Password.'
|
|
.tr;
|
|
}
|
|
if (value.length <
|
|
6) {
|
|
return 'Password must br at least 6 character.'
|
|
.tr;
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
GetBuilder<
|
|
LoginDriverController>(
|
|
builder: (controller) =>
|
|
controller.isloading
|
|
? const MyCircularProgressIndicator()
|
|
: MyElevatedButton(
|
|
onPressed:
|
|
() async {
|
|
if (controller
|
|
.formKey
|
|
.currentState!
|
|
.validate()) {
|
|
await Get.find<LoginDriverController>()
|
|
.loginWithGoogleCredential(
|
|
controller
|
|
.passwordController
|
|
.text,
|
|
controller
|
|
.emailController
|
|
.text,
|
|
);
|
|
}
|
|
},
|
|
title:
|
|
'Submit'
|
|
.tr,
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 10,
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: Container(
|
|
decoration: AppStyle.boxDecoration1,
|
|
height: Get.height * .3,
|
|
width: Get.width * .8,
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Text(
|
|
'Sign in with Google for easier email and name entry'
|
|
.tr,
|
|
textAlign: TextAlign.center,
|
|
style: AppStyle.title,
|
|
),
|
|
Text(
|
|
'Or'.tr,
|
|
textAlign: TextAlign.center,
|
|
style: AppStyle.title,
|
|
),
|
|
GestureDetector(
|
|
onTap: () async {
|
|
controller
|
|
.changeGoogleDashOpen();
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets
|
|
.symmetric(
|
|
horizontal: 16,
|
|
vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: AppColor.blueColor,
|
|
borderRadius:
|
|
BorderRadius.circular(
|
|
8),
|
|
),
|
|
child: Row(
|
|
mainAxisSize:
|
|
MainAxisSize.min,
|
|
children: [
|
|
const Icon(
|
|
Icons.email,
|
|
color: AppColor
|
|
.yellowColor,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
'Create new Account'.tr,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight:
|
|
FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () async {
|
|
await GoogleSignInHelper()
|
|
.signInFromLogin();
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: AppColor.redColor,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(
|
|
FontAwesome.google,
|
|
color: AppColor.blueColor,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
'Sign In by Google'.tr,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
!Platform.isAndroid
|
|
? GestureDetector(
|
|
onTap: () async {
|
|
User? user = await authController
|
|
.signInWithApple();
|
|
if (user != null) {
|
|
box.write(BoxName.emailDriver,
|
|
(user.email.toString()));
|
|
|
|
box.write(
|
|
BoxName.driverID, user.uid);
|
|
|
|
Get.find<LoginDriverController>()
|
|
.loginWithGoogleCredential(
|
|
box
|
|
.read(BoxName.driverID)
|
|
.toString(),
|
|
EncryptionHelper.instance
|
|
.encryptData(box
|
|
.read(BoxName.emailDriver)
|
|
.toString()),
|
|
);
|
|
// Navigate to another screen or perform other actions
|
|
} else {}
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black,
|
|
borderRadius:
|
|
BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(
|
|
Icons.apple,
|
|
color: Colors.white,
|
|
size: 24,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
'Sign in with Apple'.tr,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: const SizedBox(),
|
|
],
|
|
),
|
|
))),
|
|
GestureDetector(
|
|
onTap: () => Get.to(() => ContactUsPage()),
|
|
child: Text(
|
|
'If you need assistance, contact us'
|
|
.tr, // Improved wording
|
|
style: AppStyle.subtitle,
|
|
),
|
|
),
|
|
// GestureDetector(
|
|
// onTap: () async {
|
|
// await storage.deleteAll();
|
|
// box.erase();
|
|
// },
|
|
// child: Padding(
|
|
// padding: const EdgeInsets.all(8.0),
|
|
// child: Text(
|
|
// 'erase'.tr, // Improved wording
|
|
// style: AppStyle.subtitle,
|
|
// ),
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Column registerWitoutGoogle(LoginDriverController controller) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Form(
|
|
key: controller.formKey,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: TextFormField(
|
|
obscureText: false, // Email should not be obscured
|
|
keyboardType: TextInputType.emailAddress,
|
|
controller: controller.emailController,
|
|
decoration: InputDecoration(
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: const BorderSide(
|
|
color: AppColor.primaryColor,
|
|
width: 2.0,
|
|
),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
fillColor: AppColor.accentColor,
|
|
hoverColor: AppColor.accentColor,
|
|
focusColor: AppColor.accentColor,
|
|
border: const OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
),
|
|
labelText: 'Email'
|
|
.tr, // English: Email / Arabic: البريد الإلكتروني
|
|
hintText: 'Please enter your Email.'
|
|
.tr, // English: Please enter your Email / Arabic: يرجى إدخال بريدك الإلكتروني
|
|
),
|
|
validator: (value) {
|
|
if (value!.isEmpty) {
|
|
return 'Please enter your Email.'
|
|
.tr; // English: Please enter your Email / Arabic: يرجى إدخال بريدك الإلكتروني
|
|
}
|
|
if (!value.contains('@')) {
|
|
return 'Email must be correct.'
|
|
.tr; // English: Email must be correct / Arabic: البريد الإلكتروني يجب أن يكون صحيحاً
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: TextFormField(
|
|
obscureText: true, // Password should be obscured
|
|
keyboardType: TextInputType.text,
|
|
controller: controller.passwordController,
|
|
decoration: InputDecoration(
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: const BorderSide(
|
|
color: AppColor.primaryColor,
|
|
width: 2.0,
|
|
),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
fillColor: AppColor.accentColor,
|
|
hoverColor: AppColor.accentColor,
|
|
focusColor: AppColor.accentColor,
|
|
border: const OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
),
|
|
labelText: 'Password'
|
|
.tr, // English: Password / Arabic: كلمة المرور
|
|
hintText: 'Please enter your Password.'
|
|
.tr, // English: Please enter your Password / Arabic: يرجى إدخال كلمة المرور
|
|
),
|
|
validator: (value) {
|
|
if (value!.isEmpty) {
|
|
return 'Please enter your Password.'
|
|
.tr; // English: Please enter your Password / Arabic: يرجى إدخال كلمة المرور
|
|
}
|
|
if (value.length < 6) {
|
|
return 'Password must be at least 6 characters.'
|
|
.tr; // English: Password must be at least 6 characters / Arabic: يجب أن تكون كلمة المرور مكونة من 6 أحرف على الأقل
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
),
|
|
controller.isloading
|
|
? const MyCircularProgressIndicator()
|
|
: MyElevatedButton(
|
|
onPressed: () {
|
|
if (controller.formKey.currentState!.validate()) {
|
|
String email = controller.emailController
|
|
.text; // Assume you have this controller
|
|
String uniqueId =
|
|
controller.generateUniqueIdFromEmail(email);
|
|
Log.print('Generated ID: $uniqueId');
|
|
box.write(BoxName.driverID, uniqueId);
|
|
box.write(BoxName.emailDriver,
|
|
controller.emailController.text.toString());
|
|
controller.loginUsingCredentialsWithoutGoogle(
|
|
controller.passwordController.text.toString(),
|
|
controller.emailController.text.toString(),
|
|
);
|
|
}
|
|
},
|
|
title: 'Next'.tr,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 200,
|
|
),
|
|
GestureDetector(
|
|
onTap: () async {
|
|
await GoogleSignInHelper().signInFromLogin();
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: AppColor.redColor,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(
|
|
FontAwesome.google,
|
|
color: AppColor.blueColor,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
'Sign In by Google'.tr,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Padding agreedPage() {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Image.asset(
|
|
'assets/images/notepad.png',
|
|
width: Get.width * .2,
|
|
),
|
|
SizedBox(
|
|
width: Get.width * .7,
|
|
child: Text(
|
|
'Accept Ride\'s Terms & Review Privacy Notice'.tr,
|
|
style: AppStyle.headTitle2,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 30,
|
|
),
|
|
RichText(
|
|
text: TextSpan(
|
|
text:
|
|
"By selecting 'I Agree' below, I have reviewed and agree to the Terms of Use and acknowledge the "
|
|
.tr,
|
|
style: AppStyle.title,
|
|
children: <TextSpan>[
|
|
TextSpan(
|
|
text: 'Privacy Notice'.tr,
|
|
style: const TextStyle(
|
|
decoration: TextDecoration.underline,
|
|
color: AppColor.blueColor),
|
|
recognizer: TapGestureRecognizer()
|
|
..onTap = () {
|
|
Get.defaultDialog(
|
|
title: ''.tr,
|
|
content: const SizedBox(
|
|
height: 400,
|
|
width: 400,
|
|
child: SingleChildScrollView(
|
|
child: HtmlWidget(AppInformation.privacyPolicy),
|
|
),
|
|
));
|
|
}),
|
|
TextSpan(
|
|
text: '. I am at least 18 years of age.'.tr,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 100,
|
|
),
|
|
GetBuilder<LoginDriverController>(
|
|
builder: (controller) => Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Checkbox.adaptive(
|
|
autofocus: true,
|
|
tristate: true,
|
|
splashRadius: 25,
|
|
activeColor: AppColor.primaryColor,
|
|
value: controller.isAgreeTerms,
|
|
onChanged: (value) => controller.changeAgreeTerm(),
|
|
),
|
|
Text(
|
|
'I Agree'.tr,
|
|
style: controller.isAgreeTerms
|
|
? AppStyle.title
|
|
: AppStyle.title
|
|
.copyWith(color: AppColor.accentColor),
|
|
),
|
|
],
|
|
),
|
|
MyElevatedButton(
|
|
title: 'Submit'.tr,
|
|
onPressed: () => controller.saveAgreementTerms()),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
locationPermissionDialog() {
|
|
return GetBuilder<LoginDriverController>(builder: (controller) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Container(
|
|
height: Get.height * .4,
|
|
decoration: AppStyle.boxDecoration1,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Center(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Text(
|
|
'We need access to your location to match you with nearby passengers and ensure accurate navigation.'
|
|
.tr,
|
|
textAlign: TextAlign.center,
|
|
style: AppStyle.title,
|
|
),
|
|
Text(
|
|
'Please allow location access at all times to receive ride requests and ensure smooth service.'
|
|
.tr,
|
|
textAlign: TextAlign.center,
|
|
style: AppStyle.title.copyWith(color: AppColor.greenColor),
|
|
),
|
|
MyElevatedButton(
|
|
title: "Allow Location Access".tr,
|
|
onPressed: () async {
|
|
// Request location permissions
|
|
PermissionStatus status =
|
|
await Permission.location.status;
|
|
|
|
if (!status.isGranted) {
|
|
getLocationPermission(); // Function to request permission
|
|
return;
|
|
}
|
|
|
|
// Save permission status to local storage
|
|
box.write(BoxName.locationPermission, 'true');
|
|
controller.update();
|
|
},
|
|
kolor: AppColor.greenColor,
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
// Optionally, navigate to app settings for manual permission control
|
|
openAppSettings();
|
|
},
|
|
child: Text(
|
|
"Open Settings".tr,
|
|
style: const TextStyle(color: AppColor.blueColor),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|