Issue
I'm using NotificationDetails to show local notifications in my app:
class NotificationApi {
static final _notifications = FlutterLocalNotificationsPlugin();
static final onNotifications = BehaviorSubject<String?>();
static Future _notificationDetails() async {
return NotificationDetails(
android: AndroidNotificationDetails(
'channel id',
'channel name',
'channel description', //here shows the error
importance: Importance.max,
),
iOS: IOSNotificationDetails(),
);
}
static Future init({bool initScheduled = false}) async {
final android = AndroidInitializationSettings('@mipmap/ic_launcher');
final iOS = IOSInitializationSettings();
final settings = InitializationSettings(android: android, iOS: iOS);
await _notifications.initialize(
settings,
OnSelectNotification: (payload) async {
onNotifications.add(payload);
},
);
}
static Future showNotification({
int id = 0,
String? title,
String? body,
String? payload,
}) async =>
_notifications.show(
id,
title,
body,
await _notificationDetails(),
payload: payload,
);
}
At the moment to implement the third argument in AndroidNotificationDetails(), it is marked as error:
Too many positional arguments: 2 expected, but 3 found.
Try removing the extra positional arguments, or specifying the name for named
arguments.dartextra_positional_arguments_could_be_named
And it shows when i clicked on the () of the method:
I am guiding myself with this tutorial. This code is displayed at minute 2:05 YouTube Video
Solution
Channel description is a named parameter, you need to type channelDescription:"Your description"
android: AndroidNotificationDetails(
'channel id',
'channel name',
channelDescription:"Your description",
importance: Importance.max,
),
More about constructors.
Answered By - Yeasin Sheikh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.