-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flutter local Notification is added to the project
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
class NotificationServices { | ||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = | ||
FlutterLocalNotificationsPlugin(); // | ||
|
||
initializeNotification() async { | ||
//tz.initializeTimeZones(); | ||
final IOSInitializationSettings initializationSettingsIOS = | ||
IOSInitializationSettings( | ||
requestSoundPermission: false, | ||
requestBadgePermission: false, | ||
requestAlertPermission: false, | ||
onDidReceiveLocalNotification: onDidReceiveLocalNotification); | ||
|
||
final AndroidInitializationSettings androidInitializationSettingsIOS = | ||
AndroidInitializationSettings('appicon'); | ||
|
||
final InitializationSettings initializationSettings = | ||
InitializationSettings( | ||
iOS: initializationSettingsIOS, | ||
android: androidInitializationSettingsIOS, | ||
); | ||
await flutterLocalNotificationsPlugin.initialize(initializationSettings, | ||
onSelectNotification: selectNotification); | ||
} | ||
|
||
displayNotification({required String title, required String body}) async { | ||
print("doing test"); | ||
// ignore: prefer_const_constructors | ||
var androidPlatformChannelSpecifics = AndroidNotificationDetails( | ||
'your channel id', 'your channel name', | ||
importance: Importance.max, priority: Priority.high); | ||
var iOSPlatformChannelSpecifics = IOSNotificationDetails(); | ||
var platformChannelSpecifics = NotificationDetails( | ||
android: androidPlatformChannelSpecifics, | ||
iOS: iOSPlatformChannelSpecifics); | ||
await flutterLocalNotificationsPlugin.show( | ||
0, | ||
title, | ||
body, | ||
platformChannelSpecifics, | ||
payload: 'Default_Sound', | ||
); | ||
} | ||
|
||
void requestIOSPermissions() { | ||
flutterLocalNotificationsPlugin | ||
.resolvePlatformSpecificImplementation< | ||
IOSFlutterLocalNotificationsPlugin>() | ||
?.requestPermissions( | ||
alert: true, | ||
badge: true, | ||
sound: true, | ||
); | ||
} | ||
|
||
Future selectNotification(String? payload) async { | ||
if (payload != null) { | ||
print('notification payload: $payload'); | ||
} else { | ||
print("Notification Done"); | ||
} | ||
Get.to(() => Container()); | ||
} | ||
|
||
Future onDidReceiveLocalNotification( | ||
int? id, String? title, String? body, String? payload) async { | ||
// display a dialog with the notification details, tap ok to go to another page | ||
|
||
Get.dialog(Text("Welcome to the Flutter.")); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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