import 'dart:typed_data'; import 'dart:ui'; import 'package:flutter/cupertino.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); class LocalNotification { static Future scheduleNotification( {@required DateTime scheduledNotificationDateTime, @required String title, @required String description}) async { ///vibrationPattern var vibrationPattern = Int64List(4); vibrationPattern[0] = 0; vibrationPattern[1] = 1000; vibrationPattern[2] = 5000; vibrationPattern[3] = 2000; var androidPlatformChannelSpecifics = AndroidNotificationDetails( 'active-prescriptions', 'ActivePrescriptions', 'ActivePrescriptionsDescription', // icon: 'secondary_icon', sound: RawResourceAndroidNotificationSound('slow_spring_board'), ///change it to be as ionic // largeIcon: DrawableResourceAndroidBitmap('sample_large_icon'),///change it to be as ionic vibrationPattern: vibrationPattern, enableLights: true, color: const Color.fromARGB(255, 255, 0, 0), ledColor: const Color.fromARGB(255, 255, 0, 0), ledOnMs: 1000, ledOffMs: 500); var iOSPlatformChannelSpecifics = IOSNotificationDetails(sound: 'slow_spring_board.aiff'); ///change it to be as ionic // var platformChannelSpecifics = NotificationDetails( // androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); // await flutterLocalNotificationsPlugin.schedule(0, title, description, // scheduledNotificationDateTime, platformChannelSpecifics); } ///Repeat notification every day at approximately 10:00:00 am static Future showDailyAtTime() async { var time = Time(10, 0, 0); var androidPlatformChannelSpecifics = AndroidNotificationDetails( 'repeatDailyAtTime channel id', 'repeatDailyAtTime channel name', 'repeatDailyAtTime description'); var iOSPlatformChannelSpecifics = IOSNotificationDetails(); // var platformChannelSpecifics = NotificationDetails( // androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); // await flutterLocalNotificationsPlugin.showDailyAtTime( // 0, // 'show daily title', // 'Daily notification shown at approximately ${_toTwoDigitString(time.hour)}:${_toTwoDigitString(time.minute)}:${_toTwoDigitString(time.second)}', // time, // platformChannelSpecifics); } ///Repeat notification weekly on Monday at approximately 10:00:00 am static Future showWeeklyAtDayAndTime() async { var time = Time(10, 0, 0); var androidPlatformChannelSpecifics = AndroidNotificationDetails( 'show weekly channel id', 'show weekly channel name', 'show weekly description'); var iOSPlatformChannelSpecifics = IOSNotificationDetails(); // var platformChannelSpecifics = NotificationDetails( // androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); // await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime( // 0, // 'show weekly title', // 'Weekly notification shown on Monday at approximately ${_toTwoDigitString(time.hour)}:${_toTwoDigitString(time.minute)}:${_toTwoDigitString(time.second)}', // Day.Monday, // time, // platformChannelSpecifics); } static String _toTwoDigitString(int value) { return value.toString().padLeft(2, '0'); } static Future cancelNotification() async { await flutterLocalNotificationsPlugin.cancel(0); } static Future cancelAllNotifications() async { await flutterLocalNotificationsPlugin.cancelAll(); } }