306 lines
12 KiB
Dart
306 lines
12 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:SEFER/views/auth/sms_verfy_page.dart';
|
|
import 'package:animated_text_kit/animated_text_kit.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:SEFER/constant/box_name.dart';
|
|
import 'package:SEFER/constant/colors.dart';
|
|
import 'package:SEFER/constant/style.dart';
|
|
import 'package:SEFER/main.dart';
|
|
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
|
import 'package:SEFER/views/widgets/my_scafold.dart';
|
|
|
|
import '../../constant/info.dart';
|
|
import '../../constant/links.dart';
|
|
import '../../controller/auth/apple_signin_controller.dart';
|
|
import '../../controller/auth/google_sign.dart';
|
|
import '../../controller/auth/login_controller.dart';
|
|
import '../../controller/firebase/firbase_messge.dart';
|
|
import '../../controller/functions/crud.dart';
|
|
import '../../controller/functions/toast.dart';
|
|
import '../home/profile/passenger_profile_page.dart';
|
|
import '../widgets/mycircular.dart';
|
|
import 'register_page.dart';
|
|
|
|
class LoginPage extends StatelessWidget {
|
|
final controller = Get.put(LoginController());
|
|
final AuthController authController = Get.put(AuthController());
|
|
|
|
LoginPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Get.put(LoginController());
|
|
return GetBuilder<LoginController>(
|
|
builder: (controller) => MyScafolld(
|
|
title: 'Login'.tr,
|
|
isleading: false,
|
|
body: [
|
|
if (box.read(BoxName.agreeTerms) != 'agreed')
|
|
agreedPage()
|
|
else if (box.read(BoxName.countryCode) == null)
|
|
CountryPicker()
|
|
else if (box.read(BoxName.locationPermission) != 'true')
|
|
locationPermissionDialog()
|
|
else
|
|
SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
children: [
|
|
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,
|
|
),
|
|
Container(
|
|
decoration: AppStyle.boxDecoration1,
|
|
height: Get.height * .3,
|
|
width: Get.width * .8,
|
|
child: Center(
|
|
child: Text(
|
|
'Sign in with Google for easier email and name entry'
|
|
.tr,
|
|
textAlign: TextAlign.center,
|
|
style: AppStyle.title,
|
|
),
|
|
),
|
|
),
|
|
MyElevatedButton(
|
|
title: 'Sign In by Google'.tr,
|
|
onPressed: () async {
|
|
await GoogleSignInHelper.signInFromLogin();
|
|
},
|
|
kolor: AppColor.blueColor,
|
|
),
|
|
!Platform.isAndroid
|
|
? Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(
|
|
Icons.apple,
|
|
size: 30,
|
|
),
|
|
const SizedBox(
|
|
width: 8), // Adjust spacing as needed
|
|
MyElevatedButton(
|
|
title: 'Sign in with Apple'.tr,
|
|
onPressed: () async {
|
|
try {
|
|
User? user = await authController
|
|
.signInWithApple();
|
|
if (user != null) {
|
|
box.write(
|
|
BoxName.driverID, user.uid);
|
|
box.write(BoxName.emailDriver,
|
|
user.email);
|
|
|
|
// Provide user feedback
|
|
await GoogleSignInHelper
|
|
.signInFromLogin();
|
|
Navigator.of(context)
|
|
.pushReplacementNamed('/home');
|
|
Toast.show(
|
|
context,
|
|
'Signed in successfully',
|
|
AppColor.greenColor);
|
|
} else {
|
|
Toast.show(
|
|
context,
|
|
'Sign in failed. Please try again.',
|
|
AppColor.yellowColor);
|
|
}
|
|
} catch (error) {
|
|
print('Sign in error: $error');
|
|
Toast.show(
|
|
context,
|
|
'An error occurred. Please check your connection and try again.',
|
|
AppColor.redColor);
|
|
}
|
|
},
|
|
kolor: Colors.black,
|
|
),
|
|
],
|
|
)
|
|
: const SizedBox(),
|
|
],
|
|
),
|
|
)),
|
|
SizedBox(
|
|
height: Get.height * .1,
|
|
),
|
|
// Text(
|
|
// 'if you dont have account'.tr,
|
|
// style: AppStyle.subtitle,
|
|
// ),
|
|
// AnimatedTextKit(
|
|
// onTap: () => Get.to(() => SmsSignupEgypt()),
|
|
// animatedTexts: [
|
|
// TypewriterAnimatedText(
|
|
// 'Register'.tr,
|
|
// textStyle: AppStyle.headTitle2,
|
|
// speed: const Duration(milliseconds: 200),
|
|
// ),
|
|
// ],
|
|
// totalRepeatCount: 4,
|
|
// pause: const Duration(milliseconds: 200),
|
|
// displayFullTextOnTap: true,
|
|
// stopPauseOnTap: true,
|
|
// ),
|
|
// const Spacer(),
|
|
const SizedBox(
|
|
height: 100,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Padding agreedPage() {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: SingleChildScrollView(
|
|
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<LoginController>(
|
|
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<LoginController>(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 use location to get accurate and nearest driver for you'
|
|
.tr,
|
|
textAlign: TextAlign.center,
|
|
style: AppStyle.title,
|
|
),
|
|
MyElevatedButton(
|
|
title: 'Next'.tr,
|
|
onPressed: () async {
|
|
await controller.getLocationPermission();
|
|
},
|
|
kolor: AppColor.greenColor,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|