-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b3048e
commit 6f4b600
Showing
10 changed files
with
206 additions
and
107 deletions.
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
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
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,84 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; | ||
import 'package:timezone/timezone.dart'; | ||
|
||
class NotificationController { | ||
final FlutterLocalNotificationsPlugin _instance; | ||
|
||
NotificationController() : _instance = FlutterLocalNotificationsPlugin(); | ||
|
||
Future<void> initialize() async { | ||
const InitializationSettings initializationSettings = | ||
InitializationSettings( | ||
android: AndroidInitializationSettings('app_icon')); | ||
await _instance.initialize(initializationSettings); | ||
} | ||
|
||
Future<bool> canNotifiy() async { | ||
return await _instance | ||
.resolvePlatformSpecificImplementation< | ||
AndroidFlutterLocalNotificationsPlugin>() | ||
?.areNotificationsEnabled() ?? | ||
true; | ||
} | ||
|
||
Future<bool> requestPermission() async { | ||
return await _instance | ||
.resolvePlatformSpecificImplementation< | ||
AndroidFlutterLocalNotificationsPlugin>() | ||
?.requestPermission() ?? | ||
true; | ||
} | ||
|
||
Future<void> notifyNewGrade(List<String> notificationBody) async { | ||
return _instance.show( | ||
10000, | ||
'Nouvelle(s) note(s) disponibles !', | ||
notificationBody.join(' \n- '), | ||
const NotificationDetails( | ||
android: AndroidNotificationDetails( | ||
'grade_channel', | ||
'Grade', | ||
channelDescription: 'Notification channel for Grades', | ||
enableLights: true, | ||
ledColor: Colors.white, | ||
color: Colors.red, | ||
importance: Importance.high, | ||
)), | ||
); | ||
} | ||
|
||
Future<void> cancelSchedule(int id) async { | ||
return _instance.cancel(id); | ||
} | ||
|
||
Future<void> cancelAllSchedule() async { | ||
return _instance.cancelAll(); | ||
} | ||
|
||
Future<void> cancelAllScheduleFromChannel(String channelId) async { | ||
final activeNotifs = await _instance.getActiveNotifications(); | ||
await Future.wait(activeNotifs | ||
.where((notif) => notif.channelId == channelId) | ||
.map((notif) => _instance.cancel(notif.id))); | ||
} | ||
|
||
Future<void> schedule( | ||
int id, | ||
String? title, | ||
String? body, | ||
TZDateTime scheduledDate, | ||
NotificationDetails notificationDetails, | ||
) async { | ||
_instance.zonedSchedule( | ||
id, | ||
title, | ||
body, | ||
scheduledDate, | ||
notificationDetails, | ||
uiLocalNotificationDateInterpretation: | ||
UILocalNotificationDateInterpretation.absoluteTime, | ||
androidAllowWhileIdle: true, | ||
); | ||
} | ||
} |
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
Oops, something went wrong.