Skip to content

Commit 1a31de6

Browse files
committed
feat: initial notifications implementationg
1 parent 07bf533 commit 1a31de6

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
55
void main() async {
66
WidgetsFlutterBinding.ensureInitialized();
77

8-
notificationRepository.setup();
8+
await notificationRepository.setup();
99

1010
runApp(MyApp());
1111
}

lib/src/features/messages/views/widgets/messages.dart

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -211,25 +211,40 @@ class _Messages extends StatelessWidget {
211211
return Container();
212212
}
213213

214-
return Scrollbar(
215-
child: ListView(
216-
controller: scrollController,
217-
keyboardDismissBehavior:
218-
ScrollViewKeyboardDismissBehavior.onDrag,
219-
children: [
220-
for (final message in state.messages)
214+
return ListView(
215+
controller: scrollController,
216+
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
217+
children: [
218+
for (final message in state.messages)
219+
Padding(
220+
padding: const EdgeInsets.symmetric(horizontal: 8.0),
221+
child: Column(
222+
crossAxisAlignment: CrossAxisAlignment.start,
223+
children: [
224+
if (message == state.messages[0])
225+
SizedBox(
226+
height: 20,
227+
),
228+
_Message(
229+
message: message,
230+
from: message.from,
231+
currentUser: user,
232+
),
233+
SizedBox(
234+
height: 20,
235+
),
236+
],
237+
),
238+
),
239+
for (final typing in state.usersTyping)
240+
if (typing.id != user.id)
221241
Padding(
222242
padding: const EdgeInsets.symmetric(horizontal: 8.0),
223243
child: Column(
224244
crossAxisAlignment: CrossAxisAlignment.start,
225245
children: [
226-
if (message == state.messages[0])
227-
SizedBox(
228-
height: 20,
229-
),
230246
_Message(
231-
message: message,
232-
from: message.from,
247+
from: typing,
233248
currentUser: user,
234249
),
235250
SizedBox(
@@ -238,25 +253,7 @@ class _Messages extends StatelessWidget {
238253
],
239254
),
240255
),
241-
for (final typing in state.usersTyping)
242-
if (typing.id != user.id)
243-
Padding(
244-
padding: const EdgeInsets.symmetric(horizontal: 8.0),
245-
child: Column(
246-
crossAxisAlignment: CrossAxisAlignment.start,
247-
children: [
248-
_Message(
249-
from: typing,
250-
currentUser: user,
251-
),
252-
SizedBox(
253-
height: 20,
254-
),
255-
],
256-
),
257-
),
258-
],
259-
),
256+
],
260257
);
261258
},
262259
);

lib/src/features/notification/logic/repository/notification_repository.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ class NotificationRepository {
4141
void _handleForegroundMessage(BuildContext context, RemoteMessage message) {
4242
final type = message.data['type'];
4343

44+
SnackBar? snackBar;
45+
4446
if (type == NotificationType.room.name) {
45-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
47+
snackBar = SnackBar(
4648
content: Text(
4749
'Message received from Room: ${message.data['title']}',
4850
),
@@ -53,11 +55,11 @@ class NotificationRepository {
5355
message.data['roomId'],
5456
),
5557
),
56-
));
58+
);
5759
}
5860

5961
if (type == NotificationType.direct.name) {
60-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
62+
snackBar = SnackBar(
6163
content: Text(
6264
'Message received from User: ${message.data['username']}',
6365
),
@@ -68,8 +70,14 @@ class NotificationRepository {
6870
message.data['username'],
6971
),
7072
),
71-
));
73+
);
7274
}
75+
76+
if (snackBar == null) {
77+
return;
78+
}
79+
80+
ScaffoldMessenger.of(context).showSnackBar(snackBar);
7381
}
7482

7583
void _handleBackgroundMessage(BuildContext context, RemoteMessage message) {

0 commit comments

Comments
 (0)