fix showing local notifications
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user