Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error flutter NotificationDetails too many positional arguments

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:

enter image description here

I am guiding myself with this tutorial. This code is displayed at minute 2:05 YouTube Video

like image 835
Carlos Peñaranda Avatar asked Oct 18 '25 11:10

Carlos Peñaranda


1 Answers

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.

like image 183
Yeasin Sheikh Avatar answered Oct 20 '25 03:10

Yeasin Sheikh