Skip to content

Commit 259c0e9

Browse files
committed
dismiss notifications while clicked
1 parent fb2a36a commit 259c0e9

File tree

7 files changed

+81
-30
lines changed

7 files changed

+81
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@
3535
* fix ios recording and enable notification clicks to open the chat page
3636

3737
## 0.2.1
38-
* encrypt user access token
38+
* encrypt user access token
39+
40+
## 0.2.5
41+
* support android 12

example/pubspec.lock

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ packages:
140140
name: dio
141141
url: "https://pub.dartlang.org"
142142
source: hosted
143-
version: "4.0.1"
143+
version: "4.0.3"
144144
fake_async:
145145
dependency: transitive
146146
description:
@@ -250,7 +250,7 @@ packages:
250250
name: flutter_local_notifications
251251
url: "https://pub.dartlang.org"
252252
source: hosted
253-
version: "9.1.1"
253+
version: "9.1.2"
254254
flutter_local_notifications_linux:
255255
dependency: transitive
256256
description:
@@ -290,7 +290,7 @@ packages:
290290
name: flutter_secure_storage
291291
url: "https://pub.dartlang.org"
292292
source: hosted
293-
version: "5.0.0"
293+
version: "5.0.2"
294294
flutter_secure_storage_linux:
295295
dependency: transitive
296296
description:
@@ -489,7 +489,21 @@ packages:
489489
name: path_provider
490490
url: "https://pub.dartlang.org"
491491
source: hosted
492-
version: "2.0.6"
492+
version: "2.0.7"
493+
path_provider_android:
494+
dependency: transitive
495+
description:
496+
name: path_provider_android
497+
url: "https://pub.dartlang.org"
498+
source: hosted
499+
version: "2.0.7"
500+
path_provider_ios:
501+
dependency: transitive
502+
description:
503+
name: path_provider_ios
504+
url: "https://pub.dartlang.org"
505+
source: hosted
506+
version: "2.0.7"
493507
path_provider_linux:
494508
dependency: transitive
495509
description:
@@ -531,7 +545,7 @@ packages:
531545
name: permission_handler
532546
url: "https://pub.dartlang.org"
533547
source: hosted
534-
version: "8.2.6"
548+
version: "8.3.0"
535549
permission_handler_platform_interface:
536550
dependency: transitive
537551
description:
@@ -739,7 +753,7 @@ packages:
739753
path: ".."
740754
relative: true
741755
source: path
742-
version: "0.2.4"
756+
version: "0.2.5"
743757
vector_math:
744758
dependency: transitive
745759
description:

lib/src/modules/message/views/message_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class _MessageViewState extends State<MessageView> {
3636
Widget build(BuildContext context) {
3737
final t = VChatAppService.to.getTrans(context);
3838
return Scaffold(
39-
appBar: MessageAppBarView(),
39+
appBar: MessageAppBarView(),
4040
body: Padding(
4141
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 1, top: 4),
4242
child: Column(

lib/src/services/notification_service.dart

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:get/get.dart';
77
import 'package:v_chat_sdk/src/modules/message/bindings/message_binding.dart';
88
import 'package:v_chat_sdk/src/modules/message/views/message_view.dart';
99
import 'package:v_chat_sdk/src/services/v_chat_app_service.dart';
10-
import 'package:v_chat_sdk/src/utils/helpers/helpers.dart';
1110
import '../modules/room/controllers/rooms_controller.dart';
1211
import '../utils/api_utils/dio/custom_dio.dart';
1312

@@ -44,6 +43,7 @@ class NotificationService extends GetxService {
4443
void init() async {
4544
final messaging = FirebaseMessaging.instance;
4645
messaging.setAutoInitEnabled(true);
46+
4747
await messaging.getToken();
4848

4949
await messaging.requestPermission(
@@ -56,19 +56,33 @@ class NotificationService extends GetxService {
5656
sound: true,
5757
);
5858

59-
await FirebaseMessaging.instance
60-
.setForegroundNotificationPresentationOptions(
59+
await messaging.setForegroundNotificationPresentationOptions(
6160
alert: true,
6261
badge: true,
6362
sound: true,
6463
);
65-
64+
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
65+
if (message.notification != null) {
66+
final roomId = int.parse(message.data['roomId'].toString());
67+
try {
68+
if (!_roomController.isRoomOpen(roomId)) {
69+
await Future.delayed(const Duration(milliseconds: 100));
70+
Get.find<RoomController>().currentRoomId = roomId;
71+
MessageBinding.bind();
72+
Navigator.of(VChatAppService.to.navKey!.currentContext!)
73+
.push(MaterialPageRoute(builder: (_) => const MessageView()));
74+
}
75+
} catch (err) {
76+
//
77+
}
78+
}
79+
});
6680
await flutterLocalNotificationsPlugin
6781
.resolvePlatformSpecificImplementation<
6882
AndroidFlutterLocalNotificationsPlugin>()
6983
?.createNotificationChannel(channel);
7084

71-
FirebaseMessaging.instance.onTokenRefresh.listen((event) async {
85+
messaging.onTokenRefresh.listen((event) async {
7286
await CustomDio().send(
7387
reqMethod: "PATCH",
7488
path: "user",
@@ -86,6 +100,7 @@ class NotificationService extends GetxService {
86100
}
87101
}
88102
});
103+
89104
messaging.getInitialMessage().then((RemoteMessage? message) async {
90105
if (message != null) {
91106
try {
@@ -103,18 +118,20 @@ class NotificationService extends GetxService {
103118
}
104119
});
105120
flutterLocalNotificationsPlugin.cancelAll();
106-
//show();
107121
}
108122

109123
static void showNotification(
110124
{required String title, required String msg, required int roomId}) {
111125
BotToast.showSimpleNotification(
112126
title: title.toString(),
113127
onTap: () {
114-
Get.find<RoomController>().currentRoomId = roomId;
115-
MessageBinding.bind();
116-
Navigator.of(VChatAppService.to.navKey!.currentContext!)
117-
.push(MaterialPageRoute(builder: (_) => const MessageView()));
128+
final _roomController = Get.find<RoomController>();
129+
if (!_roomController.isRoomOpen(roomId)) {
130+
Get.find<RoomController>().currentRoomId = roomId;
131+
MessageBinding.bind();
132+
Navigator.of(VChatAppService.to.navKey!.currentContext!)
133+
.push(MaterialPageRoute(builder: (_) => const MessageView()));
134+
}
118135
BotToast.cleanAll();
119136
},
120137
duration: const Duration(seconds: 5),

lib/src/vchat_controller.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ class VChatController {
195195
);
196196
} else {
197197
// there are room
198-
return await _navigateToRoomMessage(data, ctx ?? VChatAppService.to.navKey!.currentContext!,);
198+
return await _navigateToRoomMessage(
199+
data,
200+
ctx ?? VChatAppService.to.navKey!.currentContext!,
201+
);
199202
}
200203
}
201204

pubspec.lock

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ packages:
133133
name: dio
134134
url: "https://pub.dartlang.org"
135135
source: hosted
136-
version: "4.0.1"
136+
version: "4.0.3"
137137
fake_async:
138138
dependency: transitive
139139
description:
@@ -236,7 +236,7 @@ packages:
236236
name: flutter_local_notifications
237237
url: "https://pub.dartlang.org"
238238
source: hosted
239-
version: "9.1.1"
239+
version: "9.1.2"
240240
flutter_local_notifications_linux:
241241
dependency: transitive
242242
description:
@@ -271,7 +271,7 @@ packages:
271271
name: flutter_secure_storage
272272
url: "https://pub.dartlang.org"
273273
source: hosted
274-
version: "5.0.0"
274+
version: "5.0.2"
275275
flutter_secure_storage_linux:
276276
dependency: transitive
277277
description:
@@ -463,7 +463,21 @@ packages:
463463
name: path_provider
464464
url: "https://pub.dartlang.org"
465465
source: hosted
466-
version: "2.0.6"
466+
version: "2.0.7"
467+
path_provider_android:
468+
dependency: transitive
469+
description:
470+
name: path_provider_android
471+
url: "https://pub.dartlang.org"
472+
source: hosted
473+
version: "2.0.7"
474+
path_provider_ios:
475+
dependency: transitive
476+
description:
477+
name: path_provider_ios
478+
url: "https://pub.dartlang.org"
479+
source: hosted
480+
version: "2.0.7"
467481
path_provider_linux:
468482
dependency: transitive
469483
description:
@@ -505,7 +519,7 @@ packages:
505519
name: permission_handler
506520
url: "https://pub.dartlang.org"
507521
source: hosted
508-
version: "8.2.6"
522+
version: "8.3.0"
509523
permission_handler_platform_interface:
510524
dependency: transitive
511525
description:

pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: v_chat_sdk
22
description: official sdk for vchat to impement chat system into new or exist flutter app
3-
version: 0.2.4
3+
version: 0.2.5
44
homepage: https://github.com/hatemragab/v_chat_sdk
55

66
environment:
@@ -13,17 +13,17 @@ dependencies:
1313
http: ^0.13.4
1414
textless: ^6.6.6
1515
get: ^4.3.8
16-
dio: ^4.0.1
16+
dio: ^4.0.3
1717
firebase_core: ^1.10.0
1818
firebase_messaging: ^11.1.0
1919
image_picker: ^0.8.4+4
2020
sqflite: ^2.0.0+4
21-
path_provider: ^2.0.6
21+
path_provider: ^2.0.7
2222
socket_io_client: ^1.0.1
2323
intl: ^0.17.0
2424
file_picker: ^4.2.3
2525
flutter_native_image: ^0.0.6+1
26-
permission_handler: ^8.2.6
26+
permission_handler: ^8.3.0
2727
flutter_video_info: ^1.2.0
2828
video_thumbnail: ^0.4.3
2929
video_player: ^2.2.7
@@ -35,11 +35,11 @@ dependencies:
3535
chewie: ^1.2.2
3636
cached_network_image: ^3.1.0+1
3737
timeago: ^3.1.0
38-
flutter_local_notifications: ^9.1.1
38+
flutter_local_notifications: ^9.1.2
3939
bot_toast: ^4.0.1
4040
google_fonts: ^2.1.0
4141
path: ^1.8.0
42-
flutter_secure_storage: ^5.0.0
42+
flutter_secure_storage: ^5.0.2
4343
get_storage: ^2.0.3
4444
dev_dependencies:
4545
flutter_test:

0 commit comments

Comments
 (0)