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/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';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
Future<void> _handleAndroidNotification(
|
void showLocalNotification(Message message, ChannelModel channel) async {
|
||||||
Map<String, dynamic> notification,
|
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||||
) async {
|
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 =
|
final notificationData =
|
||||||
await NotificationService.getAndStoreMessage(notification);
|
await NotificationService.getAndStoreMessage(messageId);
|
||||||
|
|
||||||
final androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
showLocalNotification(
|
||||||
'Message notifications',
|
notificationData.message,
|
||||||
'Message notifications',
|
notificationData.channel,
|
||||||
'Channel dedicated to message notifications',
|
|
||||||
importance: Importance.Max,
|
|
||||||
priority: Priority.High,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
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 {
|
void main() async {
|
||||||
final client = Client(
|
final client = Client(
|
||||||
's2dxdhpxd94g',
|
's2dxdhpxd94g',
|
||||||
logLevel: Level.INFO,
|
logLevel: Level.INFO,
|
||||||
androidNotificationHandler: _handleAndroidNotification,
|
showFakeNotification: Platform.isAndroid ? showLocalNotification : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
await client.setUser(
|
await client.setUser(
|
||||||
@@ -38,6 +60,21 @@ void main() async {
|
|||||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlcjEifQ.NGZPyPMx7KSVisJmh4tJhOIv7ZjCaMQpOh4gTINvCaU',
|
'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));
|
runApp(MyApp(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
stream_chat_flutter:
|
stream_chat_flutter:
|
||||||
path: ../
|
path: ../
|
||||||
|
flutter_apns: ^1.1.0
|
||||||
|
flutter_local_notifications: ^1.4.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class ChannelsBloc extends StatefulWidget {
|
|||||||
streamChatState = context.findAncestorStateOfType<ChannelsBlocState>();
|
streamChatState = context.findAncestorStateOfType<ChannelsBlocState>();
|
||||||
|
|
||||||
if (streamChatState == null) {
|
if (streamChatState == null) {
|
||||||
throw Exception('You must have a ChannelsProvider widget as anchestor');
|
throw Exception('You must have a ChannelsBloc widget as anchestor');
|
||||||
}
|
}
|
||||||
|
|
||||||
return streamChatState;
|
return streamChatState;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:file_picker/file_picker.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
|
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
|
||||||
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
import 'package:stream_chat/stream_chat.dart';
|
import 'package:stream_chat/stream_chat.dart';
|
||||||
|
|||||||
+36
-16
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -193,18 +192,41 @@ class StreamChatState extends State<StreamChat> with WidgetsBindingObserver {
|
|||||||
@override
|
@override
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
if (state == AppLifecycleState.paused) {
|
if (state == AppLifecycleState.paused) {
|
||||||
if (Platform.isAndroid) {
|
if (client.showFakeNotification != null) {
|
||||||
if (client.pushNotificationsEnabled) {
|
_newMessageSubscription = client
|
||||||
_newMessageSubscription =
|
.on(EventType.messageNew)
|
||||||
client.on(EventType.messageNew).listen((event) {
|
.where((e) => e.user.id != user.id)
|
||||||
client.androidNotificationHandler({
|
.listen((event) async {
|
||||||
'data': {
|
var channel = client.state.channels[event.cid];
|
||||||
'message_id': event.message.id,
|
|
||||||
},
|
if (channel == null) {
|
||||||
});
|
channel = client.channel(
|
||||||
});
|
event.type,
|
||||||
}
|
id: event.cid.split(':')[1],
|
||||||
_disconnectTimer = Timer(Duration(minutes: 1), () {
|
);
|
||||||
|
await channel.query();
|
||||||
|
}
|
||||||
|
|
||||||
|
client.showFakeNotification(
|
||||||
|
event.message,
|
||||||
|
ChannelModel(
|
||||||
|
id: channel.id,
|
||||||
|
createdAt: channel.createdAt,
|
||||||
|
extraData: channel.extraData,
|
||||||
|
type: channel.type,
|
||||||
|
members: channel.state.members,
|
||||||
|
memberCount: channel.memberCount,
|
||||||
|
frozen: channel.frozen,
|
||||||
|
cid: channel.cid,
|
||||||
|
deletedAt: channel.deletedAt,
|
||||||
|
config: channel.config,
|
||||||
|
createdBy: channel.createdBy,
|
||||||
|
updatedAt: channel.updatedAt,
|
||||||
|
lastMessageAt: channel.lastMessageAt,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
_disconnectTimer = Timer(client.backgroundKeepAlive, () {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -216,9 +238,7 @@ class StreamChatState extends State<StreamChat> with WidgetsBindingObserver {
|
|||||||
_disconnectTimer.cancel();
|
_disconnectTimer.cancel();
|
||||||
} else {
|
} else {
|
||||||
if (client.wsConnectionStatus.value == ConnectionStatus.disconnected) {
|
if (client.wsConnectionStatus.value == ConnectionStatus.disconnected) {
|
||||||
if (client.pushNotificationsEnabled) {
|
NotificationService.handleIosMessageQueue(client);
|
||||||
NotificationService.handleIosMessageQueue(client);
|
|
||||||
}
|
|
||||||
client.connect();
|
client.connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -10,7 +10,6 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
photo_view: ^0.9.2
|
photo_view: ^0.9.2
|
||||||
rxdart: ^0.23.1
|
|
||||||
jiffy: ^3.0.1
|
jiffy: ^3.0.1
|
||||||
cached_network_image: ^2.1.0+1
|
cached_network_image: ^2.1.0+1
|
||||||
flutter_markdown: ^0.3.4
|
flutter_markdown: ^0.3.4
|
||||||
@@ -20,7 +19,8 @@ dependencies:
|
|||||||
file_picker: ^1.6.2
|
file_picker: ^1.6.2
|
||||||
image_picker: ^0.6.5
|
image_picker: ^0.6.5
|
||||||
flutter_keyboard_visibility: ^0.8.0
|
flutter_keyboard_visibility: ^0.8.0
|
||||||
stream_chat: ^0.2.0-alpha
|
stream_chat:
|
||||||
|
path: ../stream_chat_dart
|
||||||
mime: ^0.9.6+3
|
mime: ^0.9.6+3
|
||||||
visibility_detector: ^0.1.4
|
visibility_detector: ^0.1.4
|
||||||
http_parser: ^3.1.4
|
http_parser: ^3.1.4
|
||||||
|
|||||||
Reference in New Issue
Block a user