Transfer showLocalNotification, backgroundKeepAlive from LLC to Core
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -277,9 +277,6 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
|
||||
final client = Client(
|
||||
apiKey,
|
||||
logLevel: Level.INFO,
|
||||
showLocalNotification: (!kIsWeb && Platform.isAndroid)
|
||||
? showLocalNotification
|
||||
: null,
|
||||
)..chatPersistenceClient = chatPersistentClient;
|
||||
|
||||
try {
|
||||
|
||||
@@ -33,8 +33,6 @@ void main() async {
|
||||
final client = Client(
|
||||
apiKey ?? kDefaultStreamApiKey,
|
||||
logLevel: Level.INFO,
|
||||
showLocalNotification:
|
||||
(!kIsWeb && Platform.isAndroid) ? showLocalNotification : null,
|
||||
)..chatPersistenceClient = chatPersistentClient;
|
||||
|
||||
if (userId != null) {
|
||||
@@ -73,6 +71,7 @@ class MyApp extends StatelessWidget {
|
||||
builder: (context, child) {
|
||||
return StreamChat(
|
||||
client: client,
|
||||
onBackgroundEventReceived: showLocalNotification,
|
||||
child: Builder(
|
||||
builder: (context) => AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
child: child,
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:example/main.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter_apns/flutter_apns.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'
|
||||
hide Message;
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
void showLocalNotification(Message message, ChannelModel channel) async {
|
||||
void showLocalNotification(Event event) async {
|
||||
if (event.message == null) return;
|
||||
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
final initializationSettingsAndroid =
|
||||
AndroidInitializationSettings('launch_background');
|
||||
@@ -17,9 +19,9 @@ void showLocalNotification(Message message, ChannelModel channel) async {
|
||||
);
|
||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
||||
await flutterLocalNotificationsPlugin.show(
|
||||
message.id.hashCode,
|
||||
'${message.user.name} @ ${channel.name}',
|
||||
message.text,
|
||||
event.message.id.hashCode,
|
||||
event.message.user.name,
|
||||
event.message.text,
|
||||
NotificationDetails(
|
||||
android: AndroidNotificationDetails(
|
||||
'message channel',
|
||||
@@ -35,24 +37,24 @@ void showLocalNotification(Message message, ChannelModel channel) async {
|
||||
|
||||
Future backgroundHandler(Map<String, dynamic> notification) async {
|
||||
print('new notification ${notification}');
|
||||
final messageId = notification['data']['id'];
|
||||
|
||||
final notificationData = await NotificationService.getAndStoreMessage(
|
||||
messageId: messageId,
|
||||
storeMessageHandler: (messageResponse) {
|
||||
return chatPersistentClient.updateChannelState(
|
||||
ChannelState(
|
||||
messages: [messageResponse.message],
|
||||
channel: messageResponse.channel,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
showLocalNotification(
|
||||
notificationData.message,
|
||||
notificationData.channel,
|
||||
);
|
||||
// final messageId = notification['data']['id'];
|
||||
//
|
||||
// final notificationData = await NotificationService.getAndStoreMessage(
|
||||
// messageId: messageId,
|
||||
// storeMessageHandler: (messageResponse) {
|
||||
// return chatPersistentClient.updateChannelState(
|
||||
// ChannelState(
|
||||
// messages: [messageResponse.message],
|
||||
// channel: messageResponse.channel,
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
//
|
||||
// showLocalNotification(
|
||||
// notificationData.message,
|
||||
// notificationData.channel,
|
||||
// );
|
||||
}
|
||||
|
||||
void initNotifications(Client client) {
|
||||
|
||||
Reference in New Issue
Block a user