Skip to content

Commit 7f14e7b

Browse files
moneymate updated notification added
1 parent fb81f89 commit 7f14e7b

File tree

8 files changed

+175
-14
lines changed

8 files changed

+175
-14
lines changed

MoneyMate/money_mate/android/app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ android {
4242
// You can update the following values to match your application needs.
4343
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
4444
minSdk = 23
45-
targetSdk = flutter.targetSdkVersion
45+
targetSdk = 33
4646
versionCode = flutterVersionCode.toInteger()
4747
versionName = flutterVersionName
4848
}

MoneyMate/money_mate/android/app/src/main/AndroidManifest.xml

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
3+
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
4+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
5+
26
<application
37
android:label="MoneyMate"
48
android:name="${applicationName}"
@@ -30,6 +34,16 @@
3034
<meta-data
3135
android:name="flutterEmbedding"
3236
android:value="2" />
37+
38+
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
39+
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
40+
<intent-filter>
41+
<action android:name="android.intent.action.BOOT_COMPLETED"/>
42+
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
43+
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
44+
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
45+
</intent-filter>
46+
</receiver>
3347
</application>
3448
<!-- Required to query activities that can process text, see:
3549
https://developer.android.com/training/package-visibility and

MoneyMate/money_mate/lib/ImportAll.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export 'package:flutter/services.dart';
1212

1313
export 'package:syncfusion_flutter_charts/charts.dart';
1414
export 'package:syncfusion_flutter_charts/sparkcharts.dart';
15+
export 'package:flutter_local_notifications/flutter_local_notifications.dart';
1516

1617
// screens
1718
export 'screens/HomeScreen.dart';
@@ -23,7 +24,7 @@ export 'screens/Register.dart';
2324
export 'screens/InfoScreen.dart';
2425

2526
export 'chartTest.dart';
26-
27+
export 'ScheduleNotiify.dart';
2728

2829
// helper
2930
export 'helper/AllRoutes.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import 'package:timezone/data/latest_all.dart' as tz;
2+
import 'package:timezone/timezone.dart' as tz;
3+
import 'ImportAll.dart';
4+
5+
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
6+
FlutterLocalNotificationsPlugin();
7+
8+
Future<void> requestNotificationPermissions() async {
9+
final bool? granted = await flutterLocalNotificationsPlugin
10+
.resolvePlatformSpecificImplementation<
11+
AndroidFlutterLocalNotificationsPlugin>()
12+
?.requestNotificationsPermission();
13+
14+
if (granted == true) {
15+
print("Notification permissions granted.");
16+
} else {
17+
print("Notification permissions denied.");
18+
}
19+
}
20+
21+
Future<void> initializeNotifications() async {
22+
const AndroidInitializationSettings initializationSettingsAndroid =
23+
AndroidInitializationSettings('@mipmap/ic_launcher');
24+
25+
const InitializationSettings initializationSettings = InitializationSettings(
26+
android: initializationSettingsAndroid,
27+
);
28+
29+
await flutterLocalNotificationsPlugin.initialize(
30+
initializationSettings,
31+
onDidReceiveNotificationResponse: (NotificationResponse response) {
32+
print('Notification Clicked!');
33+
AuthWrapper();
34+
},
35+
// onDidReceiveBackgroundNotificationResponse: (NotificationResponse response) {
36+
// print('Background Notification Clicked!');
37+
// },
38+
);
39+
}
40+
41+
Future<void> scheduleDailyNotification() async {
42+
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
43+
final tz.TZDateTime scheduledTime = tz.TZDateTime(
44+
tz.local,
45+
now.year,
46+
now.month,
47+
now.day,
48+
15,
49+
45,
50+
);
51+
52+
final tz.TZDateTime adjustedScheduledTime = scheduledTime.isBefore(now)
53+
? scheduledTime.add(Duration(days: 1))
54+
: scheduledTime;
55+
56+
const AndroidNotificationDetails androidNotificationDetails =
57+
AndroidNotificationDetails(
58+
'MoneyMate',
59+
'Daily Reminder',
60+
channelDescription: 'Daily notifications at a fixed time',
61+
importance: Importance.high,
62+
priority: Priority.high,
63+
color: Color(0xFF42A5F5),
64+
// Custom notification color
65+
playSound: true,
66+
enableLights: true,
67+
enableVibration: true,
68+
visibility: NotificationVisibility.public,
69+
// Make it visible on the lock screen
70+
timeoutAfter: 10000,
71+
// Timeout after 10 seconds
72+
actions: <AndroidNotificationAction>[
73+
AndroidNotificationAction(
74+
'action_id_1',
75+
'Mark as Done', // Action button to mark as done
76+
),
77+
AndroidNotificationAction(
78+
'action_id_2',
79+
'Dismiss', // Action button to dismiss
80+
),
81+
],
82+
);
83+
84+
const NotificationDetails notificationDetails =
85+
NotificationDetails(android: androidNotificationDetails);
86+
87+
await flutterLocalNotificationsPlugin.zonedSchedule(
88+
0,
89+
'MoneyMate',
90+
'This is your daily reminder at 11 PM.',
91+
adjustedScheduledTime,
92+
notificationDetails,
93+
uiLocalNotificationDateInterpretation:
94+
UILocalNotificationDateInterpretation.absoluteTime,
95+
matchDateTimeComponents: DateTimeComponents.time,
96+
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
97+
);
98+
}

MoneyMate/money_mate/lib/main.dart

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import 'ImportAll.dart';
2+
import 'package:timezone/data/latest_all.dart' as tz;
23

34
void main() async {
45
WidgetsFlutterBinding.ensureInitialized();
6+
tz.initializeTimeZones();
7+
await initializeNotifications();
8+
await requestNotificationPermissions();
9+
await scheduleDailyNotification();
10+
511
await Firebase.initializeApp(
612
options: DefaultFirebaseOptions.currentPlatform,
713
);

MoneyMate/money_mate/pubspec.lock

+40
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ packages:
105105
url: "https://pub.dev"
106106
source: hosted
107107
version: "1.0.8"
108+
dbus:
109+
dependency: transitive
110+
description:
111+
name: dbus
112+
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
113+
url: "https://pub.dev"
114+
source: hosted
115+
version: "0.7.10"
108116
equatable:
109117
dependency: transitive
110118
description:
@@ -214,6 +222,30 @@ packages:
214222
url: "https://pub.dev"
215223
source: hosted
216224
version: "3.0.2"
225+
flutter_local_notifications:
226+
dependency: "direct main"
227+
description:
228+
name: flutter_local_notifications
229+
sha256: ef41ae901e7529e52934feba19ed82827b11baa67336829564aeab3129460610
230+
url: "https://pub.dev"
231+
source: hosted
232+
version: "18.0.1"
233+
flutter_local_notifications_linux:
234+
dependency: transitive
235+
description:
236+
name: flutter_local_notifications_linux
237+
sha256: "8f685642876742c941b29c32030f6f4f6dacd0e4eaecb3efbb187d6a3812ca01"
238+
url: "https://pub.dev"
239+
source: hosted
240+
version: "5.0.0"
241+
flutter_local_notifications_platform_interface:
242+
dependency: transitive
243+
description:
244+
name: flutter_local_notifications_platform_interface
245+
sha256: "6c5b83c86bf819cdb177a9247a3722067dd8cc6313827ce7c77a4b238a26fd52"
246+
url: "https://pub.dev"
247+
source: hosted
248+
version: "8.0.0"
217249
flutter_svg:
218250
dependency: "direct dev"
219251
description:
@@ -517,6 +549,14 @@ packages:
517549
url: "https://pub.dev"
518550
source: hosted
519551
version: "0.7.2"
552+
timezone:
553+
dependency: "direct main"
554+
description:
555+
name: timezone
556+
sha256: ffc9d5f4d1193534ef051f9254063fa53d588609418c84299956c3db9383587d
557+
url: "https://pub.dev"
558+
source: hosted
559+
version: "0.10.0"
520560
typed_data:
521561
dependency: transitive
522562
description:

MoneyMate/money_mate/pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ dependencies:
2020
fluttertoast: ^8.2.6
2121
share_plus: ^10.0.0
2222
syncfusion_flutter_charts: ^28.1.35
23+
flutter_local_notifications: ^18.0.1
24+
timezone: ^0.10.0
2325

2426

2527
dev_dependencies:

StudyMate/pubspec.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ packages:
7979
dependency: transitive
8080
description:
8181
name: leak_tracker
82-
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
82+
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
8383
url: "https://pub.dev"
8484
source: hosted
85-
version: "10.0.4"
85+
version: "10.0.5"
8686
leak_tracker_flutter_testing:
8787
dependency: transitive
8888
description:
8989
name: leak_tracker_flutter_testing
90-
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
90+
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
9191
url: "https://pub.dev"
9292
source: hosted
93-
version: "3.0.3"
93+
version: "3.0.5"
9494
leak_tracker_testing:
9595
dependency: transitive
9696
description:
@@ -119,18 +119,18 @@ packages:
119119
dependency: transitive
120120
description:
121121
name: material_color_utilities
122-
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
122+
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
123123
url: "https://pub.dev"
124124
source: hosted
125-
version: "0.8.0"
125+
version: "0.11.1"
126126
meta:
127127
dependency: transitive
128128
description:
129129
name: meta
130-
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
130+
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
131131
url: "https://pub.dev"
132132
source: hosted
133-
version: "1.12.0"
133+
version: "1.15.0"
134134
path:
135135
dependency: transitive
136136
description:
@@ -188,10 +188,10 @@ packages:
188188
dependency: transitive
189189
description:
190190
name: test_api
191-
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
191+
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
192192
url: "https://pub.dev"
193193
source: hosted
194-
version: "0.7.0"
194+
version: "0.7.2"
195195
vector_math:
196196
dependency: transitive
197197
description:
@@ -204,10 +204,10 @@ packages:
204204
dependency: transitive
205205
description:
206206
name: vm_service
207-
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
207+
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
208208
url: "https://pub.dev"
209209
source: hosted
210-
version: "14.2.1"
210+
version: "14.2.5"
211211
sdks:
212212
dart: ">=3.4.3 <4.0.0"
213213
flutter: ">=3.18.0-18.0.pre.54"

0 commit comments

Comments
 (0)