DEV Community

medre
medre

Posted on

Requesting help on Fixing notification.

I have developed a dart/flutter app, its function is as a medication reminder app connected with supabase. I have trouble in setting reminder notification on the device installed on phone sdk.

Top comments (9)

Collapse
 
gagandeep_jnaik_a4a9c4b5 profile image
Gagandeep J Naik

Hi I would like to contribute, please use the below snippet.

// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('app_icon');
final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
final LinuxInitializationSettings initializationSettingsLinux =
LinuxInitializationSettings(
defaultActionName: 'Open notification');
final InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsDarwin,
linux: initializationSettingsLinux);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse);

...

void onDidReceiveLocalNotification(
int id, String? title, String? body, String? payload) async {
// display a dialog with the notification details, tap ok to go to another page
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
title: Text(title??''),
content: Text(body??''),
actions: [
CupertinoDialogAction(
isDefaultAction: true,
child: Text('Ok'),
onPressed: () async {
Navigator.of(context, rootNavigator: true).pop();
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondScreen(payload),
),
);
},
)
],
),
);
}

Collapse
 
medre profile image
medre

Image description

Collapse
 
medre profile image
medre

This is the error on your code, exception dosent compile.

Thread Thread
 
gagandeep_jnaik_a4a9c4b5 profile image
Gagandeep J Naik • Edited

Is this via emulator or physical device.

If this is on apk, chances are it would not be able to render due to lack of permission

Thread Thread
 
medre profile image
medre

Hi Gagandeep, the notification work when running the code. But when exported as .apk it does not function. All the permission to read data and allow notification access is given but it is not working.

Just for reference, the app is connected to supabase for Backend along with modular ui. Functions include:

  1. Inventory
  2. Translation
  3. Few DB Functions needed for a medication reminder app

If there is a way to override the action on the call function from db by triggering any SQL entity?

or

Any other ways on local state variable on the app level widget?
Thanks in advance.

Thread Thread
 
gagandeep_jnaik_a4a9c4b5 profile image
Gagandeep J Naik

ok 2 thing,

  1. If using Backend database, the notification won't work as the apk is not installed through verified means. Hence the OS rejects and. blocks the API request.

  2. If using as apk, I would suggest you remove all features which you have mentioned and use the app state to save the reminder, which is something that ii would not recommend as it becomes a useless app.


But since it is a reminder app, you can use 3rd part reminder services such as sending mail, messages.

Ex. OneSignal.

If you want, their website has a free promo code which you can use. But it have limited usability.

Also, try scrolling through other communities for some solution.

Thread Thread
 
admin_ryver_32ab9be7f5f79 profile image
admin ryver

Just trying to help, But I also do have promo codes for onSignal, DM for information

Collapse
 
admin_ryver_32ab9be7f5f79 profile image
admin ryver

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>().requestNotificationsPermission();

Add single use within function. It should work in emulator

Collapse
 
medre profile image
medre

Hi ryver, the suggested code snippet after defining class function it still does not show the reminder. The installed dependencies have been installed but yet the same continues.

On the other hand the language translation does not seem to work.

Any suggestion?