Skip to content

Commit

Permalink
Merge pull request #337 from AyaNady17/Feature/implement-notification…
Browse files Browse the repository at this point in the history
…-screen-ui

[UI] Notifications Screen with mock data
  • Loading branch information
Aarush-Acharya authored Oct 1, 2024
2 parents 773e59e + 9afb077 commit ecd8c9c
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 3 deletions.
Binary file added assets/images/user.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions lib/models/mock_models/notification_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class NotificationModel {
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,
});
}
5 changes: 5 additions & 0 deletions lib/routes/app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:resonate/routes/app_routes.dart';
import 'package:resonate/views/new_screens/new_create_room_screen.dart';
import 'package:resonate/views/new_screens/new_home_screen.dart';
import 'package:resonate/views/new_screens/new_login_screen.dart';
import 'package:resonate/views/new_screens/new_notifications_screen.dart';
import 'package:resonate/views/new_screens/new_pair_chat_screen.dart';
import 'package:resonate/views/new_screens/new_pairing_screen.dart';
import 'package:resonate/views/new_screens/new_room_chat_screen.dart';
Expand Down Expand Up @@ -219,6 +220,10 @@ class AppPages {
name: AppRoutes.aboutApp,
page: () => AboutAppScreen(),
),
GetPage(
name: AppRoutes.newNotificationsScreen,
page: () => NewNotificationsScreen(),
),
GetPage(
name: AppRoutes.contributeScreen,
page: () => const ContributeScreen(),
Expand Down
1 change: 1 addition & 0 deletions lib/routes/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AppRoutes {
static const newWelcomeScreen = '/newWelcomeScreen';
static const themeScreen = '/themeScreen';
static const userAccountScreen = '/userAccountScreen';
static const newNotificationsScreen = '/newNotificationsScreen';
static const newPairChatScreen = '/newPairChatScreen';
static const newPairingScreen = '/newPairingScreen';
static const aboutApp = "/aboutApp";
Expand Down
11 changes: 8 additions & 3 deletions lib/views/new_screens/new_home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:resonate/models/appwrite_room.dart';
import 'package:resonate/utils/enums/room_state.dart';
import 'package:resonate/views/new_screens/new_notifications_screen.dart';

class NewHomeScreen extends StatefulWidget {
const NewHomeScreen({super.key});
Expand Down Expand Up @@ -112,9 +114,12 @@ class CustomAppBarLiveRoom extends StatelessWidget {
const SizedBox(
width: 15,
),
Icon(
Icons.notifications_none_rounded,
color: Theme.of(context).colorScheme.primary,
IconButton(
icon: Icon(
Icons.notifications_none_rounded,
color: Theme.of(context).colorScheme.primary,
),
onPressed: () => Get.to(NewNotificationsScreen()),
),
const SizedBox(width: 15),
const CustomCircleAvatar(
Expand Down
158 changes: 158 additions & 0 deletions lib/views/new_screens/new_notifications_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:resonate/models/mock_models/notification_model.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: AssetImage(
"assets/images/user.jpeg",
),
),
onTap: () {
Get.to(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();
}
}
}

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)),
),
];
}

0 comments on commit ecd8c9c

Please sign in to comment.