Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit d7cd08b

Browse files
committed
feat: got application to request permission on launch if not provided
1 parent 7b6f20b commit d7cd08b

File tree

7 files changed

+100
-11
lines changed

7 files changed

+100
-11
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ android {
5555
minSdk = 29
5656
targetSdk = 35
5757
versionCode = 16
58-
versionName = "2025.3.31+1"
58+
versionName = "2025.3.31+2"
5959
}
6060
//
6161
signingConfigs {

assets/lotties/loading-bounce.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/features/home/views/dashboard.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@ class Dashboard extends StatefulWidget {
2020

2121
class _DashboardState extends State<Dashboard> {
2222
late Future<List<UserRole>?> roleresult;
23+
late Future<bool> notify;
2324
@override
2425
void initState() {
2526
super.initState();
2627
roleresult = BlocProvider.of<AuthBloc>(context).fetchUserRole(
2728
(BlocProvider.of<AuthBloc>(context).state as AuthenticatedState).user.id,
2829
);
30+
31+
BlocProvider.of<NotificationCubit>(context)
32+
.hasNotificationAccess()
33+
.then((val) {
34+
if (!context.mounted || val) return;
35+
showModalBottomSheet(
36+
context: context,
37+
builder: (context) => EnableNotificationsBanner(),
38+
);
39+
});
2940
}
3041

3142
@override
@@ -73,7 +84,7 @@ class _DashboardState extends State<Dashboard> {
7384
),
7485
actions: [
7586
CircleAvatar(
76-
backgroundColor: Colors.deepOrange,
87+
backgroundColor: Colors.black,
7788
child: IconButton(
7889
onPressed: () async {
7990
if (await Vibration.hasVibrator()) {
@@ -86,7 +97,10 @@ class _DashboardState extends State<Dashboard> {
8697

8798
context.pushNamed("memberships");
8899
},
89-
icon: Icon(Clarity.id_badge_line),
100+
icon: Icon(
101+
Clarity.id_badge_line,
102+
color: Colors.white,
103+
),
90104
),
91105
).animate().shake(duration: 2000.ms),
92106
IconButton(

lib/features/notifications/cubit/notification_cubit.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NotificationCubit extends Cubit<NotificationState> {
2929
final granted = await OneSignal.Notifications.requestPermission(true);
3030
if (granted) {
3131
OneSignal.User.addEmail(user.email!);
32-
OneSignal.User.addAlias(user.id, "id");
32+
OneSignal.User.addAlias("id", user.id);
3333
OneSignal.User.addTags({
3434
"firstname": user.firstname,
3535
"othernames": user.othernames,
@@ -43,11 +43,8 @@ class NotificationCubit extends Cubit<NotificationState> {
4343

4444
Future<bool> revokePermission(UserData user) async {
4545
try {
46-
final granted = await OneSignal.Notifications.requestPermission(false);
47-
if (granted) {
48-
return false;
49-
}
50-
return hasNotificationAccess();
46+
openAppSettings();
47+
return await hasNotificationAccess();
5148
} catch (e) {
5249
return await hasNotificationAccess();
5350
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export 'views/coming_soon_page.dart';
2+
export 'views/enable_notifications_banner.dart';
23
export 'cubit/notification_cubit.dart';
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import 'package:academia/features/features.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_animate/flutter_animate.dart';
4+
import 'package:flutter_bloc/flutter_bloc.dart';
5+
import 'package:icons_plus/icons_plus.dart';
6+
import 'package:vibration/vibration.dart';
7+
import 'package:vibration/vibration_presets.dart';
8+
9+
class EnableNotificationsBanner extends StatefulWidget {
10+
const EnableNotificationsBanner({super.key});
11+
12+
@override
13+
State<EnableNotificationsBanner> createState() =>
14+
_EnableNotificationsBannerState();
15+
}
16+
17+
class _EnableNotificationsBannerState extends State<EnableNotificationsBanner> {
18+
@override
19+
Widget build(BuildContext context) {
20+
return Container(
21+
padding: EdgeInsets.all(12),
22+
height: 160,
23+
child: Padding(
24+
padding: EdgeInsets.all(8),
25+
child: Column(
26+
spacing: 12,
27+
children: [
28+
Text(
29+
"Notifications permissions are off please grant notification permissions to stay updated 🫠",
30+
style: Theme.of(context).textTheme.titleMedium,
31+
),
32+
Row(
33+
mainAxisAlignment: MainAxisAlignment.end,
34+
children: [
35+
FilledButton.icon(
36+
style: ElevatedButton.styleFrom(
37+
iconColor: Colors.white,
38+
foregroundColor: Colors.white,
39+
backgroundColor: Colors.black,
40+
),
41+
icon: Icon(Clarity.bell_line),
42+
onPressed: () async {
43+
if (!context.mounted) return;
44+
45+
final user = (BlocProvider.of<AuthBloc>(context).state
46+
as AuthenticatedState)
47+
.user;
48+
await BlocProvider.of<NotificationCubit>(context)
49+
.requestPermission(user);
50+
51+
setState(() {});
52+
},
53+
label: Text("Grant Permission"),
54+
)
55+
.animate(
56+
delay: 1000.ms,
57+
onComplete: (controller) async {
58+
if (await Vibration.hasVibrator()) {
59+
await Vibration.vibrate(
60+
preset: VibrationPreset.dramaticNotification,
61+
);
62+
}
63+
})
64+
.shake(
65+
duration: 250.ms,
66+
)
67+
],
68+
)
69+
],
70+
),
71+
),
72+
).animate().fadeIn(
73+
duration: 1500.ms,
74+
curve: Curves.easeIn,
75+
);
76+
}
77+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1616
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1717
# In Windows, build-name is used as the major, minor, and patch parts
1818
# of the product and file versions while build-number is used as the build suffix.
19-
version: 2025.3.31+1
19+
version: 2025.3.31+2
2020

2121
environment:
2222
sdk: ^3.6.0-216.1.beta

0 commit comments

Comments
 (0)