Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7188

Flutter Release apk crashes on using notifications, though it works on emulator

$
0
0

I am trying to build an app which sends me notification after some time, for which i am using flutter_local_notifications plugin. The problem is notifications work perfectly on virtual emulators and physical mobile emulators, but when I install a release-apk on my phone, it crashes as soon as I press the 'Remind me later button'

Would really appreciate help, I have been stuck on this thing for for a few days now

Here is my notifications plugin code (the i variable was workaround to send multiple notifications without cancelling the previous ones)

import 'package:flutter_local_notifications/flutter_local_notifications.dart';var i = -999999;class Notifications {  FlutterLocalNotificationsPlugin localNotificationsPlugin =      FlutterLocalNotificationsPlugin();  initializeNotifications() async {    var initializeAndroid = AndroidInitializationSettings('ic_launcher');    var initializeIOS = IOSInitializationSettings(      requestAlertPermission: true,      requestBadgePermission: true,      requestSoundPermission: true,    );    var initSettings = InitializationSettings(initializeAndroid, initializeIOS);    await localNotificationsPlugin.initialize(initSettings);  }  Future singleNotification(DateTime datetime, String message, String subtext,      {String sound}) async {    var androidChannel = AndroidNotificationDetails('channel-id','channel-name','channel-description',      playSound: true,      importance: Importance.Max,      priority: Priority.Max,    );    if (i == 999999) {      i = -999999;    }    var iosChannel = IOSNotificationDetails();    var platformChannel = NotificationDetails(androidChannel, iosChannel);    await localNotificationsPlugin.schedule(        i++, message, subtext, datetime, platformChannel);  }}

Here is where I am calling the notifications

onTap: () async {                                    try{Navigator.pop(                                        context, "notification button");                                    Duration resultingDuration =                                        await showDurationPicker(                                            context: context,                                            initialTime: Duration(                                                hours: 0, minutes: 10));                                    // print(resultingDuration.inHours);                                    // print(resultingDuration.inMinutes);                                    if(resultingDuration!=null){DateTime now = DateTime.now().toUtc().add(                                          Duration(                                              hours: resultingDuration.inHours,                                              minutes:                                                  resultingDuration.inMinutes),                                        );                                    await notification.singleNotification(                                      now,"Reminder","Revise your deck '${deck.deckName}'",                                    );}}catch(e){                                      print(e);                                    }                                  },

Viewing all articles
Browse latest Browse all 7188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>