Skip to content
Closed
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
17 changes: 17 additions & 0 deletions lib/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
class Home extends StatelessWidget {

const Home({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home Screen'),
),
body: Center(
child: Text('Welcome to the Home Screen!'),
),
);
}
}
37 changes: 30 additions & 7 deletions lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:nommetric/home.dart';
import 'package:nommetric/screens/register_screen.dart';

class LoginScreen extends StatelessWidget {
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});

@override
State<LoginScreen> createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {

final emailController = TextEditingController();
final passwordController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -47,6 +58,7 @@ class LoginScreen extends StatelessWidget {
),
SizedBox(height: 8.0),
TextField(
controller: emailController,
decoration: InputDecoration(
hintText: "[email protected]",
hintStyle: TextStyle(fontWeight: FontWeight.w400),
Expand All @@ -66,6 +78,7 @@ class LoginScreen extends StatelessWidget {
),
SizedBox(height: 8.0),
TextField(
controller: passwordController,
decoration: InputDecoration(
hintText: "Enter your password",
hintStyle: TextStyle(fontWeight: FontWeight.w400),
Expand All @@ -80,12 +93,22 @@ class LoginScreen extends StatelessWidget {
),
SizedBox(height: 32.0),
ElevatedButton(
onPressed: () {
// Go to home placeholder
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Placeholder())
);
onPressed: () async{
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: emailController.text.trim(),
password: passwordController.text.trim(),
);

Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => Home()),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Invalid credentials")),
);
}
},
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
Expand Down
41 changes: 37 additions & 4 deletions lib/screens/register_screen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:nommetric/screens/login_screen.dart';

class RegisterScreen extends StatelessWidget {
class RegisterScreen extends StatefulWidget {
const RegisterScreen({super.key});

@override
State<RegisterScreen> createState() => _RegisterScreenState();
}

class _RegisterScreenState extends State<RegisterScreen> {

final emailController = TextEditingController();
final passwordController = TextEditingController();
final confirmPasswordController = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -53,6 +64,7 @@ class RegisterScreen extends StatelessWidget {
SizedBox(height: 15.0),
// Email TextField
TextField(
controller: emailController,
decoration: InputDecoration(
labelText: "Enter Your Email / Roll no.",
hintText: "[email protected]",
Expand All @@ -63,6 +75,7 @@ class RegisterScreen extends StatelessWidget {
SizedBox(height: 15.0),
// Password TextField
TextField(
controller: passwordController,
decoration: InputDecoration(
labelText: "Enter Your Password",
suffix: Icon(CupertinoIcons.eye_solid),
Expand All @@ -74,6 +87,7 @@ class RegisterScreen extends StatelessWidget {
SizedBox(height: 15.0),
// Confirm Password TextField
TextField(
controller: confirmPasswordController,
decoration: InputDecoration(
labelText: "Confirm Password",
suffix: Icon(CupertinoIcons.eye_solid),
Expand All @@ -85,9 +99,28 @@ class RegisterScreen extends StatelessWidget {
SizedBox(height: 20.0),
// Sign Up Button
ElevatedButton(
onPressed: () {
// Navigator.push(context,
// MaterialPageRoute(builder: (context) => HomePage()));
onPressed: () async{
if(passwordController.text != confirmPasswordController.text){
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Passwords do not match")),
);
return;
}

try {
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: emailController.text.trim(),
password: passwordController.text.trim()
);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LoginScreen())
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
}
},
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
Expand Down
89 changes: 89 additions & 0 deletions lib/widgets/bottomNav_hasan.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:flutter/material.dart';

class BottomNavHasan extends StatefulWidget {
const BottomNavHasan({super.key});

@override
State<BottomNavHasan> createState() => _BottomNavHasanState();
}

class _BottomNavHasanState extends State<BottomNavHasan> {
int _currentIndex = 0;

final List<Widget> _screens = const [
_HomePlaceholder(),
_MenuPlaceholder(),
_ProfilePlaceholder(),
];

@override
Widget build(BuildContext context) {
return Scaffold(
body: _screens[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: "Home",
),
BottomNavigationBarItem(
icon: Icon(Icons.menu_outlined),
label: "Menu",
),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: "Profile",
),
],
),
);
}
}

class _HomePlaceholder extends StatelessWidget {
const _HomePlaceholder();

@override
Widget build(BuildContext context) {
return const Center(
child: Text(
"Home Screen",
style: TextStyle(fontSize: 22, fontWeight: FontWeight.w600),
),
);
}
}

class _MenuPlaceholder extends StatelessWidget {
const _MenuPlaceholder();

@override
Widget build(BuildContext context) {
return const Center(
child: Text(
"Menu Screen",
style: TextStyle(fontSize: 22, fontWeight: FontWeight.w600),
),
);
}
}

class _ProfilePlaceholder extends StatelessWidget {
const _ProfilePlaceholder();

@override
Widget build(BuildContext context) {
return const Center(
child: Text(
"Profile Screen",
style: TextStyle(fontSize: 22, fontWeight: FontWeight.w600),
),
);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
# Firebase
firebase_core: ^3.0.0
cloud_firestore: ^5.0.0
firebase_auth: ^5.7.0

dev_dependencies:
flutter_test:
Expand Down