Skip to content

Authentication and validation #15

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions expense_tracker/lib/Components/navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ class DesktopNavbar extends StatelessWidget {
"Profile",
style: TextStyle(color: Colors.white),
),
const Text(
"Profile",
style: TextStyle(color: Colors.white),
),
const SizedBox(
width: 30,
Expand Down
24 changes: 16 additions & 8 deletions expense_tracker/lib/Screens/Login.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:expense_tracker/Screens/myhomepage.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'ForgotPasswordPage.dart';

import 'package:email_validator/email_validator.dart';
import '../main.dart';
// import 'package:font_awesome_flutter/font_awesome_flutter.dart';

Expand Down Expand Up @@ -80,42 +79,51 @@ class LoginState extends State<Login> {
const SizedBox(height: 20),
Container(
width: 250,
child: TextField(
child: TextFormField(
controller: emailController,
decoration: InputDecoration(
labelText: 'Email Address',
// suffixIcon: Icon(FontAwesomeIcons.envelope),
),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (email) =>
!(email != null && EmailValidator.validate(email))
? 'Enter a valid Email'
: null,
),
),
const SizedBox(height: 20),
Container(
width: 250,
child: TextField(
child: TextFormField(
controller: passwordController,
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
// suffixIcon: Icon(FontAwesomeIcons.envelope),
),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) => value != null && value.length < 8
? 'Enter min 6 char'
: null,
),
),
const SizedBox(height: 20),
RichText(
text: TextSpan(
style: TextStyle(
color: Colors.orangeAccent[700], fontSize: 20),
text: 'No account',
text: 'No account?',
children: [
TextSpan(
recognizer: TapGestureRecognizer()
..onTap = widget.onClickedSignUp,
text: 'Sign up?',
text: 'Sign up',
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.orangeAccent[700])),
],
),
),
const SizedBox(height: 20),
GestureDetector(
child: Text(
'Forgot Password?',
Expand Down
6 changes: 6 additions & 0 deletions expense_tracker/lib/Screens/addexpenses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class AddExpenses extends StatefulWidget {
class _AddExpensesState extends State<AddExpenses> {
String dropdownValue = list.first;

final entertainmentController = TextEditingController();
final merchantnameController = TextEditingController();
final descriptionController = TextEditingController();
final dateController = TextEditingController();
final documentController = TextEditingController();

void openFiles() async {
FilePickerResult? resultFile =
await FilePicker.platform.pickFiles(allowMultiple: true);
Expand Down
11 changes: 10 additions & 1 deletion expense_tracker/lib/Screens/profile.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import '../Components/navbar.dart';
import 'Login.dart';

class Profile extends StatefulWidget {
const Profile({super.key});
Expand Down Expand Up @@ -88,7 +89,15 @@ class _ProfileState extends State<Profile> {
],
),
GestureDetector(
onTap: () => FirebaseAuth.instance.signOut(),
onTap: () {
FirebaseAuth.instance.signOut();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Login(
onClickedSignUp: () {},
)));
},
child: Container(
alignment: Alignment.center,
width: 250,
Expand Down
21 changes: 5 additions & 16 deletions expense_tracker/lib/Screens/register.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:expense_tracker/Screens/myhomepage.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -98,7 +99,7 @@ class RegisterPageState extends State<RegisterPage> {
),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (email) =>
email != null && EmailValidator.validate(email)
!(email != null && EmailValidator.validate(email))
? 'Enter a valid Email'
: null,
),
Expand Down Expand Up @@ -131,28 +132,16 @@ class RegisterPageState extends State<RegisterPage> {
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 40, 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
'Already have an account',
style: TextStyle(color: Colors.orangeAccent[700]),
)
],
),
),
RichText(
text: TextSpan(
style: TextStyle(
color: Colors.orangeAccent[700], fontSize: 20),
text: 'Have an account',
text: 'Have an account?',
children: [
TextSpan(
recognizer: TapGestureRecognizer()
..onTap = widget.onClickedSignIn,
text: 'Sign in?',
text: 'Sign in',
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.orangeAccent[700])),
Expand Down Expand Up @@ -199,7 +188,7 @@ class RegisterPageState extends State<RegisterPage> {

Future signUp() async {
final isValid = formKey.currentState!.validate();
if (isValid) return;
if (!isValid) return;
showDialog(
context: context,
barrierDismissible: false,
Expand Down
3 changes: 0 additions & 3 deletions expense_tracker/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

import 'package:expense_tracker/Screens/Login.dart';
import 'package:expense_tracker/Screens/myhomepage.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:expense_tracker/Screens/activity.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
import 'package:flutter/material.dart';
Expand Down