feat: implement profile page with settings

This commit is contained in:
sBubshait 2025-07-20 09:46:42 +03:00
parent f55491022f
commit dc11d3ec3e
4 changed files with 408 additions and 36 deletions

View File

@ -105,6 +105,15 @@ class _FeedPageState extends State<FeedPage> {
}, },
), ),
), ),
floatingActionButton: FloatingActionButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Create post functionality coming soon!')),
);
},
backgroundColor: Color(0xFF6A4C93),
child: Icon(Icons.edit, color: Colors.white),
),
); );
} }
} }

View File

@ -253,6 +253,15 @@ class _InvitationsPageState extends State<InvitationsPage> {
], ],
), ),
), ),
floatingActionButton: FloatingActionButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Create invitation functionality coming soon!')),
);
},
backgroundColor: Color(0xFF6A4C93),
child: Icon(Icons.person_add, color: Colors.white),
),
); );
} }
} }

View File

@ -12,6 +12,36 @@ class _ProfilePageState extends State<ProfilePage> {
final TextEditingController _tokenController = TextEditingController(); final TextEditingController _tokenController = TextEditingController();
bool isLoading = false; bool isLoading = false;
final List<Map<String, dynamic>> mockUserPosts = [
{
'id': '1',
'content':
'Just finished working on a new Flutter project! The development experience keeps getting better.',
'timestamp': '2 hours ago',
'likes': 15,
'comments': 4,
'isLiked': true,
},
{
'id': '2',
'content':
'Beautiful sunset from my office window today. Sometimes you need to take a moment to appreciate the simple things.',
'timestamp': '1 day ago',
'likes': 23,
'comments': 8,
'isLiked': false,
},
{
'id': '3',
'content':
'Excited to share that I completed my certification today! Hard work pays off.',
'timestamp': '3 days ago',
'likes': 42,
'comments': 12,
'isLiked': true,
},
];
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -28,7 +58,7 @@ class _ProfilePageState extends State<ProfilePage> {
setState(() { setState(() {
isLoading = true; isLoading = true;
}); });
try { try {
final token = await NotificationService().getToken(); final token = await NotificationService().getToken();
setState(() { setState(() {
@ -57,25 +87,333 @@ class _ProfilePageState extends State<ProfilePage> {
} }
} }
void _navigateToSettings() {
Navigator.of(
context,
).push(MaterialPageRoute(builder: (context) => SettingsPage()));
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text('Profile', style: TextStyle(fontWeight: FontWeight.w600)),
'Profile', backgroundColor: Colors.white,
style: TextStyle( foregroundColor: Color(0xFF6A4C93),
fontWeight: FontWeight.w600, elevation: 0,
actions: [
IconButton(
onPressed: _navigateToSettings,
icon: Icon(Icons.settings),
), ),
],
bottom: PreferredSize(
preferredSize: Size.fromHeight(1),
child: Container(height: 1, color: Colors.grey[200]),
), ),
),
body: SingleChildScrollView(
child: Column(
children: [
Container(
padding: EdgeInsets.all(24),
child: Column(
children: [
CircleAvatar(
radius: 50,
backgroundColor: Color(0xFF6A4C93),
child: Text(
'A',
style: TextStyle(
color: Colors.white,
fontSize: 36,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(height: 16),
Text(
'Abu Norah',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
SizedBox(height: 4),
Text(
'@yasser_hajri',
style: TextStyle(fontSize: 16, color: Colors.grey[600]),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
Text(
'${mockUserPosts.length}',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color(0xFF6A4C93),
),
),
Text(
'Posts',
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
],
),
Column(
children: [
Text(
'127',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color(0xFF6A4C93),
),
),
Text(
'Followers',
style: TextStyle(
fontSize: 14,
color: Colors.grey[600],
),
),
],
),
],
),
],
),
),
Container(
height: 1,
color: Colors.grey[200],
margin: EdgeInsets.symmetric(horizontal: 16),
),
SizedBox(height: 16),
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.symmetric(horizontal: 16),
itemCount: mockUserPosts.length,
itemBuilder: (context, index) {
final post = mockUserPosts[index];
return Container(
margin: EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: Offset(0, 2),
),
],
),
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
CircleAvatar(
radius: 16,
backgroundColor: Color(0xFF6A4C93),
child: Text(
'J',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Abu Norah',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
color: Colors.black87,
),
),
Text(
post['timestamp'],
style: TextStyle(
color: Colors.grey[600],
fontSize: 12,
),
),
],
),
),
],
),
SizedBox(height: 12),
Text(
post['content'],
style: TextStyle(
fontSize: 15,
height: 1.4,
color: Colors.black87,
),
),
SizedBox(height: 12),
Row(
children: [
Icon(
post['isLiked']
? Icons.favorite
: Icons.favorite_border,
color: post['isLiked']
? Colors.red
: Colors.grey[600],
size: 20,
),
SizedBox(width: 4),
Text(
'${post['likes']}',
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
),
),
SizedBox(width: 16),
Icon(
Icons.chat_bubble_outline,
color: Colors.grey[600],
size: 20,
),
SizedBox(width: 4),
Text(
'${post['comments']}',
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
),
),
],
),
],
),
),
);
},
),
SizedBox(height: 24),
],
),
),
);
}
}
class SettingsPage extends StatefulWidget {
@override
_SettingsPageState createState() => _SettingsPageState();
}
class _SettingsPageState extends State<SettingsPage> {
String? fcmToken;
final TextEditingController _tokenController = TextEditingController();
bool isLoading = false;
@override
void initState() {
super.initState();
_loadFCMToken();
}
@override
void dispose() {
_tokenController.dispose();
super.dispose();
}
Future<void> _loadFCMToken() async {
setState(() {
isLoading = true;
});
try {
final token = await NotificationService().getToken();
setState(() {
fcmToken = token;
_tokenController.text = token ?? 'Token not available';
isLoading = false;
});
} catch (e) {
setState(() {
fcmToken = null;
_tokenController.text = 'Error loading token: $e';
isLoading = false;
});
}
}
Future<void> _copyToClipboard() async {
if (fcmToken != null && fcmToken!.isNotEmpty) {
await Clipboard.setData(ClipboardData(text: fcmToken!));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('FCM Token copied to clipboard'),
backgroundColor: Color(0xFF6A4C93),
),
);
}
}
void _signOut() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Sign Out'),
content: Text('Are you sure you want to sign out?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Signed out successfully')),
);
},
child: Text('Sign Out', style: TextStyle(color: Colors.red)),
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Settings', style: TextStyle(fontWeight: FontWeight.w600)),
backgroundColor: Colors.white, backgroundColor: Colors.white,
foregroundColor: Color(0xFF6A4C93), foregroundColor: Color(0xFF6A4C93),
elevation: 0, elevation: 0,
bottom: PreferredSize( bottom: PreferredSize(
preferredSize: Size.fromHeight(1), preferredSize: Size.fromHeight(1),
child: Container( child: Container(height: 1, color: Colors.grey[200]),
height: 1,
color: Colors.grey[200],
),
), ),
), ),
body: Padding( body: Padding(
@ -92,7 +430,7 @@ class _ProfilePageState extends State<ProfilePage> {
), ),
), ),
SizedBox(height: 16), SizedBox(height: 16),
Text( Text(
'FCM Token:', 'FCM Token:',
style: TextStyle( style: TextStyle(
@ -102,7 +440,7 @@ class _ProfilePageState extends State<ProfilePage> {
), ),
), ),
SizedBox(height: 8), SizedBox(height: 8),
if (isLoading) if (isLoading)
Center( Center(
child: CircularProgressIndicator( child: CircularProgressIndicator(
@ -122,10 +460,7 @@ class _ProfilePageState extends State<ProfilePage> {
controller: _tokenController, controller: _tokenController,
readOnly: true, readOnly: true,
maxLines: 4, maxLines: 4,
style: TextStyle( style: TextStyle(fontSize: 12, fontFamily: 'monospace'),
fontSize: 12,
fontFamily: 'monospace',
),
decoration: InputDecoration( decoration: InputDecoration(
border: InputBorder.none, border: InputBorder.none,
contentPadding: EdgeInsets.all(12), contentPadding: EdgeInsets.all(12),
@ -134,7 +469,7 @@ class _ProfilePageState extends State<ProfilePage> {
), ),
), ),
SizedBox(height: 8), SizedBox(height: 8),
Row( Row(
children: [ children: [
ElevatedButton.icon( ElevatedButton.icon(
@ -166,9 +501,28 @@ class _ProfilePageState extends State<ProfilePage> {
), ),
], ],
), ),
SizedBox(height: 32),
Container(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _signOut,
icon: Icon(Icons.logout, color: Colors.red),
label: Text('Sign Out', style: TextStyle(color: Colors.red)),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
side: BorderSide(color: Colors.red),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
padding: EdgeInsets.symmetric(vertical: 16),
),
),
),
], ],
), ),
), ),
); );
} }
} }

View File

@ -16,7 +16,7 @@ class NotificationService {
// Firebase project configuration // Firebase project configuration
static const String _projectId = 'wesalapp-bc676'; static const String _projectId = 'wesalapp-bc676';
// Service account credentials (JSON string) // Service account credentials (JSON string)
static const String _serviceAccountJson = ''' static const String _serviceAccountJson = '''
{ {
@ -259,15 +259,16 @@ class NotificationService {
Future<String?> _getAccessToken() async { Future<String?> _getAccessToken() async {
try { try {
final credentials = ServiceAccountCredentials.fromJson(_serviceAccountJson); final credentials = ServiceAccountCredentials.fromJson(
final client = await clientViaServiceAccount( _serviceAccountJson,
credentials,
['https://www.googleapis.com/auth/firebase.messaging'],
); );
final client = await clientViaServiceAccount(credentials, [
'https://www.googleapis.com/auth/firebase.messaging',
]);
final token = client.credentials.accessToken.data; final token = client.credentials.accessToken.data;
client.close(); client.close();
return token; return token;
} catch (e) { } catch (e) {
print('Error getting access token: $e'); print('Error getting access token: $e');
@ -288,7 +289,9 @@ class NotificationService {
return false; return false;
} }
final url = Uri.parse('https://fcm.googleapis.com/v1/projects/$_projectId/messages:send'); final url = Uri.parse(
'https://fcm.googleapis.com/v1/projects/$_projectId/messages:send',
);
final headers = { final headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken', 'Authorization': 'Bearer $accessToken',
@ -297,10 +300,7 @@ class NotificationService {
final payload = { final payload = {
'message': { 'message': {
'token': token, 'token': token,
'notification': { 'notification': {'title': title, 'body': body},
'title': title,
'body': body,
},
'data': data ?? {}, 'data': data ?? {},
'webpush': { 'webpush': {
'notification': { 'notification': {
@ -348,7 +348,9 @@ class NotificationService {
return false; return false;
} }
final url = Uri.parse('https://fcm.googleapis.com/v1/projects/$_projectId/messages:send'); final url = Uri.parse(
'https://fcm.googleapis.com/v1/projects/$_projectId/messages:send',
);
final headers = { final headers = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken', 'Authorization': 'Bearer $accessToken',
@ -357,10 +359,7 @@ class NotificationService {
final payload = { final payload = {
'message': { 'message': {
'topic': topic, 'topic': topic,
'notification': { 'notification': {'title': title, 'body': body},
'title': title,
'body': body,
},
'data': data ?? {}, 'data': data ?? {},
'webpush': { 'webpush': {
'notification': { 'notification': {
@ -394,8 +393,9 @@ class NotificationService {
Future<bool> sendCoffeeInviteAcceptedNotification() async { Future<bool> sendCoffeeInviteAcceptedNotification() async {
// Send to specific token for testing // Send to specific token for testing
const testToken = 'cetNA4PmdzwBS075-zdvbP:APA91bEDAqLC0D4txAaiYAdzzfk43yk99tKlC_x3Tii24qHdyhIzuQifsJG4Rm_oijvdVkbsoQUm3tQso34_71OvU-kQsqZTrMOQVIvHkIul7PYqOODFJUA'; const testToken =
'evEF6UT53IkV98ku-MR1bH:APA91bGE52wWTUBm_cOoQ0GeGy6gUgpHhaZquB0Y0L_eyoosFZvE8lMuiQrhhVZ81tw-lB_baC7en0Bk1JIVGAuIj6KyFHKeuoPJVbntHh7HtEZDBEeJRkc';
return await sendNotificationToToken( return await sendNotificationToToken(
testToken, testToken,
'Coffee Time! ☕', 'Coffee Time! ☕',