fix showing local notifications

This commit is contained in:
Salvatore Giordano
2021-02-04 17:37:08 +01:00
parent 9284512d6a
commit be5755f27f
2 changed files with 11 additions and 3 deletions
+3 -2
View File
@@ -36,7 +36,7 @@ void main() async {
if (userId != null) {
final token = await secureStorage.read(key: kStreamToken);
await client.setUser(
await client.connectUser(
User(id: userId),
token,
);
@@ -67,7 +67,8 @@ class MyApp extends StatelessWidget {
builder: (context, child) {
return StreamChat(
client: client,
onBackgroundEventReceived: showLocalNotification,
onBackgroundEventReceived: (e) =>
showLocalNotification(e, client.state.user.id),
child: Builder(
builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>(
child: child,
@@ -2,7 +2,14 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'
hide Message;
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void showLocalNotification(Event event) async {
void showLocalNotification(Event event, String currentUserId) async {
if (![
EventType.messageNew,
EventType.notificationMessageNew,
].contains(event.type) ||
event.user.id == currentUserId) {
return;
}
if (event.message == null) return;
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final initializationSettingsAndroid =