File tree Expand file tree Collapse file tree 5 files changed +59
-4
lines changed
android/app/src/main/res/drawable Expand file tree Collapse file tree 5 files changed +59
-4
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
2
+
3
+ class NotificationService {
4
+ static final NotificationService _notificationService = NotificationService ._internal ();
5
+ final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin ();
6
+
7
+ NotificationDetails platformChannelSpecifics = const NotificationDetails (
8
+ android: AndroidNotificationDetails (
9
+ "0" ,
10
+ "Flutter Local Notification" ,
11
+ importance: Importance .defaultImportance,
12
+ priority: Priority .defaultPriority,
13
+ ),
14
+ );
15
+
16
+ factory NotificationService () {
17
+ return _notificationService;
18
+ }
19
+
20
+ NotificationService ._internal ();
21
+
22
+ Future <void > init () async {
23
+ const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings ('app_icon' );
24
+
25
+ const InitializationSettings initializationSettings =
26
+ InitializationSettings (android: initializationSettingsAndroid);
27
+
28
+ await flutterLocalNotificationsPlugin.initialize (
29
+ initializationSettings,
30
+ );
31
+ }
32
+
33
+ void sendAndoidNotification ({required String title, required String body}) async {
34
+ await flutterLocalNotificationsPlugin.show (
35
+ 0 ,
36
+ title,
37
+ body,
38
+ platformChannelSpecifics,
39
+ payload: 'data' ,
40
+ );
41
+ }
42
+ }
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
2
3
import 'package:hooks_riverpod/hooks_riverpod.dart' ;
4
+ import 'package:untis_phasierung/core/service/notification.service.dart' ;
3
5
import 'package:untis_phasierung/core/service/services.dart' ;
4
6
import 'package:untis_phasierung/ui/screens/settings/settings.screen.dart' ;
5
7
import 'package:untis_phasierung/ui/screens/time_table/time_table.screen.dart' ;
@@ -8,8 +10,10 @@ import 'package:untis_phasierung/ui/shared/custom_drawer.dart';
8
10
import 'package:logger/logger.dart' ;
9
11
import 'package:untis_phasierung/ui/screens/login/login.screen.dart' ;
10
12
11
- void main () {
13
+ Future < void > main () async {
12
14
Logger .level = Level .debug;
15
+ WidgetsFlutterBinding .ensureInitialized ();
16
+ await NotificationService ().init ();
13
17
runApp (
14
18
const ProviderScope (
15
19
child: MyApp (),
Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
2
3
import 'package:hooks_riverpod/hooks_riverpod.dart' ;
3
4
import 'package:liquid_pull_to_refresh/liquid_pull_to_refresh.dart' ;
4
5
import 'package:untis_phasierung/core/api/models/timetable.hour.dart' ;
5
6
import 'package:untis_phasierung/core/api/timetable.dart' ;
6
7
import 'package:untis_phasierung/core/excel/models/mergedtimetable.dart' ;
8
+ import 'package:untis_phasierung/core/service/notification.service.dart' ;
7
9
import 'package:untis_phasierung/core/service/services.dart' ;
8
10
import 'package:untis_phasierung/ui/screens/time_table/widgets/custom_time_table_card.dart' ;
9
11
import 'package:untis_phasierung/ui/screens/time_table/widgets/custom_time_table_day_card.dart' ;
@@ -245,7 +247,13 @@ class TimeTableScreen extends ConsumerWidget {
245
247
},
246
248
icon: const Icon (Icons .today),
247
249
tooltip: "Spring zur aktuellen Woche" ,
248
- )
250
+ ),
251
+ IconButton (
252
+ onPressed: () {
253
+ NotificationService ().sendAndoidNotification (title: "Test" , body: "lol" );
254
+ },
255
+ icon: const Icon (Icons .notification_add),
256
+ ),
249
257
],
250
258
),
251
259
drawer: const CustomDrawer (),
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ dependencies:
13
13
file_picker : ^4.3.1
14
14
flutter :
15
15
sdk : flutter
16
+ flutter_local_notifications : ^9.2.0
16
17
flutter_secure_storage : ^5.0.2
17
18
fluttericon : ^2.0.0
18
19
google_fonts : ^2.2.0
@@ -26,9 +27,9 @@ dependencies:
26
27
url_launcher : ^6.0.17
27
28
28
29
dev_dependencies :
29
- flutter_native_splash : ^1.3.3
30
30
flutter_launcher_icons : " ^0.9.2"
31
31
flutter_lints : ^1.0.0
32
+ flutter_native_splash : ^1.3.3
32
33
flutter_test :
33
34
sdk : flutter
34
35
@@ -40,4 +41,4 @@ flutter:
40
41
flutter_icons :
41
42
android : true
42
43
ios : true
43
- image_path : " assets/images/app_icon.png"
44
+ image_path : " assets/images/app_icon.png"
You can’t perform that action at this time.
0 commit comments