im in a serious trouble im writing a custom code for scheduling the local push notification cuz i can'not do it in flutterflow directly
so the matter is that i have writtem some of codes 2 to 3 codes lil bit similar to each other they donnt have any syntext or logical errors
1 code was for showing notifications instantly
here is the code (it works totally perfectally fine ) :
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:rxdart/subjects.dart';
// Import the notification plugin
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
Future<void> titleonly(String title) async {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = DarwinInitializationSettings();
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'Notification_channel_id', 'channel_name',
channelDescription: '_description',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker');
var iOSPlatformChannelSpecifics = DarwinNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics,
iOS: iOSPlatformChannelSpecifics);
// Use the provided title parameter instead of static string
await flutterLocalNotificationsPlugin.show(0, title,
'Task succesfully added, keep it up Pal', platformChannelSpecifics,
payload: 'test');
}
but the 2 other codes that i wrote the schedule the notifications ( the problem) when i rum them into my phone it didnt show notifications at all
here is that code (can anyon help me fixing that i tried almost all other solutions but all in vain i think if anyone of u able to help meh):
// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
// Import necessary packages
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
Future<void> scheduleNotification(
String title, String body, DateTime scheduledDate) async {
// Initialize the notification plugin
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
// Initialize Android settings
var initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
// Initialize iOS settings
var initializationSettingsIOS = DarwinInitializationSettings();
// Initialize settings for both platforms
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
// Initialize the plugin with the settings
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
// Initialize time zone data
tz.initializeTimeZones();
// Configure the Android notification details
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'To_Do_channel_', 'Scheduled_Notification',
channelDescription:
'This channel only shows the notifications related to Scheduld notification_',
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker');
// Configure the iOS notification details
var iOSPlatformChannelSpecifics = DarwinNotificationDetails();
// Combine the platform-specific settings
var platformChannelSpecifics = NotificationDetails(
android: androidPlatformChannelSpecifics,
iOS: iOSPlatformChannelSpecifics);
// Schedule the notification
await flutterLocalNotificationsPlugin.zonedSchedule(0, title, body,
tz.TZDateTime.from(scheduledDate, tz.local), platformChannelSpecifics,
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents:
DateTimeComponents.time // Adjust as necessary for your use case
);
}