Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature of password visibility has fixed #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 104 additions & 67 deletions app/lib/screens/auth_screen/signup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:examtime/services/ApiServices/api_services.dart.dart';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'signin.dart'; // Import your sign-in page here
import 'package:flutter/cupertino.dart';

class SignUpPage extends StatefulWidget {
static const String routeName = '/signup';
Expand All @@ -16,12 +17,22 @@ class SignUpPage extends StatefulWidget {
}

class _SignUpPageState extends State<SignUpPage> {
late bool passwordVisible;
late bool passwordVisibleConfirm;
TextEditingController name = TextEditingController();
TextEditingController email = TextEditingController();
TextEditingController password = TextEditingController();
final _formKey1 = GlobalKey<FormState>();
final _formKey2 = GlobalKey<FormState>();
final _formKey3 = GlobalKey<FormState>();
@override
void initState() {
// TODO: implement initState
super.initState();
passwordVisible = false;
passwordVisibleConfirm = false;
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -43,31 +54,30 @@ class _SignUpPageState extends State<SignUpPage> {
width: 200,
height: 150,
),
Form(
key: _formKey1,
child: TextFormField(
controller: email,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Enter your email',
prefixIcon: Icon(Icons.email),
Form(
key: _formKey1,
child: TextFormField(
controller: email,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Enter your email',
prefixIcon: Icon(Icons.email),
),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter an email';
}
final emailRegex = RegExp(r'^[^@]+@[^@]+\.[^@]+');
if (!emailRegex.hasMatch(value)) {
return 'Please enter a valid email';
}
return null;
},
),

autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter an email';
}
final emailRegex = RegExp(r'^[^@]+@[^@]+\.[^@]+');
if (!emailRegex.hasMatch(value)) {
return 'Please enter a valid email';
}
return null;
},
),
),
const SizedBox(height: 10.0),
TextField(
controller: name,
Expand All @@ -84,12 +94,26 @@ class _SignUpPageState extends State<SignUpPage> {
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextFormField(
controller: password,
obscureText: true, // Set to true for password fields
decoration: const InputDecoration(
obscureText: !passwordVisible,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Enter your password',
prefixIcon: Icon(Icons.lock),
prefixIcon: const Icon(Icons.lock),
suffixIcon: IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
passwordVisible
? CupertinoIcons.eye_fill
: CupertinoIcons.eye_slash_fill,
),
onPressed: () {
// Update the state i.e. toogle the state of passwordVisible variable
setState(() {
passwordVisible = !passwordVisible;
});
},
),
),
validator: (value) {
if (value == null || value.isEmpty) {
Expand All @@ -103,29 +127,45 @@ class _SignUpPageState extends State<SignUpPage> {
),
),
const SizedBox(height: 10.0),
Form(
key: _formKey3,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextFormField(
validator: (value) {
if(value!=password.text){
return 'password should be match';
}
return null;
},
obscureText: true,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Confirm Password',
prefixIcon: Icon(Icons.lock),
Form(
key: _formKey3,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextFormField(
validator: (value) {
if (value != password.text) {
return 'password should be match';
}
return null;
},
obscureText: !passwordVisibleConfirm,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Confirm Password',
prefixIcon: const Icon(Icons.lock),
suffixIcon: IconButton(
icon: Icon(
// Based on passwordVisible state choose the icon
passwordVisibleConfirm
? CupertinoIcons.eye_fill
: CupertinoIcons.eye_slash_fill,
),
onPressed: () {
// Update the state i.e. toogle the state of passwordVisible variable
setState(() {
passwordVisibleConfirm = !passwordVisibleConfirm;
});
},
),
),
),
),
),
const SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
if(_formKey1.currentState!.validate() && _formKey2.currentState!.validate() && _formKey3.currentState!.validate()){
if (_formKey1.currentState!.validate() &&
_formKey2.currentState!.validate() &&
_formKey3.currentState!.validate()) {
Apiservices.signupUser(
name: name.text,
email: email.text,
Expand All @@ -139,32 +179,30 @@ class _SignUpPageState extends State<SignUpPage> {
context,
value['token'],
);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => OTPPage(
token: value['token'],
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => OTPPage(
token: value['token'],
),
));
}
});
}
else{
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Credentials should not be empty"),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("OK"),
),
],
);
}
);
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
"Credentials should not be empty"),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("OK"),
),
],
);
});
}
Apiservices.signupUser(
name: name.text,
Expand Down Expand Up @@ -204,7 +242,6 @@ class _SignUpPageState extends State<SignUpPage> {
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(

builder: (context) => LoginPage(),
),
);
Expand All @@ -222,4 +259,4 @@ class _SignUpPageState extends State<SignUpPage> {
),
);
}
}
}
Loading