|
|
|
@ -7,7 +7,7 @@ import 'package:google_api_availability/google_api_availability.dart';
|
|
|
|
// import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
|
|
|
|
// import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
|
|
|
|
import 'package:huawei_push/huawei_push.dart' as h_push;
|
|
|
|
import 'package:huawei_push/huawei_push.dart' as h_push;
|
|
|
|
import 'package:test_sa/controllers/notification/notification_manger.dart';
|
|
|
|
import 'package:test_sa/controllers/notification/notification_manger.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
|
|
import 'package:test_sa/models/all_requests_and_count_model.dart';
|
|
|
|
import 'package:test_sa/models/all_requests_and_count_model.dart';
|
|
|
|
import 'package:test_sa/models/device/asset_transfer.dart';
|
|
|
|
import 'package:test_sa/models/device/asset_transfer.dart';
|
|
|
|
import 'package:test_sa/models/new_models/gas_refill_model.dart';
|
|
|
|
import 'package:test_sa/models/new_models/gas_refill_model.dart';
|
|
|
|
@ -40,18 +40,11 @@ class FirebaseNotificationManger {
|
|
|
|
if (!(await isGoogleServicesAvailable())) {
|
|
|
|
if (!(await isGoogleServicesAvailable())) {
|
|
|
|
h_push.Push.enableLogger();
|
|
|
|
h_push.Push.enableLogger();
|
|
|
|
final result = await h_push.Push.setAutoInitEnabled(true);
|
|
|
|
final result = await h_push.Push.setAutoInitEnabled(true);
|
|
|
|
|
|
|
|
h_push.Push.onMessageReceivedStream.listen(_onMessageReceived, onError: _onMessageReceiveError);
|
|
|
|
h_push.Push.onNotificationOpenedApp.listen((message) {
|
|
|
|
|
|
|
|
// newMessage(toFirebaseRemoteMessage(message));
|
|
|
|
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h_push.Push.onMessageReceivedStream.listen((message) {
|
|
|
|
|
|
|
|
// newMessage(toFirebaseRemoteMessage(message));
|
|
|
|
|
|
|
|
}, onError: (e) => print(e.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h_push.Push.getTokenStream.listen((hToken) {
|
|
|
|
h_push.Push.getTokenStream.listen((hToken) {
|
|
|
|
// onToken(token);
|
|
|
|
// onToken(token);
|
|
|
|
print("Huawei Token: ${token}");
|
|
|
|
// print("Huawei Token: ${hToken}");
|
|
|
|
token = hToken;
|
|
|
|
token = hToken;
|
|
|
|
}, onError: (e) {
|
|
|
|
}, onError: (e) {
|
|
|
|
print(e.toString());
|
|
|
|
print(e.toString());
|
|
|
|
@ -75,7 +68,15 @@ class FirebaseNotificationManger {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print("pushToken:$token");
|
|
|
|
print("pushToken:$token");
|
|
|
|
// return token;
|
|
|
|
// return token;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void _onMessageReceived(h_push.RemoteMessage remoteMessage) {
|
|
|
|
|
|
|
|
print("onMessageReceivedStream:${remoteMessage.toMap()}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void _onMessageReceiveError(Object error) {
|
|
|
|
|
|
|
|
print("onMessageReceivedStream:${error?.toString()}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Future<bool> isGoogleServicesAvailable() async {
|
|
|
|
static Future<bool> isGoogleServicesAvailable() async {
|
|
|
|
@ -119,7 +120,27 @@ class FirebaseNotificationManger {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static initialized(BuildContext context) async {
|
|
|
|
static initialized(BuildContext context) async {
|
|
|
|
//await Firebase.initializeApp();
|
|
|
|
if (!(await isGoogleServicesAvailable())) {
|
|
|
|
|
|
|
|
var initialNotification = await h_push.Push.getInitialNotification();
|
|
|
|
|
|
|
|
if (initialNotification != null) {
|
|
|
|
|
|
|
|
Map<String, dynamic> remoteData = Map<String, dynamic>.from(initialNotification["extras"] as Map);
|
|
|
|
|
|
|
|
handleMessage(context, remoteData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h_push.Push.onNotificationOpenedApp.listen((message) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (message is Map<String, dynamic>) {
|
|
|
|
|
|
|
|
Map<String, dynamic> remoteData = message;
|
|
|
|
|
|
|
|
remoteData = remoteData["extras"];
|
|
|
|
|
|
|
|
handleMessage(context, remoteData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
|
|
|
print("parsingError:$ex");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, onError: (e) => print("onNotificationOpenedApp Error${e.toString()}"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NotificationSettings settings;
|
|
|
|
NotificationSettings settings;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|