fix showing local notifications
This commit is contained in:
@@ -36,7 +36,7 @@ void main() async {
|
|||||||
|
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
final token = await secureStorage.read(key: kStreamToken);
|
final token = await secureStorage.read(key: kStreamToken);
|
||||||
await client.setUser(
|
await client.connectUser(
|
||||||
User(id: userId),
|
User(id: userId),
|
||||||
token,
|
token,
|
||||||
);
|
);
|
||||||
@@ -67,7 +67,8 @@ class MyApp extends StatelessWidget {
|
|||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
return StreamChat(
|
return StreamChat(
|
||||||
client: client,
|
client: client,
|
||||||
onBackgroundEventReceived: showLocalNotification,
|
onBackgroundEventReceived: (e) =>
|
||||||
|
showLocalNotification(e, client.state.user.id),
|
||||||
child: Builder(
|
child: Builder(
|
||||||
builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>(
|
builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>(
|
||||||
child: child,
|
child: child,
|
||||||
|
|||||||
@@ -2,7 +2,14 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'
|
|||||||
hide Message;
|
hide Message;
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
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;
|
if (event.message == null) return;
|
||||||
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
final initializationSettingsAndroid =
|
final initializationSettingsAndroid =
|
||||||
|
|||||||
Reference in New Issue
Block a user