|
|
|
|
@ -26,7 +26,7 @@ class _LoginState extends State<Login> {
|
|
|
|
|
bool isObscureText=true;
|
|
|
|
|
TextEditingController mobileNumberController = TextEditingController();
|
|
|
|
|
TextEditingController passwordController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -51,172 +51,229 @@ class _LoginState extends State<Login> {
|
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
|
|
|
},
|
|
|
|
|
child: SafeArea(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Padding(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
|
|
|
|
|
child: Column(
|
|
|
|
|
child: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Column(
|
|
|
|
|
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SizedBox(height: MediaQuery.of(context).size.height * .2),
|
|
|
|
|
CircleAvatar(radius: 80, backgroundColor: Color(0XFFF3F1FB)),
|
|
|
|
|
SizedBox(height: MediaQuery.of(context).size.height * .05),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SizedBox(height: MediaQuery.of(context).size.height * .2),
|
|
|
|
|
CircleAvatar(radius: 80, backgroundColor: Color(0XFFF3F1FB)),
|
|
|
|
|
SizedBox(height: MediaQuery.of(context).size.height * .05),
|
|
|
|
|
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .024,),
|
|
|
|
|
Container(
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .024,),
|
|
|
|
|
TextFormField(
|
|
|
|
|
controller: mobileNumberController,
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
textCapitalization: TextCapitalization.sentences,
|
|
|
|
|
maxLength: 10,
|
|
|
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
|
|
|
|
|
|
|
|
decoration: textFormFieldDecoration(Icons.phone,'Mobile Number'),
|
|
|
|
|
style:fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
|
|
|
|
|
|
|
|
|
|
style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w400),
|
|
|
|
|
cursorColor: Color(0XFF8270DB),
|
|
|
|
|
|
|
|
|
|
//TextStyle(color: Colors.black,fontWeight: FontWeight.bold),
|
|
|
|
|
inputFormatters: [
|
|
|
|
|
|
|
|
|
|
// Allow only numbers
|
|
|
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
|
|
|
|
|
|
|
|
// Restrict first digit 6-9
|
|
|
|
|
TextInputFormatter.withFunction(
|
|
|
|
|
(oldValue, newValue) {
|
|
|
|
|
|
|
|
|
|
if (newValue.text.isEmpty) {
|
|
|
|
|
return newValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// First digit must be 6-9
|
|
|
|
|
if (!RegExp(r'^[6-9]').hasMatch(newValue.text)) {
|
|
|
|
|
return oldValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newValue;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
validator: (value) {
|
|
|
|
|
|
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
|
return "Please enter mobile number";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!RegExp(r'^[6-9]').hasMatch(value)) {
|
|
|
|
|
return "Please enter digits 6,7,8,9";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value.length != 10) {
|
|
|
|
|
return "Enter valid 10 digit number";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .016,),
|
|
|
|
|
|
|
|
|
|
Container(
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
cursorColor:Color(0XFF8270DB),
|
|
|
|
|
obscureText: isObscureText,
|
|
|
|
|
obscuringCharacter: '*',
|
|
|
|
|
controller: passwordController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
filled: false,
|
|
|
|
|
fillColor: Colors.white,
|
|
|
|
|
labelText: 'Password',
|
|
|
|
|
//prefixIcon: const Icon(Icons.lock, color: Colors.white,),
|
|
|
|
|
labelStyle: fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400),
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .016,),
|
|
|
|
|
|
|
|
|
|
Container(
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
cursorColor:Color(0XFF8270DB),
|
|
|
|
|
obscureText: isObscureText,
|
|
|
|
|
obscuringCharacter: '*',
|
|
|
|
|
controller: passwordController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
filled: false,
|
|
|
|
|
fillColor: Colors.white,
|
|
|
|
|
labelText: 'Password',
|
|
|
|
|
//prefixIcon: const Icon(Icons.lock, color: Colors.white,),
|
|
|
|
|
labelStyle: fontTextStyle(14,Color(0XFF7E7F80),FontWeight.w400),
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
|
|
|
borderSide: BorderSide(color: greyColor,
|
|
|
|
|
width: 1, )),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
|
|
|
borderSide: BorderSide(color: greyColor,
|
|
|
|
|
width: 1, )),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
|
|
|
borderSide: BorderSide(color: Color(0XFF8270DB),width: 2,),
|
|
|
|
|
),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
|
|
|
borderSide: BorderSide(color: greyColor),
|
|
|
|
|
),
|
|
|
|
|
borderSide: BorderSide(color: Color(0XFF8270DB),width: 2,),
|
|
|
|
|
),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(4.0),
|
|
|
|
|
borderSide: BorderSide(color: greyColor),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
icon: isObscureText==true?Image.asset('images/eye_icon.png',color: Color(0XFF7E7F80),width: 30,height: 30,):Image.asset('images/open_eye.png',color:Color(0XFF7E7F80),width: 30,height: 30,),
|
|
|
|
|
/* Icon(
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
icon: isObscureText==true?Image.asset('images/eye_icon.png',color: Color(0XFF7E7F80),width: 30,height: 30,):Image.asset('images/open_eye.png',color:Color(0XFF7E7F80),width: 30,height: 30,),
|
|
|
|
|
/* Icon(
|
|
|
|
|
icon:Image.asset('assets/your_image.png'),
|
|
|
|
|
color: isObscureText==true?greyColor:primaryColor,
|
|
|
|
|
),*/
|
|
|
|
|
onPressed: () {
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
|
|
|
|
print("show password");
|
|
|
|
|
setState(() {
|
|
|
|
|
isObscureText = !isObscureText;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
print("show password");
|
|
|
|
|
setState(() {
|
|
|
|
|
isObscureText = !isObscureText;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
),
|
|
|
|
|
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
|
|
|
|
|
validator: (value) {
|
|
|
|
|
if (value == null || value.isEmpty) {
|
|
|
|
|
return "Please enter password";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
style: fontTextStyle(14,Color(0XFF2A2A2A),FontWeight.w400),
|
|
|
|
|
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .016,),
|
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
|
child:GestureDetector(
|
|
|
|
|
onTap: (){
|
|
|
|
|
/* Navigator.push(
|
|
|
|
|
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .016,),
|
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
|
child:GestureDetector(
|
|
|
|
|
onTap: (){
|
|
|
|
|
/* Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (context) => ForgotpasswordNew()),
|
|
|
|
|
);*/
|
|
|
|
|
},
|
|
|
|
|
child: Text(
|
|
|
|
|
'Forgot Password?',
|
|
|
|
|
style: fontTextStyle(12,Color(0XFF1D7AFC),FontWeight.w600),
|
|
|
|
|
},
|
|
|
|
|
child: Text(
|
|
|
|
|
'Forgot Password?',
|
|
|
|
|
style: fontTextStyle(12,Color(0XFF1D7AFC),FontWeight.w600),
|
|
|
|
|
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .024,),
|
|
|
|
|
Container(
|
|
|
|
|
width:double.infinity,
|
|
|
|
|
height: MediaQuery.of(context).size.height * .06,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12.0), // Customize the radius
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async{
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .024,),
|
|
|
|
|
Container(
|
|
|
|
|
width:double.infinity,
|
|
|
|
|
height: MediaQuery.of(context).size.height * .06,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(12.0), // Customize the radius
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
|
|
|
|
|
// 🔥 THIS MAKES VALIDATION WORK
|
|
|
|
|
if (!_formKey.currentState!.validate()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mobileNumberController.text != ''&&
|
|
|
|
|
passwordController.text != '') {
|
|
|
|
|
AppSettings.preLoaderDialog(context);
|
|
|
|
|
|
|
|
|
|
bool isOnline = await AppSettings.internetConnectivity();
|
|
|
|
|
|
|
|
|
|
if(isOnline){
|
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs =
|
|
|
|
|
await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
|
|
String? fcmToken = prefs.getString('fcmToken');
|
|
|
|
|
var payload = new Map<String, dynamic>();
|
|
|
|
|
payload["phone"] = mobileNumberController.text.toString();
|
|
|
|
|
payload["password"] = passwordController.text.toString();
|
|
|
|
|
payload["fcmIds"] = [fcmToken];
|
|
|
|
|
|
|
|
|
|
bool signinStatus = await AppSettings.login(payload);
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
if (signinStatus) {
|
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
|
String token = AppSettings.accessToken;
|
|
|
|
|
await storage.write(key: 'authToken', value: token);
|
|
|
|
|
|
|
|
|
|
print('Token saved: $token');
|
|
|
|
|
await Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => const DashboardScreen()),
|
|
|
|
|
);
|
|
|
|
|
AppSettings.longSuccessToast("Logged in Successfully");
|
|
|
|
|
mobileNumberController.text='';
|
|
|
|
|
passwordController.text='';
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
|
AppSettings.longFailedToast("Invalid details");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(exception){
|
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
|
print(exception);
|
|
|
|
|
|
|
|
|
|
var payload = {
|
|
|
|
|
"phone": mobileNumberController.text.trim(),
|
|
|
|
|
"password": passwordController.text.trim(),
|
|
|
|
|
"fcmIds": [fcmToken]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool signinStatus =
|
|
|
|
|
await AppSettings.login(payload);
|
|
|
|
|
|
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
|
|
|
|
|
|
if (signinStatus) {
|
|
|
|
|
|
|
|
|
|
String token = AppSettings.accessToken;
|
|
|
|
|
|
|
|
|
|
await storage.write(
|
|
|
|
|
key: 'authToken',
|
|
|
|
|
value: token);
|
|
|
|
|
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
const DashboardScreen()),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
AppSettings.longSuccessToast(
|
|
|
|
|
"Logged in Successfully");
|
|
|
|
|
|
|
|
|
|
mobileNumberController.clear();
|
|
|
|
|
passwordController.clear();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
AppSettings.longFailedToast(
|
|
|
|
|
"Invalid details");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Navigator.of(context,rootNavigator: true).pop();
|
|
|
|
|
AppSettings.longFailedToast("Please Check internet");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Navigator.of(context,
|
|
|
|
|
rootNavigator: true).pop();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
AppSettings.longFailedToast(
|
|
|
|
|
"Please Check internet");
|
|
|
|
|
|
|
|
|
|
AppSettings.longFailedToast("Please enter valid details");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
child: Text('Login',style: fontTextStyle(12,Colors.white,FontWeight.w600),),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
child: Text('Login',style: fontTextStyle(12,Colors.white,FontWeight.w600),),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
), ],
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|