Skip to content

Commit 555593c

Browse files
committed
FlutterLocalNotificationsPlugin() no longer refer-
enced from the main.dart
1 parent bcafcb3 commit 555593c

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

‎lib/main.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import 'views/bottomAppBar.dart';
1818
import 'views/onboarding_page.dart';
1919

2020
NotificationAppLaunchDetails notifLaunch;
21-
final FlutterLocalNotificationsPlugin notifsPlugin =
22-
FlutterLocalNotificationsPlugin();
2321

2422
void main() async {
2523
await GetStorage.init();
2624

25+
final FlutterLocalNotificationsPlugin notifsPlugin =
26+
FlutterLocalNotificationsPlugin();
2727
await _configureLocalTimeZone();
2828
notifLaunch = await notifsPlugin.getNotificationAppLaunchDetails();
2929
await initNotifications(notifsPlugin);

‎lib/notificationUtil/isolate_handler_notification.dart‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
12
import 'package:get_storage/get_storage.dart';
23
import 'package:isolate_handler/isolate_handler.dart';
34
import 'package:timezone/timezone.dart' as tz;
45
import 'package:waktusolatmalaysia/utils/debug_toast.dart';
56
import '../CONSTANTS.dart';
67
import '../locationUtil/locationDatabase.dart';
7-
import '../main.dart';
88
import 'notifications_helper.dart';
99

1010
// https://gist.github.com/taciomedeiros/50472cf94c742befba720853e9d598b6
1111

1212
final IsolateHandler isolateHandler = IsolateHandler();
13+
final _notifsPlugin = FlutterLocalNotificationsPlugin();
1314
DateTime currentDate = DateTime.now();
1415

1516
void schedulePrayNotification(List<dynamic> times) async {
16-
await notifsPlugin.cancelAll(); //reset all
17+
await _notifsPlugin.cancelAll(); //reset all
1718

1819
String currentLocation =
1920
LocationDatabase.getDaerah(GetStorage().read(kStoredGlobalIndex));
@@ -46,7 +47,7 @@ void schedulePrayNotification(List<dynamic> times) async {
4647
//to make sure the time is in future
4748
await schedulePrayerNotification(
4849
name: 'Fajr',
49-
notifsPlugin: notifsPlugin,
50+
notifsPlugin: _notifsPlugin,
5051
id: (subuhTimeEpoch / 1000).truncate(),
5152
title: 'It\'s Subuh',
5253
scheduledTime: tz.TZDateTime.from(
@@ -57,7 +58,7 @@ void schedulePrayNotification(List<dynamic> times) async {
5758
if (!(syurukTimeEpoch < currentTime)) {
5859
await schedulePrayerNotification(
5960
name: 'Syuruk',
60-
notifsPlugin: notifsPlugin,
61+
notifsPlugin: _notifsPlugin,
6162
id: (syurukTimeEpoch / 1000).truncate(),
6263
title: 'It\'s Syuruk',
6364
body: 'in ' + currentLocation,
@@ -67,7 +68,7 @@ void schedulePrayNotification(List<dynamic> times) async {
6768
if (!(zuhrTimeEpoch < currentTime)) {
6869
await schedulePrayerNotification(
6970
name: 'Zuhr',
70-
notifsPlugin: notifsPlugin,
71+
notifsPlugin: _notifsPlugin,
7172
id: (zuhrTimeEpoch / 1000).truncate(),
7273
title: 'It\'s Zohor',
7374
body: 'in ' + currentLocation,
@@ -77,7 +78,7 @@ void schedulePrayNotification(List<dynamic> times) async {
7778
if (!(asarTimeEpoch < currentTime)) {
7879
await schedulePrayerNotification(
7980
name: 'Asr',
80-
notifsPlugin: notifsPlugin,
81+
notifsPlugin: _notifsPlugin,
8182
id: (asarTimeEpoch / 1000).truncate(),
8283
title: 'It\'s Asar',
8384
body: 'in ' + currentLocation,
@@ -87,7 +88,7 @@ void schedulePrayNotification(List<dynamic> times) async {
8788
if (!(maghribTimeEpoch < currentTime)) {
8889
await schedulePrayerNotification(
8990
name: 'Maghrib',
90-
notifsPlugin: notifsPlugin,
91+
notifsPlugin: _notifsPlugin,
9192
id: (maghribTimeEpoch / 1000).truncate(),
9293
title: 'It\'s Maghrib',
9394
body: 'in ' + currentLocation,
@@ -97,7 +98,7 @@ void schedulePrayNotification(List<dynamic> times) async {
9798
if (!(isyakTimeEpoch < currentTime)) {
9899
await schedulePrayerNotification(
99100
name: 'Isya\'',
100-
notifsPlugin: notifsPlugin,
101+
notifsPlugin: _notifsPlugin,
101102
id: (isyakTimeEpoch / 1000).truncate(),
102103
title: 'It\'s Isyak',
103104
body: 'in ' + currentLocation,
@@ -109,7 +110,7 @@ void schedulePrayNotification(List<dynamic> times) async {
109110
}
110111

111112
scheduleAlertNotification(
112-
notifsPlugin: notifsPlugin,
113+
notifsPlugin: _notifsPlugin,
113114
id: 2190,
114115
title: 'Monthly refresh reminder',
115116
body:

‎lib/notificationUtil/notifications_helper.dart‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
66
import 'package:fluttertoast/fluttertoast.dart';
77
import 'package:rxdart/subjects.dart' as rxsub;
88
import '../CONSTANTS.dart';
9-
import '../main.dart';
109

1110
final rxsub.BehaviorSubject<NotificationClass>
1211
didReceiveLocalNotificationSubject =
@@ -47,17 +46,17 @@ Future<void> initNotifications(
4746
});
4847
}
4948

50-
void requestIOSPermissions(
51-
notifs.FlutterLocalNotificationsPlugin notifsPlugin) {
52-
notifsPlugin
53-
.resolvePlatformSpecificImplementation<
54-
notifs.IOSFlutterLocalNotificationsPlugin>()
55-
?.requestPermissions(
56-
alert: true,
57-
badge: true,
58-
sound: true,
59-
);
60-
}
49+
// void requestIOSPermissions(
50+
// notifs.FlutterLocalNotificationsPlugin notifsPlugin) {
51+
// notifsPlugin
52+
// .resolvePlatformSpecificImplementation<
53+
// notifs.IOSFlutterLocalNotificationsPlugin>()
54+
// ?.requestPermissions(
55+
// alert: true,
56+
// badge: true,
57+
// sound: true,
58+
// );
59+
// }
6160

6261
void configureSelectNotificationSubject(BuildContext context) {
6362
selectNotificationSubject.stream.listen((String payload) async {
@@ -144,6 +143,6 @@ Future<void> showDebugNotification() async {
144143
const NotificationDetails platformChannelSpecifics = NotificationDetails(
145144
android: androidPlatformChannelSpecifics,
146145
);
147-
await notifsPlugin.show(
146+
await FlutterLocalNotificationsPlugin().show(
148147
0, 'Debug notifs.', 'For developer purposes', platformChannelSpecifics);
149148
}

‎lib/views/Settings part/AboutPage.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
22
import 'package:flutter/gestures.dart';
33
import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
5+
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
56
import 'package:fluttertoast/fluttertoast.dart';
67
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
78
import 'package:get_storage/get_storage.dart';
@@ -11,7 +12,6 @@ import 'package:provider/provider.dart';
1112
import 'package:timezone/timezone.dart' as tz;
1213
import '../../CONSTANTS.dart';
1314
import '../../locationUtil/LocationData.dart';
14-
import '../../main.dart';
1515
import '../../notificationUtil/notifications_helper.dart';
1616
import '../../utils/launchUrl.dart';
1717
import '../Settings%20part/settingsProvider.dart';
@@ -67,7 +67,7 @@ class AboutAppPage extends StatelessWidget {
6767
subtitle: const Text('Payload: $kPayloadDebug'),
6868
onTap: () async {
6969
await scheduleAlertNotification(
70-
notifsPlugin: notifsPlugin,
70+
notifsPlugin: FlutterLocalNotificationsPlugin(),
7171
title: 'debug payload',
7272
id: 219, //randrom int haha
7373
body: 'With payload',

0 commit comments

Comments
 (0)