Created
December 20, 2020 17:36
-
-
Save chamithchathuka/a67d34805ff97d621e4fd56c5c2e3581 to your computer and use it in GitHub Desktop.
Flutter Scheduled Notification with a Custom Sound
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<void> _cancelNotification() async { | |
| await flutterLocalNotificationsPlugin.cancel(0); | |
| } | |
| /// Schedules a notification that specifies a different icon, sound and vibration pattern | |
| Future<void> _scheduleNotification() async { | |
| var scheduledNotificationDateTime = | |
| DateTime.now().add(Duration(seconds: 5)); | |
| var vibrationPattern = Int64List(4); | |
| vibrationPattern[0] = 0; | |
| vibrationPattern[1] = 1000; | |
| vibrationPattern[2] = 5000; | |
| vibrationPattern[3] = 2000; | |
| var androidPlatformChannelSpecifics = AndroidNotificationDetails( | |
| 'your channel id', | |
| 'your channel name', 'your channel description', | |
| importance: Importance.Max, | |
| priority: Priority.High, | |
| sound: RawResourceAndroidNotificationSound('slow_spring_board'), | |
| ticker: 'ticker', | |
| visibility: NotificationVisibility.Public); | |
| // var androidPlatformChannelSpecifics = AndroidNotificationDetails( | |
| // 'your other channel id', | |
| // 'your other channel name', | |
| // 'your other channel description', | |
| // icon: 'app_icon', | |
| // importance: Importance.Max, | |
| // priority: Priority.High, | |
| // ticker: 'ticker', | |
| // sound: RawResourceAndroidNotificationSound('slow_spring_board'), | |
| //// vibrationPattern: vibrationPattern, | |
| // enableLights: true, | |
| // visibility: NotificationVisibility.Public, | |
| //// 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'); | |
| var platformChannelSpecifics = NotificationDetails( | |
| androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); | |
| // await flutterLocalNotificationsPlugin.show( | |
| // 0, | |
| // 'public notification title', | |
| // 'public notification body', | |
| // platformChannelSpecifics, | |
| // payload: 'item x'); | |
| await flutterLocalNotificationsPlugin.schedule( | |
| 0, | |
| 'scheduled title', | |
| 'scheduled body', | |
| scheduledNotificationDateTime, | |
| platformChannelSpecifics); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment