import 'package:flutter/material.dart';
import 'firstpage.dart';
import 'loginpage.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Navigation Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: LoginPage(), // Main entry point
debugShowCheckedModeBanner: false,
);
}
}
import 'package:flutter/material.dart';
import 'firstpage.dart';
class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeLogin(),
debugShowCheckedModeBanner: false,
);
}
}
class HomeLogin extends StatefulWidget {
@override
State<HomeLogin> createState() => _HomeLoginState();
}
class _HomeLoginState extends State<HomeLogin> {
// Fixed: Use proper types instead of dynamic
TextEditingController usernameController = TextEditingController();
TextEditingController passwordController = TextEditingController();
// List to store registered users
List<Map<String, String>> registeredUsers = [
{'username': 'Admin', 'password': 'Admin123'}
];
void login() {
// Fixed: Use proper String types
String username = usernameController.text;
String password = passwordController.text;
if (username.isEmpty || password.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Please provide input in all fields'),
),
);
} else {
// Check if user exists in registered users
bool userExists = registeredUsers.any((user) =>
user['username'] == username && user['password'] == password);
if (userExists) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (BuildContext context) => LoginPage()),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Invalid Credentials')),
);
}
}
}
void navigateToSignUp() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SignUpPage(registeredUsers: registeredUsers)),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color.fromARGB(255, 220, 245, 242),
title: Text('Login Screen'),
centerTitle: true,
),
body: Center(
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 70, 20, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
CircleAvatar(radius: 75),
Text(
'Welcome Users',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
color: Colors.teal,
),
),
Text(
'Please Login to Continue',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
color: Colors.black54,
),
),
SizedBox(height: 20),
TextField(
controller: usernameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Username',
prefixIcon: Icon(Icons.person),
),
),
SizedBox(height: 10),
TextField(
controller: passwordController,
obscureText: true,
obscuringCharacter: '*',
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
prefixIcon: Icon(Icons.lock),
),
),
SizedBox(height: 20),
SizedBox(
height: 60,
width: double.infinity,
child: ElevatedButton(
onPressed: login,
child: Text('Login'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.greenAccent,
foregroundColor: Colors.white,
),
),
),
SizedBox(height: 10),
TextButton(
onPressed: navigateToSignUp,
child: Text(
"Don't have an account? Sign Up",
style: TextStyle(
color: Colors.teal,
fontSize: 16,
),
),
),
],
),
),
),
);
}
}
class SignUpPage extends StatefulWidget {
final List<Map<String, String>> registeredUsers;
const SignUpPage({Key? key, required this.registeredUsers}) : super(key: key);
@override
State<SignUpPage> createState() => _SignUpPageState();
}
class _SignUpPageState extends State<SignUpPage> {
TextEditingController newUsernameController = TextEditingController();
TextEditingController newPasswordController = TextEditingController();
TextEditingController confirmPasswordController = TextEditingController();
void signUp() {
String username = newUsernameController.text;
String password = newPasswordController.text;
String confirmPassword = confirmPasswordController.text;
if (username.isEmpty || password.isEmpty || confirmPassword.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Please fill all fields'),
),
);
} else if (password != confirmPassword) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Passwords do not match'),
),
);
} else if (widget.registeredUsers
.any((user) => user['username'] == username)) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Username already exists'),
),
);
} else {
// Add new user
widget.registeredUsers.add({
'username': username,
'password': password,
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Account created successfully!'),
),
);
// Navigate back to login page
Navigator.of(context).pop();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal[200],
title: Text('Sign Up'),
centerTitle: true,
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: 60,
backgroundColor: Colors.teal[100],
child: Icon(Icons.person_add, size: 50, color: Colors.teal),
),
SizedBox(height: 30),
Text(
'Create New Account',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.teal,
),
),
SizedBox(height: 30),
TextField(
controller: newUsernameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Username',
prefixIcon: Icon(Icons.person),
),
),
SizedBox(height: 15),
TextField(
controller: newPasswordController,
obscureText: true,
obscuringCharacter: '*',
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
prefixIcon: Icon(Icons.lock),
),
),
SizedBox(height: 15),
TextField(
controller: confirmPasswordController,
obscureText: true,
obscuringCharacter: '*',
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Confirm Password',
prefixIcon: Icon(Icons.lock_outline),
),
),
SizedBox(height: 30),
SizedBox(
height: 60,
width: double.infinity,
child: ElevatedButton(
onPressed: signUp,
child: Text('Sign Up'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
foregroundColor: Colors.white,
),
),
),
SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Already have an account? Login',
style: TextStyle(
color: Colors.teal,
fontSize: 16,
),
),
),
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'loginpage.dart';
import 'profile.dart';
import 'settings.dart';
import 'logout.dart';
class FirstPageHome extends StatefulWidget {
@override
_FirstPageHomeState createState() => _FirstPageHomeState();
}
class _FirstPageHomeState extends State<FirstPageHome> {
int _currentPageIndex = 0;
final List<Widget> _pages = [
HomePage(),
ProfilePage(),
SettingsPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: ListView(
children: [
SizedBox(
height: 250,
child: DrawerHeader(
decoration: BoxDecoration(
color: Colors.teal[100],
),
child: Column(
children: [
CircleAvatar(
radius: 75,
backgroundImage: AssetImage('bata.jpeg'),
),
SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person),
SizedBox(width: 5),
Text(
'Ronel Mariscal',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.email),
SizedBox(width: 5),
Text(
'ronelmariscal76@gmail.com',
style: TextStyle(
fontSize: 16,
color: Colors.blue,
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline,
),
),
],
),
],
),
),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: () {
setState(() {
_currentPageIndex = 0;
});
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.person),
title: Text('Profile'),
onTap: () {
setState(() {
_currentPageIndex = 1;
});
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
onTap: () {
setState(() {
_currentPageIndex = 2;
});
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.power_settings_new),
title: Text('Logout'),
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Logout"),
content: Text('Are you sure you want to logout?'),
actions: [
TextButton(
child: Text('Cancel'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: Text('Ok'),
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (BuildContext context) => LoginPage(),
),
);
},
),
],
);
},
);
},
),
],
),
),
appBar: AppBar(
backgroundColor: Colors.teal,
centerTitle: true,
title: Text(_getAppBarTitle()),
),
body: _pages[_currentPageIndex],
);
}
String _getAppBarTitle() {
switch (_currentPageIndex) {
case 0:
return 'Home';
case 1:
return 'Profile';
case 2:
return 'Settings';
default:
return 'Flutter Activity';
}
}
}
// Home Page
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Card(
color: Colors.teal.shade100,
child: Padding(
padding: EdgeInsets.fromLTRB(30, 20, 30, 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
CircleAvatar(
radius: 75,
backgroundImage: AssetImage('assets/bata.jpeg'),
),
SizedBox(height: 10),
Text(
'Ronel Mariscal',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black54,
),
),
Text(
'Bachelor of Science in Information Technology',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.black54,
),
),
Text('21 Years Old'),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {},
child: Text('Welcome to Home Page'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
),
),
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'loginpage.dart';
import 'profile.dart';
import 'settings.dart';
import 'logout.dart';
class ProfilePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/bata.jpeg'),
),
SizedBox(width: 20),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Ronel Mariscal',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 8),
Text(
'ronelmariscal76@gmail.com',
style: TextStyle(
color: Colors.blue,
),
),
SizedBox(height: 8),
Text(
'BS Information Technology',
style: TextStyle(
color: Colors.grey[600],
),
),
],
),
),
],
),
),
),
SizedBox(height: 20),
Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Personal Information',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 16),
_buildInfoRow('Age', '21 years'),
_buildInfoRow('Student ID', '2024-03703'),
_buildInfoRow('Phone', '+63 9105791925'),
_buildInfoRow('Address',
'Buklod, Senator Ninoy Aquino, Sultan Kudarat'),
],
),
),
),
],
),
);
}
Widget _buildInfoRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Text(
'$label: ',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.teal,
),
),
Text(value),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'loginpage.dart';
import 'profile.dart';
import 'settings.dart';
import 'logout.dart';
class SettingsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Settings',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.teal,
),
),
SizedBox(height: 20),
Card(
elevation: 4,
child: Column(
children: [
_buildSettingsTile(
Icons.notifications,
'Notifications',
'Manage your notifications',
),
_buildSettingsTile(
Icons.security,
'Privacy',
'Control your privacy settings',
),
_buildSettingsTile(
Icons.language,
'Language',
'App language: English',
),
_buildSettingsTile(
Icons.dark_mode,
'Theme',
'Dark mode: Off',
),
],
),
),
SizedBox(height: 20),
Card(
elevation: 4,
child: Column(
children: [
_buildSettingsTile(
Icons.help,
'Help & Support',
'Get help and contact support',
),
_buildSettingsTile(
Icons.info,
'About',
'App version 1.0.0',
),
],
),
),
SizedBox(height: 20),
Center(
child: ElevatedButton(
onPressed: () {
// Add backup functionality
},
child: Text('Backup Data'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
),
),
),
],
),
);
}
Widget _buildSettingsTile(IconData icon, String title, String subtitle) {
return ListTile(
leading: Icon(icon, color: Colors.teal),
title: Text(title),
subtitle: Text(subtitle),
trailing: Icon(Icons.arrow_forward_ios, size: 16),
onTap: () {},
);
}
}
import 'package:flutter/material.dart';
import 'loginpage.dart';
class LogoutPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: () {
// Show confirmation dialog
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Logout'),
content: Text('Are you sure you want to log out?'),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context); // Close the dialog
},
child: Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LoginPage()),
);
},
child: Text('Logout'),
),
],
);
},
);
},
child: Text('Logout'),
),
);
}
}
Connect them all and you won't leave anything out of the code, you won't change anything, just connect them so that after I log in, I get redirected to the other page, you won't change anything, just really connect them.