357 lines
14 KiB
Dart
357 lines
14 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:glassmorphism/glassmorphism.dart';
|
||
import 'package:regroup/Utils/Common/CustomNextButton.dart';
|
||
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
|
||
import 'package:regroup/Utils/Common/blureffect.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:show_fps/show_fps.dart';
|
||
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||
|
||
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 _email = TextEditingController();
|
||
RxBool isObscured = true.obs;
|
||
final TextEditingController _password = TextEditingController();
|
||
// final GlobalKey<FormState> _form = GlobalKey<FormState>();
|
||
|
||
@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(() {});
|
||
}
|
||
|
||
@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)),
|
||
),
|
||
Center(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
SizedBox(
|
||
height: 150.h,
|
||
),
|
||
Padding(
|
||
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
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),
|
||
text16400white('Email address'),
|
||
sizedBoxHeight(10.h),
|
||
CustomTextFormField(
|
||
textEditingController: _email,
|
||
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,
|
||
),
|
||
),
|
||
// validatorText: "Email Id",
|
||
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;
|
||
},
|
||
inputFormatters: [
|
||
LengthLimitingTextInputFormatter(30),
|
||
RemoveEmojiInputFormatter()
|
||
],
|
||
),
|
||
sizedBoxHeight(10.h),
|
||
text16400white('Password'),
|
||
sizedBoxHeight(10.h),
|
||
CustomTextFormField(
|
||
isInputPassword: true,
|
||
textEditingController: _password,
|
||
hintText: 'Enter your password',
|
||
leadingIcon: Image.asset(
|
||
'assets/images/png/lock.png',
|
||
width: 22.w,
|
||
height: 17.h,
|
||
),
|
||
validator: (val) {
|
||
if (val == null || val.isEmpty) {
|
||
return '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: text14400white('Forgot password ?'),
|
||
)),
|
||
sizedBoxHeight(40.h),
|
||
CustomButton(
|
||
text: "Login",
|
||
onPressed: () {
|
||
Get.toNamed(RouteName.mainscreen);
|
||
}),
|
||
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: [
|
||
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(),
|
||
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'))),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|