-
Notifications
You must be signed in to change notification settings - Fork 152
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
[UI] Notifications Screen with mock data #337
Merged
Aarush-Acharya
merged 4 commits into
AOSSIE-Org:dev
from
AyaNady17:Feature/implement-notification-screen-ui
Oct 1, 2024
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b03435e
[UI] Notifciations Screen with mock data
AyaNady17 79b33c4
Merge branch 'dev' into Feature/implement-notification-screen-ui
AyaNady17 c8e37c8
Apply comments
AyaNady17 9afb077
Merge branch 'dev' into Feature/implement-notification-screen-ui
Aarush-Acharya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:get/get_core/src/get_main.dart'; | ||
import 'package:resonate/views/new_screens/new_profile_screen.dart'; | ||
|
||
class NewNotificationsScreen extends StatelessWidget { | ||
final List<NotificationModel> notifications = getMockNotifications(); | ||
|
||
NewNotificationsScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.background, | ||
elevation: 0, | ||
leading: IconButton( | ||
icon: const Icon( | ||
Icons.keyboard_arrow_down, | ||
// color: Colors.black, | ||
size: 36, | ||
), | ||
onPressed: () => Navigator.of(context).pop(), | ||
), | ||
title: const Text('Notifications'), | ||
actions: [ | ||
Padding( | ||
padding: const EdgeInsets.only(right: 16.0, left: 16), | ||
child: InkWell( | ||
child: const CircleAvatar( | ||
backgroundImage: NetworkImage( | ||
'https://img.freepik.com/free-vector/user-blue-gradient_78370-4692.jpg?ga=GA1.1.338869508.1708106114&semt=sph'), | ||
), | ||
onTap: () { | ||
Get.to(const NewProfileScreen()); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
body: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: AnimatedList( | ||
initialItemCount: notifications.length, | ||
itemBuilder: (context, index, animation) { | ||
final notification = notifications[index]; | ||
return Card( | ||
color: Theme.of(context).colorScheme.primary, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(20.0), | ||
), | ||
elevation: 5, | ||
shadowColor: Colors.grey.shade300, | ||
margin: const EdgeInsets.symmetric(vertical: 10.0), | ||
child: ListTile( | ||
contentPadding: const EdgeInsets.symmetric( | ||
horizontal: 20.0, vertical: 15.0), | ||
leading: CircleAvatar( | ||
backgroundColor: notification.isRead | ||
? Colors.grey.shade300 | ||
: Colors.blue.shade100, | ||
child: Icon( | ||
notification.isRead | ||
? Icons.notifications_none | ||
: Icons.notifications, | ||
color: notification.isRead ? Colors.grey : Colors.blue, | ||
), | ||
), | ||
title: Text( | ||
notification.title, | ||
style: TextStyle( | ||
fontWeight: FontWeight.bold, | ||
fontSize: 18.0, | ||
color: Theme.of(context).colorScheme.onPrimary, | ||
), | ||
), | ||
subtitle: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const SizedBox(height: 8), | ||
Text( | ||
notification.message, | ||
style: TextStyle( | ||
fontSize: 16.0, | ||
color: Theme.of(context).colorScheme.secondary, | ||
), | ||
), | ||
const SizedBox(height: 8), | ||
Text( | ||
_formatDateTime(notification.dateTime), | ||
style: TextStyle( | ||
fontSize: 14.0, | ||
color: Colors.grey.shade500, | ||
), | ||
), | ||
], | ||
), | ||
trailing: Icon(Icons.arrow_forward_ios, | ||
size: 16.0, color: Colors.grey.shade400), | ||
onTap: () { | ||
// Handle notification tap | ||
}, | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
|
||
String _formatDateTime(DateTime dateTime) { | ||
final now = DateTime.now(); | ||
final difference = now.difference(dateTime); | ||
|
||
if (difference.inMinutes < 60) { | ||
return '${difference.inMinutes} minutes ago'; | ||
} else if (difference.inHours < 24) { | ||
return '${difference.inHours} hours ago'; | ||
} else if (difference.inDays < 7) { | ||
return '${difference.inDays} days ago'; | ||
} else { | ||
return dateTime.toIso8601String(); | ||
} | ||
} | ||
} | ||
|
||
class NotificationModel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to models folder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
final String title; | ||
final String message; | ||
final DateTime dateTime; | ||
final bool isRead; | ||
|
||
NotificationModel({ | ||
required this.title, | ||
required this.message, | ||
required this.dateTime, | ||
this.isRead = false, | ||
}); | ||
} | ||
|
||
List<NotificationModel> getMockNotifications() { | ||
return [ | ||
NotificationModel( | ||
title: "Welcome to Resonate!", | ||
message: "Start by exploring rooms and joining conversations.", | ||
dateTime: DateTime.now().subtract(const Duration(minutes: 5)), | ||
), | ||
NotificationModel( | ||
title: "New Follow Request", | ||
message: "John Doe has requested to follow you.", | ||
dateTime: DateTime.now().subtract(const Duration(hours: 1)), | ||
), | ||
NotificationModel( | ||
title: "Room Recommendation", | ||
message: "Join the 'Flutter Developers' room happening now.", | ||
dateTime: DateTime.now().subtract(const Duration(days: 1)), | ||
isRead: true, | ||
), | ||
NotificationModel( | ||
title: "Room Recommendation", | ||
message: "Join the 'Flutter Developers' room happening now.", | ||
dateTime: DateTime.now().subtract(const Duration(days: 1)), | ||
isRead: true, | ||
), | ||
NotificationModel( | ||
title: "New Follow Request", | ||
message: "John Doe has requested to follow you.", | ||
dateTime: DateTime.now().subtract(const Duration(hours: 1)), | ||
), | ||
]; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use an asset image here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done