remove all notifications dependencies
This commit is contained in:
+58
-21
@@ -1,36 +1,58 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_apns/apns.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'
|
||||
hide Message;
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
Future<void> _handleAndroidNotification(
|
||||
Map<String, dynamic> notification,
|
||||
) async {
|
||||
void showLocalNotification(Message message, ChannelModel channel) async {
|
||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
final initializationSettingsAndroid =
|
||||
AndroidInitializationSettings('launch_background');
|
||||
final initializationSettingsIOS = IOSInitializationSettings();
|
||||
final initializationSettings = InitializationSettings(
|
||||
initializationSettingsAndroid,
|
||||
initializationSettingsIOS,
|
||||
);
|
||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
||||
flutterLocalNotificationsPlugin.show(
|
||||
message.id.hashCode,
|
||||
'${message.user.name} @ ${channel.name}',
|
||||
message.text,
|
||||
NotificationDetails(
|
||||
AndroidNotificationDetails(
|
||||
'message channel',
|
||||
'Message channel',
|
||||
'Channel used for showing messages',
|
||||
priority: Priority.High,
|
||||
importance: Importance.High,
|
||||
),
|
||||
IOSNotificationDetails(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future backgroundHandler(Map<String, dynamic> notification) async {
|
||||
final messageId = notification['data']['message_id'];
|
||||
|
||||
print('messageId: ${messageId}');
|
||||
|
||||
final notificationData =
|
||||
await NotificationService.getAndStoreMessage(notification);
|
||||
await NotificationService.getAndStoreMessage(messageId);
|
||||
|
||||
final androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
||||
'Message notifications',
|
||||
'Message notifications',
|
||||
'Channel dedicated to message notifications',
|
||||
importance: Importance.Max,
|
||||
priority: Priority.High,
|
||||
showLocalNotification(
|
||||
notificationData.message,
|
||||
notificationData.channel,
|
||||
);
|
||||
|
||||
final androidNotificationOptions = AndroidNotificationOptions(
|
||||
androidNotificationDetails: androidPlatformChannelSpecifics,
|
||||
id: notificationData.message.id.hashCode,
|
||||
title:
|
||||
'CUSTOM ${notificationData.message.user.name} @ ${notificationData.channel.cid}',
|
||||
body: notificationData.message.text,
|
||||
);
|
||||
|
||||
await NotificationService.showNotification(androidNotificationOptions);
|
||||
}
|
||||
|
||||
void main() async {
|
||||
final client = Client(
|
||||
's2dxdhpxd94g',
|
||||
logLevel: Level.INFO,
|
||||
androidNotificationHandler: _handleAndroidNotification,
|
||||
showFakeNotification: Platform.isAndroid ? showLocalNotification : null,
|
||||
);
|
||||
|
||||
await client.setUser(
|
||||
@@ -38,6 +60,21 @@ void main() async {
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlcjEifQ.NGZPyPMx7KSVisJmh4tJhOIv7ZjCaMQpOh4gTINvCaU',
|
||||
);
|
||||
|
||||
final connector = createPushConnector();
|
||||
connector.configure(
|
||||
onBackgroundMessage: backgroundHandler,
|
||||
);
|
||||
|
||||
connector.requestNotificationPermissions();
|
||||
connector.token.addListener(() {
|
||||
if (connector.token.value != null) {
|
||||
client.addDevice(
|
||||
connector.token.value,
|
||||
Platform.isAndroid ? 'firebase' : 'apn',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
runApp(MyApp(client));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ dependencies:
|
||||
sdk: flutter
|
||||
stream_chat_flutter:
|
||||
path: ../
|
||||
flutter_apns: ^1.1.0
|
||||
flutter_local_notifications: ^1.4.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user