Files
Regroup/lib/onboarding/Signup/View/signupscreen.dart
2024-08-14 16:33:09 +05:30

623 lines
30 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:regroup/Common/base_manager.dart';
import 'package:regroup/Global.dart';
import 'package:regroup/Login/ViewModel/LoginApi.dart';
import 'package:regroup/Utils/Common/AppleOAuthService.dart';
import 'package:regroup/Utils/Common/CommonDropdown.dart';
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
import 'package:regroup/Utils/Common/CustomNextButton.dart';
import 'package:regroup/Utils/Common/googleOAuthService.dart';
import 'package:regroup/Utils/Common/sized_box.dart';
import 'package:regroup/Utils/dialogs.dart';
import 'package:regroup/Utils/texts.dart';
import 'package:regroup/onboarding/Signup/view_model/postmethod.dart';
import 'package:regroup/resources/routes/route_name.dart';
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SignupScreen extends StatefulWidget {
const SignupScreen({super.key});
@override
State<SignupScreen> createState() => _SignupScreenState();
}
class _SignupScreenState extends State<SignupScreen> {
TextEditingController emailidcontroller = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController confirmpasscontroller = TextEditingController();
AccessToken? _accessToken;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
GoogleAuthService googleSigninController = Get.put(GoogleAuthService());
final Map<String, int> _accountTypeMap = {
'Individual': 1,
'Business': 2,
};
String _selectedAccountType = '';
void _onItemSelected(String value) {
setState(() {
_selectedAccountType = value;
});
}
_loginWithApple() {
AppleOAuthService().logIn();
}
_loginWithGoogle() {
googleSigninController.handleGoogleSignIn().then((value) async {
final resp = await LoginAPI().storeGoogleSignin(
{"google_access_token": value, "one_signal_player_id": "ABCD"});
if (value != 'Google Sign-In canceled') {
if (resp.message == "go-to-signin-via-oauth") {
Get.toNamed(RouteName.verifygoogleapplepage,
arguments: {"email": resp.data});
} else if (value == null) {
Get.snackbar(
'Error',
resp.data["message"][0],
duration: const Duration(seconds: 2),
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
} else {
Get.snackbar(
"Success!",
'Login successful!',
duration: const Duration(seconds: 2),
colorText: Colors.white,
backgroundColor: Colors.green,
margin: const EdgeInsets.all(8),
snackStyle: SnackStyle.FLOATING,
snackPosition: SnackPosition.BOTTOM,
);
//Get.toNamed(RouteName.mainscreen);
logger.d("go to login");
}
} else {
Get.snackbar(
'Error',
resp.data["message"][0],
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.red,
colorText: Colors.white,
);
}
});
}
_checkIfisLoggedIn() async {
await _logout();
final accessToken = await FacebookAuth.instance.accessToken;
if (accessToken != null) {
print("/////////////////////////////////////////xcheck");
final userData = await FacebookAuth.instance.getUserData();
logger.i(accessToken.token);
logger.i(userData.toString());
} else {
print("/////////////////////////////////////////check");
_login();
}
}
_login() async {
final LoginResult result = await FacebookAuth.instance.login();
if (result.status == LoginStatus.success) {
_accessToken = result.accessToken;
final userData = await FacebookAuth.instance.getUserData();
logger.i(userData['email']);
logger.i(userData['id']);
await LoginAPI().storeFacebookSignin(
{"facebook_auth_token": userData['id']},
emailReceived: userData['email']);
} else {
print(result.status);
print(result.message);
}
}
_logout() async {
await FacebookAuth.instance.logOut();
_accessToken = null;
setState(() {});
}
Uploadata() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
utils.loader();
int accountTypeValue = _accountTypeMap[_selectedAccountType] ?? 0;
Map<String, dynamic> updata = {
"email_address": emailidcontroller.text,
"password": passwordController.text,
"account_type": "1",
};
final data = await Onboard().Postregisteration(updata);
if (data.status == ResponseStatus.SUCCESS) {
Get.back();
print("Sign up done");
globalAccountType = "1";
String selectedCategory = _selectedAccountType;
Get.toNamed(RouteName.verifyusercreen, arguments: {
"emailid": emailidcontroller.text,
"password": passwordController.text,
"accounttype": "Individual",
'accountypenumber': 1,
});
return utils.showToast(data.message);
} else {
Get.back();
print("registration not done");
return utils.showToast(data.message);
}
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: const Color.fromARGB(255, 18, 32, 47),
body: Stack(
children: [
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image:
AssetImage("assets/images/png/Choice screen.png"),
fit: BoxFit.fill)),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(top: 150.h),
child: Center(child: text22400white('Create account')),
),
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.w, vertical: 30.h),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text16400white('Email address'),
sizedBoxHeight(10.h),
CustomTextFormField(
textEditingController: emailidcontroller,
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(50),
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,
),
// const Icon(Icons.lock_outline),
// validationMessage: "Enter your password",
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter your password';
}
return null;
},
inputFormatters: [
LengthLimitingTextInputFormatter(50),
RemoveEmojiInputFormatter()
],
),
sizedBoxHeight(10.h),
text16400white('Confirm password'),
sizedBoxHeight(10.h),
CustomTextFormField(
isInputPassword: true,
textEditingController: confirmpasscontroller,
hintText: "Enter your password",
leadingIcon: Image.asset(
'assets/images/png/lock.png',
width: 22.w,
height: 17.h,
),
// const Icon(Icons.lock_outline),
// validatorText: "Enter your password",
validator: (val) {
if (val == null || val.isEmpty) {
return 'Please enter your password';
}
if (val != passwordController.text) {
return 'Password does not match';
}
return null;
},
inputFormatters: [
LengthLimitingTextInputFormatter(50),
RemoveEmojiInputFormatter()
],
),
sizedBoxHeight(10.h),
// Row(
// children: [
// text16400white('Account type'),
// sizedBoxWidth(5.w),
// Image.asset(
// 'assets/images/png/informationicon.png')
// ],
// ),
// sizedBoxHeight(10.h),
// CustomDropDownRadio(
// header: 'Select account type',
// title: '',
// listData: const [
// 'Individual',
// 'Business',
// ],
// onItemSelected: _onItemSelected,
// leadingImage: Image.asset(
// 'assets/images/png/user.png',
// ),
// ),
sizedBoxHeight(30.h),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 320.w,
// height: 42.h,
child: Text.rich(
TextSpan(
children: [
TextSpan(
text:
'By signing up to ReGroup you agree to our ',
style: TextStyle(
color: const Color(0xCCFCFCFC),
fontSize: 14.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
TextSpan(
text: 'Terms and Conditions',
style: TextStyle(
color: const Color(0xCCFCFCFC),
fontSize: 14.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w700,
decoration:
TextDecoration.underline,
decorationColor:
const Color(0xffFCFCFC)
.withOpacity(0.80),
),
),
TextSpan(
text: ' and ',
style: TextStyle(
color: const Color(0xCCFCFCFC),
fontSize: 14.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
TextSpan(
text: 'Privacy Policy',
style: TextStyle(
color: const Color(0xCCFCFCFC),
fontSize: 14.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w700,
decoration:
TextDecoration.underline,
decorationColor:
const Color(0xffFCFCFC)
.withOpacity(0.80),
),
),
],
),
textAlign: TextAlign.center,
),
),
],
),
sizedBoxHeight(20.h),
CustomButton(
text: "Continue",
onPressed: () {
// _Signincheck();
final isValid =
_formKey.currentState?.validate();
if (
// isValid!
emailidcontroller.text.isBlank! ||
passwordController.text.isBlank! ||
confirmpasscontroller
.text.isBlank!
// && _selectedAccountType.isEmpty
) {
print(emailidcontroller.text);
print(passwordController.text);
print(_selectedAccountType.toString());
utils.showToast('Please fill all fields');
} else {
Uploadata();
}
}),
sizedBoxHeight(20.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(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
if (Platform.isIOS)
GestureDetector(
onTap: () {
_loginWithApple();
},
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'))),
),
),
if (Platform.isAndroid)
GestureDetector(
onTap: () {
_loginWithGoogle();
},
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'))),
),
),
GestureDetector(
onTap: () async {
_checkIfisLoggedIn();
},
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(20.h),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 320.w,
// height: 42.h,
child: Text.rich(
TextSpan(
children: [
TextSpan(
text:
'Are you a business looking to join ',
style: TextStyle(
color: const Color(0xFFFCFCFC),
fontSize: 14.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
TextSpan(
text: 'Regroup?',
style: TextStyle(
color: const Color(0xFFD90B2E),
fontSize: 14.sp,
fontFamily: 'Helvetica',
fontWeight: FontWeight.w400,
),
),
],
),
textAlign: TextAlign.center,
),
),
],
),
sizedBoxHeight(25.h),
InkWell(
onTap: () {
Get.toNamed(RouteName.bussignupScreen);
},
child: Container(
width: double.infinity,
height: 50.h,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color.fromRGBO(255, 255, 255, 0.036),
Color.fromRGBO(255, 255, 255, 0.048),
],
),
borderRadius: BorderRadius.circular(30.r),
border: Border.all(
color: Color(0xFF434A53),
width: 1,
),
),
child: Center(
child: text16w400_FCFCFC("Sign up here")),
),
),
],
),
),
),
),
)
],
),
],
)),
);
}
}