'My flutter crashed in release version only

when i am scheduleing a notification app crashed in release version only not in debug it a flutter project

Here I called it

notificationHelper.cancelNotification(1);
                    notificationHelper.cancelNotification(2);
                    int second = DateTime.now().difference(DateTime(now.year, now.month, now.day, time.hour, time.minute)).inSeconds.abs();
                    notificationHelper.scheduleNotification(
                      title: WORKOUT[LANGUAGE_TYPE],
                      body: YOUR_WORKOUT_TIME_IS_UP[LANGUAGE_TYPE],
                      payload: "payload",
                      id: 10.toString(),
                      context2: context,
                      seconds: second,
                    ); 

Notification.dart

scheduleNotification({String title, String body, String payload, String id, BuildContext context2, int seconds}) async{
    context = context2;
    await flutterLocalNotificationsPlugin.zonedSchedule(
        1,
        title,
        body,
        TZDateTime.now(local).add(Duration(seconds: seconds)),
         NotificationDetails(
            android: AndroidNotificationDetails(id,
                title, body),),
                // 'Exercise App', 'Exercise App'),),

        androidAllowWhileIdle: true,
        uiLocalNotificationDateInterpretation:
        UILocalNotificationDateInterpretation.absoluteTime);

    periodicNotification(
      title: title,
      context2: context,
      id: id,
      payload: payload,
      body: body
    );

    // AndroidNotificationDetails androidPlatformChannelSpecifics =
    // new AndroidNotificationDetails(
    //   id, body, payload,
    //   importance: Importance.max,
    //   priority: Priority.high,
    //   showWhen: true,
    // );
    // NotificationDetails platformChannelSpecifics =
    // NotificationDetails(android: androidPlatformChannelSpecifics);
    // await flutterLocalNotificationsPlugin.show(
    //     0, title, body, platformChannelSpecifics,
    //     payload: payload);

  }

  periodicNotification({String title, String body, String payload, String id, BuildContext context2}) async{
    context = context2;
     AndroidNotificationDetails androidPlatformChannelSpecifics =
    AndroidNotificationDetails(id,title,body);
      // 'Scheduled Notification',
      //   "Scheduled", "Scheduled");
     NotificationDetails platformChannelSpecifics =
    NotificationDetails(android: androidPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.periodicallyShow(
        2,
        title,
        body,
        RepeatInterval.daily,
        platformChannelSpecifics,
        androidAllowWhileIdle: true
    );
  }

  cancelNotification(int id){
    flutterLocalNotificationsPlugin.cancel(id);
  }

....................................................................................................................................................................................................................................................................................



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source