В настоящее время когда я нажимаю на уведомление, оно открывает приложение (что для меня нормально), но я хочу вызвать метод сервера API, когда пользователь нажимает кнопку действия. Я пробовал много методов, но мне так и не удалось заставить их работать. На самом деле, когда я нажимаю на кнопку, ничего не происходит. Может ли кто-нибудь помочь мне активировать событие кнопки действия при нажатии?
Заранее спасибо.
Код: Выделить всё
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
var firebaseMessaging = FirebaseMessaging.instance;
// Listening to the background messages
Future _firebaseMessagingBackgroundHandler(RemoteMessage? message) async {
showNotification(message);
}
// Show local notification
Future showNotification(RemoteMessage? message) async {
var androidPlatformChannelSpecifics = const AndroidNotificationDetails(
'channel_id', 'channel_name',
importance: Importance.max,
priority: Priority.high,
icon: "ic_launcher",
actions: [
AndroidNotificationAction('action_1', 'API Call'),
]
);
// var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics);
if(message?.notification == null){
if(message?.data != null){
await flutterLocalNotificationsPlugin.show(
0, message?.data["title"], message?.data["content"], platformChannelSpecifics,
payload: 'item x');
}
}
}
void main() async{
WidgetsFlutterBinding.ensureInitialized();
// Initialize Firebase
await Firebase.initializeApp(options: FirebaseConfig.defaultFirebaseOptions);
await firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
// Listening to the background messages
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// Listening to the foreground messages
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
showNotification(message);
});
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => myprovider1()),
ChangeNotifierProvider(create: (context) => myprovider2()),
ChangeNotifierProvider(create: (context) => myprovider3())
],
child: MyApp(),
),
);
}

Подробнее здесь: https://stackoverflow.com/questions/779 ... ion-button