0

I use flutter_local_notifications package to set notifications. I have a list of notification.In my case, my app shows only the last notification every 5 seconds , but I want to show the last 10 notifications. How can I do this ?

this my code :

Future<void> repeatNotification() async {
    var androidChannelSpecifics = AndroidNotificationDetails(
      'CHANNEL_ID 3',
      'CHANNEL_NAME 3',
      "CHANNEL_DESCRIPTION 3",
      playSound: true,
      importance: Importance.max,
      priority: Priority.high,
      sound: RawResourceAndroidNotificationSound('notification'),
      styleInformation: DefaultStyleInformation(true, true),
    );
    var iosChannelSpecifics = IOSNotificationDetails();
    var platformChannelSpecifics = NotificationDetails(
        android: androidChannelSpecifics, iOS: iosChannelSpecifics);
    SharedPreferences localStorage = await SharedPreferences.getInstance();
    String token = localStorage.getString('access_token');
    Map<String, String> headers = {
      'Content-type': 'application/json',
      'Accept': 'application/json',
      'Authorization': 'Bearer $token'
    };
    var response =
        await http.get(Uri.parse(ApiUtil.GET_ALERT), headers: headers);
    var data = json.decode(response.body);
    var dataa = (data['data']['data']['data'][0]);
    if (data['status'] == 200) {
      flutterLocalNotificationsPlugin.show(
          0,
          dataa['boxName'],
          dataa['alert_description'],    
          platformChannelSpecifics);
    } else {
      print("no message");
    }
   
  }

and this the response from the server :

{
    "code": 0,
    "message": " success",
    "data": {
        "data": {
            "current_page": 1,
            "data": [
                {
                    "id": 69,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265310,
                    "boxName": "box Malta",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne high",
                    "alert_level": "info"
                },
                {
                    "id": 68,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265310,
                    "boxName": "box Malta",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne Pression",
                    "alert_level": "warning"
                },
                {
                    "id": 67,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265309,
                    "boxName": "box masr",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne Pression",
                    "alert_level": "warning"
                },
                {
                    "id": 66,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265308,
                    "boxName": "box libya",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne Pression",
                    "alert_level": "warning"
                },
                {
                    "id": 62,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265245,
                    "boxName": "Box Sfax",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne Pression",
                    "alert_level": "warning"
                },
                {
                    "id": 61,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265243,
                    "boxName": "Box Tunis",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne Pression Roux",
                    "alert_level": "info"
                },
                {
                    "id": 58,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265244,
                    "boxName": "Box Office",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne Pression Roux",
                    "alert_level": "warning"
                },
                {
                    "id": 57,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265244,
                    "boxName": "Box Office",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne batterie",
                    "alert_level": "danger"
                },
                {
                    "id": 56,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265300,
                    "boxName": "box Maroc",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:40",
                    "alert_description": "Panne batterie",
                    "alert_level": "danger"
                },
                {
                    "id": 54,
                    "user_id": 53,
                    "boxIdentifiant": 1924589682265246,
                    "boxName": "boxt mannouba",
                    "alert_date": "2021-05-30",
                    "alert_time": "09:45",
                    "alert_description": "Panne roue",
                    "alert_level": "info"
                }
            ],

Thanks for your help

1 Answer 1

1

In this line you are taking the data to display as notification

var dataa = (data['data']['data']['data'][0])

And you are taking only the first element by specifing index 0

Then you show the notification

To show all the notification you have to cycle throw your data array at any index then show the notification.. something like this

For(int i = 0; i < data['data']['data']['data'].lemgth; i++) { var data = data['data']['data']['data'][i];

//Display notification with data }

Sign up to request clarification or add additional context in comments.

2 Comments

Slow Looper main: Activity com.example.tracar/.MainActivity is 774ms late (wall=35ms running=14ms ClientTransaction{ lifecycleRequest=android.app.servertransaction.StopActivityItem }) because of 9 msg ... @Patrick Gharapetians Gheshlagh
var bataa = (data['data']['data']['data']); notifs = bataa; print(id); print(notifs.length); for (var i = 0; i < notifs.length; i++) { if (data['status'] == 200) { flutterLocalNotificationsPlugin.show( 0, bataa['boxName'], bataa['alert_description'], // RepeatInterval.everyMinute, platformChannelSpecifics); // } } else { print("no message"); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.