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

[SCRUM-6] Implement profile page ui #2

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
Binary file added frontend/assets/Default_pfp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions frontend/lib/common/router.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:go_router/go_router.dart';
import 'package:utm_marketplace/views/login.dart';
import 'package:utm_marketplace/views/profile.dart';

// TODO: These are temporary imports for testing purposes, remove when no longer needed
import 'package:utm_marketplace/views/model_view.dart';
import 'package:utm_marketplace/models/model.dart';
import 'package:utm_marketplace/views/home.dart';

// Define the router as a top-level global variable
final GoRouter router = GoRouter(
Expand All @@ -18,5 +20,14 @@ final GoRouter router = GoRouter(
builder: (context, state) =>
ModelView(model: Model(attribute1: 'Attribute 1', attribute2: 2)),
),
GoRoute(
path: '/profile',
builder: (context, state) => const Profile(),
),
GoRoute(
path: '/home',
builder: (context, state) => const HomePage(),
),
],
);

23 changes: 23 additions & 0 deletions frontend/lib/views/home.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

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

@override
Widget build(BuildContext context) {
return Scaffold(
Marwanyx marked this conversation as resolved.
Show resolved Hide resolved
appBar: AppBar(
title: const Text('Home'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
context.go('/profile');
},
child: const Text('Go to Profile'),
),
),
);
}
}
2 changes: 1 addition & 1 deletion frontend/lib/views/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LoginState extends State<Login> {
// TODO: Implement login functionality (backend)
// If this condition passed, a redirect call to the home
// page should be made
context.go('/temp_view');
context.go('/home'); // TODO: JUST FOR DEBUGGING
}
},
style: ElevatedButton.styleFrom(
Expand Down
236 changes: 236 additions & 0 deletions frontend/lib/views/profile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
import 'package:flutter/material.dart';
import 'package:utm_marketplace/common/theme.dart';
import 'package:go_router/go_router.dart';

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

@override
State<Profile> createState() => _ProfileState();
}

class _ProfileState extends State<Profile> {
String userName = 'Aubrey Drake'; // Added state variable, replace with actual user name from backend

@override
Widget build(BuildContext context) {
return SafeArea(
Marwanyx marked this conversation as resolved.
Show resolved Hide resolved
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
context.go('/home');
},
),
title: Text('Profile'),
Marwanyx marked this conversation as resolved.
Show resolved Hide resolved
actions: [
IconButton(
icon: Icon(Icons.settings),
onPressed: () {
// TODO: Implement settings navigation
},
),
],
),
body: SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
// Profile Picture
CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/Default_pfp.jpg'),
// TODO: Replace with actual user profile picture from backend---db
),
SizedBox(height: 16),

// User Name
StyleText(
text: userName, // Updated to use state variable
style: ThemeText.header.copyWith(fontSize: 24),
),

// Email
Text(
'aubreydrake@mail.utoronto.ca', // TODO: Replace with actual email from backend
style: TextStyle(
color: Colors.grey[600],
fontSize: 16,
),
),
SizedBox(height: 24),

// Stats Row
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// TODO: Replace with actual stats from backend
_buildStatColumn('Listings', '12'),
_buildStatColumn('Sold', '8'),
_buildStatColumn('Rating', '4.5'),
],
),

SizedBox(height: 24),

// Action Buttons
_buildActionButton('My Listings', Icons.list_alt, () {
// TODO: Navigate to listings
}),
_buildActionButton('Saved Items', Icons.favorite_border, () {
// TODO: Navigate to saved items
}),
_buildActionButton('Purchase History', Icons.history, () {
// TODO: Navigate to purchase history
}),
_buildActionButton('Edit Profile', Icons.edit, () {
_showEditProfileDialog(context); // added this temporary dailog
}),
],
),
),
),
);
}

Widget _buildStatColumn(String label, String value) {
return Column(
children: [
Text(
value,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
label,
style: TextStyle(
color: Colors.grey[600],
),
),
],
);
}

Widget _buildActionButton(String label, IconData icon, VoidCallback onPressed) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
minimumSize: Size(double.infinity, 50),
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(horizontal: 16),
),
child: Row(
children: [
Icon(icon),
SizedBox(width: 16),
Text(label),
Spacer(),
Icon(Icons.chevron_right),
],
),
),
);
}

void _showEditProfileDialog(BuildContext context) {
Marwanyx marked this conversation as resolved.
Show resolved Hide resolved
final TextEditingController firstNameController = TextEditingController();
final TextEditingController lastNameController = TextEditingController();

showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Edit Profile'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: () {
// TODO: Implement image picker
},
child: Stack(
children: [
CircleAvatar(
radius: 40,
backgroundImage: AssetImage('assets/Default_pfp.jpg'), // TODO: Replace with actual user profile picture from backend---db
),
Positioned(
bottom: 0,
right: 0,
child: Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
shape: BoxShape.circle,
),
child: Icon(
Icons.camera_alt,
color: Colors.white,
size: 16,
),
),
),
],
),
),
SizedBox(height: 16),
TextField(
controller: firstNameController,
decoration: InputDecoration(
labelText: 'First Name',
border: OutlineInputBorder(),
),
),
SizedBox(height: 8),
TextField(
controller: lastNameController,
decoration: InputDecoration(
labelText: 'Last Name',
border: OutlineInputBorder(),
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('Cancel'),
),
ElevatedButton(
onPressed: () async {
final String firstName = firstNameController.text.trim();
final String lastName = lastNameController.text.trim();

if (firstName.isEmpty || lastName.isEmpty) {
Marwanyx marked this conversation as resolved.
Show resolved Hide resolved
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Please fill in both names'))
);
return;
}

// TODO: Backend - Send request to update user profile

setState(() {
userName = '$firstName $lastName';
});

Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Profile updated successfully'))
);
},
child: Text('Save'),
),
],
);
},
);
}
}
2 changes: 2 additions & 0 deletions frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ flutter:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- assets/Default_pfp.jpg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
Expand Down
Loading