I got this class which is a service inside my flutter project, here some excerpt of code:
_initialize() async {
print('notification _initialize');
const android = AndroidInitializationSettings('@mipmap/ic_launcher');
await plugin.initialize(
const InitializationSettings(
android: android,
),
onSelectNotification: _onSelectNotification,
);
}
_onSelectNotification(String? payload) {
print('_onSelectNotification');
if (payload != null && payload.isNotEmpty) {
var array = payload.split('/');
if (array.length == 2) {
var acao = int.tryParse(array[0]);
var idDispositivo = array[1].toString();
if (acao != null && idDispositivo.isNotEmpty) {
int disIndex = serverConnection.equipamentos
.indexWhere((x) => x.serverId == idDispositivo);
if (disIndex != -1) {
DispositivoModel dis = serverConnection.equipamentos[disIndex];
if (dis.sep != null) {
sepService.showDialogAlertaAcionado(dis);
} else if (disp.port != null) {
gateService.showGateStatus(
Routes.navigatorKey!.currentContext!, dis);
}
}
}
}
Navigator.of(Routes.navigatorKey!.currentContext!)
.pushReplacementNamed(payload);
}
}
showNotification(RemoteMessage message) async {
print('showNotification');
var user = await accountService.getUser();
print('isLoggedIn ${accountService.isLoggedIn}');
print('isLoggedIn ${user}');
if (accountService.isLoggedIn == true && user != null) {
Future<RingerModeStatus> soundModeAparelho =
_verificaModoDeSomAtualDispositivo();
print('Retorno do verificaSom $soundModeAparelho');
if (soundModeAparelho == RingerModeStatus.silent) {
Future.delayed(const Duration(seconds: 9), () async {
_conteudoNotificacao(message);
});
} else {
_conteudoNotificacao(message);
}
}
}
_conteudoNotificacao(RemoteMessage message) {
RemoteMessageData data = RemoteMessageData.fromJson(message.data);
sound = data.sound != 'default' && data.sound != null
? data.sound ?? 'gate'
: 'gate';
//sound = "assets/$sound.mp3";
print('sound $sound');
AndroidNotificationChannel channel = AndroidNotificationChannel(
'Connector $sound',
'ConnectorChannel',
description: '',
importance: Importance.high,
sound: RawResourceAndroidNotificationSound(sound),
//sound: UriAndroidNotificationSound("assets/$sound"),
enableVibration: true,
enableLights: true,
);
plugin = FlutterLocalNotificationsPlugin();
String title = 'Connector';
if (data.route != null) {
var array = data.route!.split('/');
if (array.length == 2) {
var acao = int.tryParse(array[0]);
var idDispositivo = array[1].toString();
if (acao != null && idDispositivo.isNotEmpty) {
int disIndex = serverConnection.equipamentos
.indexWhere((x) => x.serverId == idDispositivo);
if (disIndex != -1) {
DispositivoModel dis = serverConnection.equipamentos[disIndex];
if (dis.sep != null) {
title = 'SEP';
} else if (dis.port != null) {
title = 'Portão';
}
}
}
}
}
plugin.show(
message.hashCode,
title,
data.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: channel.description,
importance: channel.importance,
priority: Priority.high,
showProgress: true,
enableLights: true,
enableVibration: true,
visibility: NotificationVisibility.public,
sound: RawResourceAndroidNotificationSound(sound),
//sound: UriAndroidNotificationSound("assets/$sound"),
),
iOS: IOSNotificationDetails(
presentSound: true,
presentBadge: true,
presentAlert: true,
//sound: '$sound.mp3',
sound: 'assets/$sound.mp3',
),
),
payload: data.route,
);
}
I cannot build my project with Xcode because it always throws this kind of error:
"name of parameter 'onSelectNotification' isn't defined in the class"
I already replaced with onDidReceiveNotificationResponse
and i updated my flutter from 3.0.5
to 3.3.9
but nothing works, why is this happening? Someone can help me out?
Some informations for you all:
Current flutter: 3.3.9
Xcode: 13.4.1
macOS: Monterey
Pofile's OS version: ios 12
I update my flutter version and i searched outside of internet and no one solved. I'm gonna post more data, flutter doctor, version of dart and so on later.Since now, my pleasure.
I solved this issue by downgrading the flutter_local_notifications plugin inside my pubspec.yaml. Before i was using version 12:
#flutter_local_notifications: ^12.0.4
flutter_local_notifications: ^9.9.1
If anyone face this problem in the future, try it this way, it worked for me.