import ‘dart:typed_data’;
import ‘package deal:flutter/materials.dart’;
import ‘dart:io’;
import ‘package deal:firebase_messaging/firebase_messaging.dart’;
import ‘package deal:flutter_local_notifications/flutter_local_notifications.dart’;
import ‘package deal:fluttertoast/fluttertoast.dart’;
import ‘package deal:pump_pipe/amc_quotation.dart’;
import ‘package deal:pump_pipe/draw_screen.dart’;
import ‘package deal:pump_pipe/home_screen.dart’;
import ‘package deal:pump_pipe/repair_detail.dart’;
import ‘package deal:pump_pipe/wallet_screen.dart’;
import ‘package deal:pump_pipe/your_quotation.dart’;
import ‘package deal:shared_preferences/shared_preferences.dart’;
import ‘../fundamental.dart’;
import ‘../your_orders.dart’;
Future<void> handlebackgroundMessage(RemoteMessage message) async {
remaining notification = message.notification;
print(‘Title1: ${message.notification?.title}’);
print(‘physique: ${message.notification?.physique}’);
print(‘payload: ${message.information}’);
_showLocalNotification(notification!);
_navigateToScreen(notificationType);
}
remaining _locaNotifications = FlutterLocalNotificationsPlugin();
Future<void> handleForegroundMessage(RemoteMessage message) async {
remaining notification = message.notification;
print(‘Title: ${message.notification?.title}’);
print(‘physique: ${message.notification?.physique}’);
print(‘payload: ${message.information}’);
_showLocalNotification(notification!);
String notificationType = message.notification?.android?.clickAction ?? ”;
_navigateToScreen(notificationType);
}
String notificationType = “”;
void handleMessage(RemoteMessage? message) {
if (message == null) return;
remaining notification = message.notification;
remaining information = message.information;
if (notification != null) {
}
}
Future initPushNotification() async {
await FirebaseMessaging.occasion.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
FirebaseMessaging.onBackgroundMessage(handlebackgroundMessage);
FirebaseMessaging.onBackgroundMessage((message) async {
print(“Dealing with background message: $message”);
handlebackgroundMessage(message);
String notificationType = message.notification?.android?.clickAction ??
”;
_navigateToScreen(notificationType);
});
FirebaseMessaging.occasion.getInitialMessage().then(handleMessage);
FirebaseMessaging.onMessageOpenedApp.pay attention((RemoteMessage message) {
handleMessage(message);
String notificationType = message.notification?.android?.clickAction ??
”;
_navigateToScreen(notificationType);
});
FirebaseMessaging.onMessage.pay attention((RemoteMessage message) {
remaining notification = message.notification;
if (notification == null) return;
_showLocalNotification(notification);
print(‘Title: ${notification.title}’);
print(‘physique: ${notification.physique}’);
print(‘payload: ${message.information}’);
});
}
void _showLocalNotification(RemoteNotification notification) async {
await _locaNotifications.present(
0,
notification.title ?? ”,
notification.physique ?? ”,
NotificationDetails(
android: AndroidNotificationDetails(
‘high_importance_channel’,
‘Excessive Significance Notifications’,
significance: Significance.max,
precedence: Precedence.excessive,
additionalFlags: Int32List.fromList(<int>[4]),
),
),
payload: notification.android?.clickAction ?? ”,
);
notificationType = notification.android?.clickAction ??
”;
}
class FirebaseApi {
remaining _firebaseMessaging = FirebaseMessaging.occasion;
remaining _androidchannel = const AndroidNotificationChannel(
‘high_importance_channel’,
‘Excessive Significance Notifications’,
description: ‘This Channel is used for essential notification’,
significance: Significance.defaultImportance,
);
remaining _locaNotifications = FlutterLocalNotificationsPlugin();
Future<void> initNotification() async {
await _firebaseMessaging.requestPermission();
SharedPreferences _pref = await SharedPreferences.getInstance();
if (Platform.isAndroid) {
remaining fCMToken = await _firebaseMessaging.getToken();
print(“fcm”);
_pref.setString(‘fcm’, fCMToken!);
else if (Platform.isIOS) {
NotificationSettings settings =
await _firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.licensed) {
print(‘Consumer granted permission’);
await _firebaseMessaging.getAPNSToken().then((worth) async {
var iosToken = worth ?? ”;
Fluttertoast.showToast(msg: “token $iosToken”);
_pref.setString(‘fcm’, iosToken);
print(‘Token 11212 : $iosToken’);
});
else if (settings.authorizationStatus ==
AuthorizationStatus.provisional) {
print(‘Consumer granted provisional permission’);
else {
print(‘Consumer declined or has not accepted permission’);
}
}
await _locaNotifications.initialize(
InitializationSettings(
android: AndroidInitializationSettings(
‘@mipmap/ic_launcher’),
iOS: DarwinInitializationSettings(
requestSoundPermission: true,
requestAlertPermission: true,
)),
onDidReceiveNotificationResponse: (message) async {
print(‘Consumer tapped on the notification’);
_navigateToScreen(notificationType);
},
);`
await _locaNotifications
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(_androidchannel);
initPushNotification();
}
}
}
i get APNS Token however All the time fetch Null , methods to get APNS token , add data.plist in my challenge and all firebase arrange performed