Skip to content

Commit

Permalink
adding notification feature in jadwal Sholat
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris80 committed Sep 16, 2023
1 parent 31692e6 commit a5bf588
Show file tree
Hide file tree
Showing 26 changed files with 404 additions and 120 deletions.
29 changes: 19 additions & 10 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a"
channel: "stable"
revision: "58ba6c295d8ccf125366b7e871b1c41fe2255f75"
channel: "master"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
base_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
- platform: android
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
- platform: ios
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
- platform: linux
create_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
base_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
- platform: macos
create_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
base_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
- platform: web
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
- platform: windows
create_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
base_revision: ff5b5b5fa6f35b717667719ddfdb1521d8bdd05a
create_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75
base_revision: 58ba6c295d8ccf125366b7e871b1c41fe2255f75

# User provided section

Expand Down
3 changes: 3 additions & 0 deletions .vs/CMakeWorkspaceSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"enableCMake": false
}
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "No Configurations"
}
9 changes: 9 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ExpandedNodes": [
"",
"\\lib",
"\\lib\\screens"
],
"SelectedNode": "\\lib\\screens\\detail_doa_screen.dart",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file added .vs/quran/v17/.wsuo
Binary file not shown.
Binary file added .vs/quran/v17/Browse.VC.db
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
Binary file added android/app/src/main/res/drawable/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/main/res/raw/adzan.mp3
Binary file not shown.
2 changes: 2 additions & 0 deletions android/app/src/main/res/raw/keep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@raw/adzan" />
Binary file added assets/sound/adzan.mp3
Binary file not shown.
12 changes: 12 additions & 0 deletions ios/RunnerTests/RunnerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Flutter
import UIKit
import XCTest

class RunnerTests: XCTestCase {

func testExample() {
// If you add code to the Runner application, consider adding tests here.
// See https://developer.apple.com/documentation/xctest for more information about using XCTest.
}

}
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:quran/screens/home_screen.dart';
import 'package:google_fonts/google_fonts.dart';
import 'services/notification.dart';
import 'package:timezone/data/latest.dart' as tz;

final colorScheme = ColorScheme.fromSeed(
brightness: Brightness.light,
Expand All @@ -16,6 +18,9 @@ final theme = ThemeData().copyWith(
textTheme: GoogleFonts.poppinsTextTheme());

void main() {
WidgetsFlutterBinding.ensureInitialized();
NotificationService().initNotification();
tz.initializeTimeZones();
runApp(
const ProviderScope(child: MyApp()),
);
Expand Down
30 changes: 11 additions & 19 deletions lib/screens/jadwal_sholat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
bool isLoading = false;
bool isMocked = false;
bool errorLocation = false;
bool delay = true;

Future<Position> _determinePosition() async {
LocationPermission permission;
Expand All @@ -33,9 +32,6 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
setState(() {
errorLocation = true;
});

if (permission == LocationPermission.denied) {
// Permissions are denied, next time you could try
Expand All @@ -44,6 +40,9 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
// returned true. According to Android guidelines
// your App should show an explanatory UI now.

setState(() {
errorLocation = true;
});
return Future.error('Acceses denied');
}
}
Expand All @@ -57,6 +56,7 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
setState(() {
isLoading = true;
});

final getPosition = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);

Expand All @@ -72,7 +72,9 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
position = getPosition;
userPlace = '${place.subAdministrativeArea}';
});
} catch (e) {}
} catch (e) {
print(e);
}
setState(() {
isLoading = false;
});
Expand All @@ -82,17 +84,8 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {

@override
void initState() {
super.initState();
Future.delayed(
Duration(seconds: 2),
() {
setState(() {
delay = false;
});
},
);

_determinePosition();
super.initState();
}

@override
Expand Down Expand Up @@ -121,7 +114,7 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
))
],
)
: delay == true
: isLoading == true
? Center(
child: CircularProgressIndicator(),
)
Expand Down Expand Up @@ -154,9 +147,8 @@ class _JadwalScreenState extends ConsumerState<JadwalScreen> {
height: 18,
),
data.when(
error: (error, stackTrace) => const Center(
child: Text('No data'),
),
error: (error, stackTrace) =>
Text(error.toString()),
loading: () => const Center(
child: CircularProgressIndicator(),
),
Expand Down
64 changes: 64 additions & 0 deletions lib/services/notification.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

import 'package:timezone/timezone.dart' as tz;

class NotificationService {
final FlutterLocalNotificationsPlugin notificationsPlugin =
FlutterLocalNotificationsPlugin();

final sound = 'adzan.mp3';

Future<void> initNotification() async {
AndroidInitializationSettings initializationSettingsAndroid =
const AndroidInitializationSettings('icon');

var initializationSettingsIOS = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
onDidReceiveLocalNotification:
(int id, String? title, String? body, String? payload) async {});

var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
await notificationsPlugin.initialize(initializationSettings,
onDidReceiveNotificationResponse:
(NotificationResponse notificationResponse) async {});
}

notificationDetails() {
return NotificationDetails(
android: AndroidNotificationDetails(
'your_channel_id',
'channelName',
playSound: true,
sound: RawResourceAndroidNotificationSound('adzan'),
importance: Importance.max,
priority: Priority.high,
),
iOS: DarwinNotificationDetails());
}

Future showNotification(
{int id = 0, String? title, String? body, String? payLoad}) async {
return notificationsPlugin.show(
id, title, body, await notificationDetails());
}

Future scheduleNotification(
{int id = 0,
String? title,
String? body,
String? payLoad,
required DateTime scheduledNotificationDateTime}) async {
return notificationsPlugin.zonedSchedule(
id,
title,
body,
tz.TZDateTime.from(scheduledNotificationDateTime, tz.local),
await notificationDetails(),
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
}
Loading

0 comments on commit a5bf588

Please sign in to comment.