-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added request notification permission popup
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,5 @@ enum PreferenceKeys { | |
tipType, | ||
sleepPermissionGranted, | ||
finishedIntroduction, | ||
notificationPermissionRequested, | ||
} |
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
68 changes: 68 additions & 0 deletions
68
lib/presentation/molecules/notification_permission_alert_dialog_molecule.dart
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,68 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:infinite_horizons/domain/controllers/controllers.dart'; | ||
import 'package:infinite_horizons/presentation/atoms/atoms.dart'; | ||
import 'package:infinite_horizons/presentation/molecules/molecules.dart'; | ||
|
||
void requestNotificationPermissionPopup(BuildContext context) { | ||
openAlertDialog( | ||
context, | ||
_NotificationPopup(), | ||
); | ||
} | ||
|
||
class _NotificationPopup extends StatefulWidget { | ||
@override | ||
State<_NotificationPopup> createState() => _NotificationPopupState(); | ||
} | ||
|
||
class _NotificationPopupState extends State<_NotificationPopup> { | ||
bool generalNotifications = false; | ||
bool isLoading = true; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
checkPermissionsState(); | ||
} | ||
|
||
Future checkPermissionsState() async { | ||
generalNotifications = !Platform.isAndroid && | ||
await NotificationsController.instance.isPermissionGranted(); | ||
|
||
setState(() { | ||
isLoading = false; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
height: 280, | ||
child: PageEnclosureMolecule( | ||
title: 'Notification Permission', | ||
subTitle: | ||
'Please approve the permission inorder for the app to work properly', | ||
child: CardAtom( | ||
child: isLoading | ||
? const ProgressIndicatorAtom(totalDuration: Duration(seconds: 3)) | ||
: ToggleSwitchMolecule( | ||
text: 'Notification Permission', | ||
description: | ||
'Get notify about timer status when the app is in the background', | ||
offIcon: Icons.notifications_off_outlined, | ||
onIcon: Icons.notifications_outlined, | ||
onChange: (value) async { | ||
await NotificationsController.instance.generalPermission(); | ||
await NotificationsController.instance | ||
.preciseAlarmPermission(); | ||
}, | ||
initialValue: generalNotifications, | ||
lockOnToggleOn: 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