islamic_utils 1.0.0
islamic_utils: ^1.0.0 copied to clipboard
A comprehensive Dart/Flutter package for Islamic utilities including accurate prayer times calculation with 18+ methods, Qibla direction and distance, and complete inheritance (faraidh) distribution a [...]
example/example.dart
// ignore_for_file: avoid_print
import 'package:islamic_utils/islamic_utils.dart';
void main() {
prayerTimesExample();
qiblaExample();
inheritanceExample();
}
/// Prayer Times Examples
void prayerTimesExample() {
print('=== PRAYER TIMES ===\n');
// Basic prayer times calculation
final jakarta = Coordinates(latitude: -6.2088, longitude: 106.8456);
final today = DateOnly.now();
final result = computePrayerTimes(
location: jakarta,
date: today,
timezone: 7, // WIB (UTC+7)
params: const PrayerCalculationParams(
method: CalculationMethods.kemenag,
),
);
if (result.isSuccess) {
final times = result.unwrap();
print(
'Prayer times for Jakarta on ${today.year}-${today.month}-${today.day}:');
print(' Imsak : ${times.formatted[PrayerName.imsak]}');
print(' Fajr : ${times.formatted[PrayerName.fajr]}');
print(' Sunrise : ${times.formatted[PrayerName.sunrise]}');
print(' Dhuhr : ${times.formatted[PrayerName.dhuhr]}');
print(' Asr : ${times.formatted[PrayerName.asr]}');
print(' Maghrib : ${times.formatted[PrayerName.maghrib]}');
print(' Isha : ${times.formatted[PrayerName.isha]}');
print('');
}
// Compare Asr times: Standard vs Hanafi
print('Asr Comparison:');
final standard = computePrayerTimes(
location: jakarta,
date: today,
timezone: 7,
params: const PrayerCalculationParams(
method: CalculationMethods.kemenag,
asrMadhhab: AsrMadhhab.standard,
),
);
final hanafi = computePrayerTimes(
location: jakarta,
date: today,
timezone: 7,
params: const PrayerCalculationParams(
method: CalculationMethods.kemenag,
asrMadhhab: AsrMadhhab.hanafi,
),
);
print(
' Standard (Shafi\'i): ${standard.unwrap().formatted[PrayerName.asr]}');
print(' Hanafi : ${hanafi.unwrap().formatted[PrayerName.asr]}');
print('');
// With safety buffer
print('With 2-minute safety buffer:');
final withBuffer = computePrayerTimes(
location: jakarta,
date: today,
timezone: 7,
params: const PrayerCalculationParams(
method: CalculationMethods.kemenag,
safetyBufferMinutes: 2,
),
);
print(' Fajr: ${withBuffer.unwrap().formatted[PrayerName.fajr]}');
print('');
// Monthly prayer times
print('Monthly prayer times for March 2024:');
final monthly = computeMonthlyPrayerTimes(
year: 2024,
month: 3,
location: jakarta,
timezone: 7,
params: const PrayerCalculationParams(method: CalculationMethods.kemenag),
);
if (monthly.isSuccess) {
print(' Days in month: ${monthly.unwrap().daysInMonth}');
print(
' First day Fajr: ${monthly.unwrap().days[0].formatted[PrayerName.fajr]}');
print(
' Last day Fajr: ${monthly.unwrap().days.last.formatted[PrayerName.fajr]}');
}
print('');
// Next prayer
print('Next Prayer:');
final nextPrayer = getNextPrayer(
location: jakarta,
timezone: 7,
params: const PrayerCalculationParams(method: CalculationMethods.kemenag),
);
if (nextPrayer.isSuccess) {
final next = nextPrayer.unwrap();
print(' Name: ${next.name.name}');
print(' Time: ${next.time}');
print(' In ${next.minutesUntil} minutes');
}
print('\n');
}
/// Qibla Direction Examples
void qiblaExample() {
print('=== QIBLA DIRECTION ===\n');
// Cities around the world
final cities = [
('Jakarta', Coordinates(latitude: -6.2088, longitude: 106.8456)),
('New York', Coordinates(latitude: 40.7128, longitude: -74.0060)),
('London', Coordinates(latitude: 51.5074, longitude: -0.1278)),
('Tokyo', Coordinates(latitude: 35.6762, longitude: 139.6503)),
('Sydney', Coordinates(latitude: -33.8688, longitude: 151.2093)),
];
for (final (name, coords) in cities) {
final result = computeQiblaDirection(
coordinates: coords,
includeDistance: true,
);
if (result.isSuccess) {
final qibla = result.unwrap();
print('$name:');
print(' Bearing: ${qibla.bearing.toStringAsFixed(1)}°');
print(' Direction: ${qibla.compassDirection.displayName}');
print(
' Distance: ${(qibla.meta.distance! / 1000).toStringAsFixed(0)} km');
print('');
}
}
// At Ka'bah
final atKaaba = computeQiblaDirection(
coordinates: Coordinates.kaaba,
);
print('At Ka\'bah: atKaaba=${atKaaba.unwrap().meta.atKaaba}');
print('\n');
}
/// Inheritance (Faraidh) Examples
void inheritanceExample() {
print('=== INHERITANCE (FARAIDH) ===\n');
// Example 1: Simple case - Wife and Son
print('Case 1: Wife + Son');
final case1 = computeInheritance(
estate: const EstateInput(grossValue: 800000000),
heirs: const [
HeirInput(type: HeirType.wife, count: 1),
HeirInput(type: HeirType.son, count: 1),
],
deceased: const DeceasedInfo(gender: Gender.male),
);
_printInheritanceResult(case1);
// Example 2: With deductions
print('Case 2: With Deductions (debts, funeral, wasiyyah)');
final case2 = computeInheritance(
estate: const EstateInput(
grossValue: 1000000000,
debts: 100000000,
funeralCosts: 20000000,
wasiyyah: 200000000, // Will be capped at 1/3
),
heirs: const [
HeirInput(type: HeirType.son, count: 1),
],
deceased: const DeceasedInfo(gender: Gender.male),
);
if (case2.isSuccess) {
final result = case2.unwrap();
print(' Gross: ${result.meta.estate.grossValue}');
print(' Funeral: ${result.meta.estate.deductions.funeralCosts}');
print(' Debts: ${result.meta.estate.deductions.debts}');
print(' Wasiyyah: ${result.meta.estate.deductions.wasiyyah}');
print(' Wasiyyah Capped: ${result.meta.estate.deductions.wasiyyahCapped}');
print(' Net Estate: ${result.netEstate}');
}
print('');
// Example 3: Hijab (blocking) - Father blocks brother
print('Case 3: Hijab - Father blocks Brother');
final case3 = computeInheritance(
estate: const EstateInput(grossValue: 1000000000),
heirs: const [
HeirInput(type: HeirType.father, count: 1),
HeirInput(type: HeirType.brotherFull, count: 1),
],
deceased: const DeceasedInfo(gender: Gender.male),
);
if (case3.isSuccess) {
for (final share in case3.unwrap().shares) {
print(
' ${share.heirType.name}: ${share.isBlocked ? "BLOCKED" : share.totalValue}');
}
}
print('');
// Example 4: Aul case
print('Case 4: Aul (Over-subscription) - Husband + 2 Sisters');
final case4 = computeInheritance(
estate: const EstateInput(grossValue: 600000000),
heirs: const [
HeirInput(type: HeirType.husband, count: 1),
HeirInput(type: HeirType.sisterFull, count: 2),
],
deceased: const DeceasedInfo(gender: Gender.female),
);
if (case4.isSuccess) {
final result = case4.unwrap();
print(' Aul Applied: ${result.summary.aulApplied}');
if (result.summary.aulApplied) {
print(' Original Denom: ${result.summary.aulOriginalDenominator}');
print(' New Denom: ${result.summary.aulNewDenominator}');
}
for (final share in result.shares.where((s) => !s.isBlocked)) {
print(
' ${share.heirType.name}: ${share.finalShare} = ${share.totalValue}');
}
}
print('');
// Example 5: Radd case
print('Case 5: Radd - 2 Daughters only');
final case5 = computeInheritance(
estate: const EstateInput(grossValue: 900000000),
heirs: const [
HeirInput(type: HeirType.daughter, count: 2),
],
deceased: const DeceasedInfo(gender: Gender.male),
);
if (case5.isSuccess) {
final result = case5.unwrap();
print(' Radd Applied: ${result.summary.raddApplied}');
final daughters = result.shares.first;
print(' Daughters: ${daughters.totalValue} (full estate after radd)');
}
print('');
// Example 6: Special Case - Umariyatayn
print('Case 6: Umariyatayn (Husband + Father + Mother)');
final case6 = computeInheritance(
estate: const EstateInput(grossValue: 600000000),
heirs: const [
HeirInput(type: HeirType.husband, count: 1),
HeirInput(type: HeirType.father, count: 1),
HeirInput(type: HeirType.mother, count: 1),
],
deceased: const DeceasedInfo(gender: Gender.female),
);
if (case6.isSuccess) {
final result = case6.unwrap();
print(' Special Case: ${result.summary.specialCase}');
for (final share in result.shares.where((s) => !s.isBlocked)) {
print(' ${share.heirType.name}: ${share.totalValue}');
}
}
print('');
// Example 7: With trace output
print('Case 7: With Trace Output');
final case7 = computeInheritance(
estate: const EstateInput(grossValue: 1000000000),
heirs: const [
HeirInput(type: HeirType.wife, count: 1),
HeirInput(type: HeirType.son, count: 1),
],
deceased: const DeceasedInfo(gender: Gender.male),
includeTrace: true,
);
if (case7.isSuccess) {
print(' Trace steps:');
for (final step in case7.unwrap().trace!) {
print(' [${step.step}] ${step.category}: ${step.description}');
}
}
}
void _printInheritanceResult(Result<InheritanceResult> result) {
if (result.isSuccess) {
final r = result.unwrap();
print(' Net Estate: ${r.netEstate}');
for (final share in r.shares.where((s) => !s.isBlocked)) {
print(
' ${share.heirType.name}: ${share.finalShare} = ${share.totalValue}');
}
print(' Valid: ${r.verification.isValid}');
} else {
print(' Error: ${result.errorOrNull}');
}
print('');
}