476 lines
20 KiB
Dart
476 lines
20 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:flutter_svg/flutter_svg.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:regroup/Common/base_manager.dart';
|
||
import 'package:regroup/Login/ViewModel/LoginApi.dart';
|
||
import 'package:regroup/Utils/Common/CustomNextButton.dart';
|
||
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
|
||
import 'package:regroup/Utils/Common/sized_box.dart';
|
||
import 'package:regroup/Utils/texts.dart';
|
||
import 'package:regroup/resources/routes/route_name.dart';
|
||
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
|
||
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||
import 'package:regroup/Common/global.dart' as global;
|
||
// import 'package:regroup/Common/global.dart' as global;
|
||
|
||
class LoginScreen extends StatefulWidget {
|
||
const LoginScreen({super.key});
|
||
|
||
@override
|
||
State<LoginScreen> createState() => _LoginScreenState();
|
||
}
|
||
|
||
class _LoginScreenState extends State<LoginScreen> {
|
||
Map<String, dynamic>? _userData;
|
||
AccessToken? _accessToken;
|
||
bool _checking = true;
|
||
final TextEditingController _emailController = TextEditingController();
|
||
RxBool isObscured = true.obs;
|
||
final TextEditingController _passwordController = TextEditingController();
|
||
// final GlobalKey<FormState> _form = GlobalKey<FormState>();
|
||
|
||
// RxString errormsg = ''.obs;
|
||
// RxString errormsgpass = ''.obs;
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
|
||
super.initState();
|
||
}
|
||
|
||
_checkIfisLoggedIn() async {
|
||
//user token
|
||
final accessToken = await FacebookAuth.instance.accessToken;
|
||
|
||
setState(() {
|
||
_checking = false;
|
||
});
|
||
|
||
if (accessToken != null) {
|
||
print("/////////////////////////////////////////check");
|
||
print("worked");
|
||
print(accessToken.toJson());
|
||
final userData = await FacebookAuth.instance.getUserData();
|
||
_accessToken = accessToken;
|
||
setState(() {
|
||
_userData = userData;
|
||
});
|
||
} else {
|
||
print("/////////////////////////////////////////check");
|
||
|
||
print("not worked");
|
||
_login();
|
||
}
|
||
}
|
||
|
||
_login() async {
|
||
final LoginResult result = await FacebookAuth.instance.login();
|
||
|
||
if (result.status == LoginStatus.success) {
|
||
_accessToken = result.accessToken;
|
||
|
||
final userData = await FacebookAuth.instance.getUserData();
|
||
_userData = userData;
|
||
} else {
|
||
print(result.status);
|
||
print(result.message);
|
||
}
|
||
setState(() {
|
||
_checking = false;
|
||
});
|
||
}
|
||
|
||
_logout() async {
|
||
await FacebookAuth.instance.logOut();
|
||
_accessToken = null;
|
||
_userData = null;
|
||
setState(() {});
|
||
}
|
||
|
||
_logincheck() async {
|
||
if (_emailController.text.isBlank! || _passwordController.text.isBlank!) {
|
||
Get.snackbar(
|
||
'Error',
|
||
'Enter your credentials',
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
backgroundColor: Colors.red,
|
||
colorText: Colors.white,
|
||
);
|
||
} else if (!_emailController.text.isEmail) {
|
||
Get.snackbar(
|
||
'Error',
|
||
'Enter a valid e-mail address',
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
backgroundColor: Colors.red,
|
||
colorText: Colors.white,
|
||
);
|
||
} else {
|
||
Map<String, String> updata = {
|
||
"email_address": _emailController.text,
|
||
"password": _passwordController.text,
|
||
// "access-token" : ""
|
||
//
|
||
// "player_id": global.player_id!,
|
||
};
|
||
final data = await LoginAPI().loginApi(updata);
|
||
if (data.status == ResponseStatus.SUCCESS) {
|
||
// await global.setname();
|
||
Get.snackbar(
|
||
"Success!",
|
||
'Login successful!',
|
||
duration: Duration(seconds: 2),
|
||
colorText: Colors.white,
|
||
backgroundColor: Colors.green,
|
||
margin: EdgeInsets.all(8),
|
||
snackStyle: SnackStyle.FLOATING,
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
);
|
||
|
||
Get.toNamed(RouteName.mainscreen);
|
||
} else if (data.status == ResponseStatus.FAILED) {
|
||
Get.snackbar(
|
||
"Error!",
|
||
data.message,
|
||
duration: Duration(seconds: 2),
|
||
colorText: Colors.white,
|
||
backgroundColor: Colors.red,
|
||
margin: EdgeInsets.all(8),
|
||
snackStyle: SnackStyle.FLOATING,
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
);
|
||
// _controller.isTextFieldEnabled.value = true;
|
||
} else {
|
||
// btnController.reset();
|
||
Get.snackbar(
|
||
"Error!",
|
||
data.data['message'],
|
||
duration: Duration(seconds: 2),
|
||
colorText: Colors.white,
|
||
backgroundColor: Colors.red,
|
||
margin: EdgeInsets.all(8),
|
||
snackStyle: SnackStyle.FLOATING,
|
||
snackPosition: SnackPosition.BOTTOM,
|
||
);
|
||
// _controller.isTextFieldEnabled.value = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
resizeToAvoidBottomInset:
|
||
false, // Prevent resizing when the keyboard opens
|
||
backgroundColor: const Color.fromARGB(255, 18, 32, 47),
|
||
body: Stack(
|
||
clipBehavior: Clip.none,
|
||
children: [
|
||
Container(
|
||
decoration: const BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage("assets/images/png/Choice screen.png"),
|
||
fit: BoxFit.cover)),
|
||
),
|
||
Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
SizedBox(
|
||
height: 150.h,
|
||
),
|
||
Padding(
|
||
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
||
child: Align(
|
||
alignment: Alignment.center,
|
||
child: Container(
|
||
width: 107.w,
|
||
height: 70.h,
|
||
child: SvgPicture.asset(
|
||
"assets/images/svg/onboarding2.svg",
|
||
fit: BoxFit.cover,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
sizedBoxHeight(20.h),
|
||
Align(
|
||
alignment: Alignment.center,
|
||
child: text22400FCFCFC("Find your community")),
|
||
sizedBoxHeight(40.h),
|
||
Expanded(
|
||
child: Padding(
|
||
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
text16400white('Email address'),
|
||
sizedBoxHeight(10.h),
|
||
CustomTextFormField(
|
||
textEditingController: _emailController,
|
||
hintText: "Enter your email address",
|
||
leadingIcon:
|
||
// const Icon(Icons.mail_outline),
|
||
SizedBox(
|
||
width: 22.w,
|
||
height: 17.h,
|
||
child: Image.asset(
|
||
'assets/images/png/mail.png',
|
||
width: 22.w,
|
||
height: 17.h,
|
||
),
|
||
),
|
||
// validationMessage: errormsg.value,
|
||
validator: (value) {
|
||
if (value!.isEmpty) {
|
||
return 'Enter your e-mail address';
|
||
}
|
||
if (!RegExp(
|
||
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
|
||
.hasMatch(value)) {
|
||
return 'Enter a valid e-mail address';
|
||
}
|
||
return null;
|
||
},
|
||
// onInput: (p0) {
|
||
// if (p0!.isEmpty) {
|
||
// errormsg.value = 'Enter your e-mail address';
|
||
// }
|
||
// if (!RegExp(
|
||
// r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
|
||
// .hasMatch(p0!)) {
|
||
// errormsg.value = 'Enter a valid e-mail address';
|
||
// }
|
||
// return null;
|
||
// },
|
||
// validatorText: "Email Id",
|
||
|
||
inputFormatters: [
|
||
LengthLimitingTextInputFormatter(30),
|
||
RemoveEmojiInputFormatter()
|
||
],
|
||
),
|
||
sizedBoxHeight(10.h),
|
||
text16400white('Password'),
|
||
sizedBoxHeight(10.h),
|
||
CustomTextFormField(
|
||
isInputPassword: true,
|
||
textEditingController: _passwordController,
|
||
hintText: 'Enter your password',
|
||
leadingIcon: Image.asset(
|
||
'assets/images/png/lock.png',
|
||
width: 22.w,
|
||
height: 17.h,
|
||
),
|
||
// validationMessage: errormsgpass.value,
|
||
validator: (value) {
|
||
if (value!.isEmpty) {
|
||
return 'Please enter your password';
|
||
}
|
||
if (!RegExp(
|
||
r'^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$')
|
||
.hasMatch(value)) {
|
||
return 'Enter a valid password';
|
||
}
|
||
|
||
return null;
|
||
},
|
||
// onInput: (p0) {
|
||
// if (p0 == null || p0.isEmpty) {
|
||
// errormsgpass.value =
|
||
// 'Please enter your password';
|
||
// }
|
||
// return null;
|
||
// },
|
||
inputFormatters: [
|
||
LengthLimitingTextInputFormatter(20),
|
||
RemoveEmojiInputFormatter()
|
||
],
|
||
),
|
||
sizedBoxHeight(10.h),
|
||
Align(
|
||
alignment: Alignment.centerRight,
|
||
child: Padding(
|
||
padding: EdgeInsets.only(right: 6.w),
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(RouteName.forgotpass);
|
||
},
|
||
child: text14400white('Forgot password ?')),
|
||
)),
|
||
sizedBoxHeight(40.h),
|
||
CustomButton(
|
||
text: "Login",
|
||
onPressed: () {
|
||
_logincheck();
|
||
}),
|
||
sizedBoxHeight(20.h),
|
||
GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(RouteName.signupscreen);
|
||
},
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
text14400white('Don’t have account ? '),
|
||
sizedBoxWidth(5.w),
|
||
text14700white('Sign up')
|
||
],
|
||
),
|
||
),
|
||
sizedBoxHeight(30.h),
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Container(
|
||
width: 160,
|
||
decoration: const ShapeDecoration(
|
||
shape: RoundedRectangleBorder(
|
||
side: BorderSide(
|
||
width: 0.50,
|
||
strokeAlign: BorderSide.strokeAlignCenter,
|
||
color: Color(0xFF434A53),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
sizedBoxWidth(6.w),
|
||
text14400white('Or'),
|
||
sizedBoxWidth(6.w),
|
||
Container(
|
||
width: 160,
|
||
decoration: const ShapeDecoration(
|
||
shape: RoundedRectangleBorder(
|
||
side: BorderSide(
|
||
width: 0.50,
|
||
strokeAlign: BorderSide.strokeAlignCenter,
|
||
color: Color(0xFF434A53),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
sizedBoxHeight(20.h),
|
||
Center(
|
||
child: SizedBox(
|
||
width: 220.w,
|
||
child: Row(
|
||
children: [
|
||
GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(RouteName.verifygoogleapplepage);
|
||
},
|
||
child: Container(
|
||
width: 55,
|
||
height: 55,
|
||
decoration: ShapeDecoration(
|
||
gradient: LinearGradient(
|
||
begin: const Alignment(0.71, -0.70),
|
||
end: const Alignment(-0.71, 0.7),
|
||
colors: [
|
||
Colors.white
|
||
.withOpacity(0.07999999821186066),
|
||
Colors.white
|
||
.withOpacity(0.12999999523162842)
|
||
],
|
||
),
|
||
shape: const OvalBorder(
|
||
side: BorderSide(
|
||
width: 0.50,
|
||
color: Color(0xFF434A53)),
|
||
),
|
||
image: const DecorationImage(
|
||
image: AssetImage(
|
||
'assets/images/png/login2.png'))),
|
||
),
|
||
),
|
||
const Spacer(),
|
||
GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(RouteName.verifygoogleapplepage);
|
||
},
|
||
child: Container(
|
||
width: 55,
|
||
height: 55,
|
||
decoration: ShapeDecoration(
|
||
gradient: LinearGradient(
|
||
begin: const Alignment(0.71, -0.70),
|
||
end: const Alignment(-0.71, 0.7),
|
||
colors: [
|
||
Colors.white
|
||
.withOpacity(0.07999999821186066),
|
||
Colors.white
|
||
.withOpacity(0.12999999523162842)
|
||
],
|
||
),
|
||
shape: const OvalBorder(
|
||
side: BorderSide(
|
||
width: 0.50,
|
||
color: Color(0xFF434A53)),
|
||
),
|
||
image: const DecorationImage(
|
||
image: AssetImage(
|
||
'assets/images/png/login3.png'))),
|
||
),
|
||
),
|
||
const Spacer(),
|
||
GestureDetector(
|
||
onTap: () async {
|
||
_checkIfisLoggedIn();
|
||
|
||
/* FacebookAuth.instance.login(
|
||
permissions: ['public_profile', 'email'],
|
||
).then((value) {
|
||
FacebookAuth.instance.getUserData().then((userData) {
|
||
setState(() {
|
||
/* _isLoggedIn = true;
|
||
_userObj = userData; */
|
||
});
|
||
});
|
||
}); */
|
||
},
|
||
child: Container(
|
||
width: 55,
|
||
height: 55,
|
||
decoration: ShapeDecoration(
|
||
gradient: LinearGradient(
|
||
begin: const Alignment(0.71, -0.70),
|
||
end: const Alignment(-0.71, 0.7),
|
||
colors: [
|
||
Colors.white.withOpacity(
|
||
0.07999999821186066),
|
||
Colors.white.withOpacity(
|
||
0.12999999523162842)
|
||
],
|
||
),
|
||
shape: const OvalBorder(
|
||
side: BorderSide(
|
||
width: 0.50,
|
||
color: Color(0xFF434A53)),
|
||
),
|
||
image: const DecorationImage(
|
||
image: AssetImage(
|
||
'assets/images/png/login4.png'))),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
sizedBoxHeight(100)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|