Prayer Times Calculation for Dart

pub package pub popularity pub points Dart Flutter License: MIT Zero Dependencies

A minimalist, offline Prayer Times calculation SDK for Dart and Flutter applications.

Installation โ€ข Quick Start โ€ข API Reference โ€ข Examples โ€ข Documentation


๐ŸŒŸ Features

  • โœ… Zero Dependencies: No external packages required
  • โœ… Offline: Works completely offline without internet connection
  • โœ… Fast: Calculations complete in <10ms
  • โœ… Lightweight: Minimal package size
  • โœ… Accurate: ยฑ1 minute accuracy compared to official sources
  • โœ… Flexible: Support for multiple calculation methods and custom angles
  • โœ… Type Safe: Full Dart type safety with null safety compliance
  • โœ… Universal: Works in Dart CLI, Flutter mobile, web, and desktop apps
  • โœ… Well-tested: Comprehensive test suite with 25+ test cases

๐Ÿ“ฆ Installation

Add this to your package's pubspec.yaml file:

dependencies:
  prayer_times_calculation: ^1.0.0

Then run:

dart pub get

Or for Flutter projects:

flutter pub get

๐Ÿš€ Quick Start

import 'package:prayer_times_calculation/prayer_times_calculation.dart';

void main() {
  // Riyadh coordinates
  const latitude = 24.7136;
  const longitude = 46.6753;
  const timezone = 3.0; // UTC+3
  final date = DateTime.now();

  const options = CalculationOptions(
    method: CalculationMethod.mwl,
    asrJurisdiction: AsrJurisdiction.standard,
  );

  final prayerTimes = PrayerTimesSDK(latitude, longitude, date, timezone, options);
  final times = prayerTimes.getTimes();

  print('Prayer Times for Riyadh:');
  print('Fajr:    ${times.fajr}');
  print('Sunrise: ${times.sunrise}');
  print('Dhuhr:   ${times.dhuhr}');
  print('Asr:     ${times.asr}');
  print('Maghrib: ${times.maghrib}');
  print('Isha:    ${times.isha}');
}

๐Ÿ“š API Reference

PrayerTimesSDK

Main class for calculating prayer times.

PrayerTimesSDK(
  double latitude,     // Geographic latitude (-90 to 90)
  double longitude,    // Geographic longitude (-180 to 180)
  DateTime date,       // Date for calculation
  double timezone,     // UTC offset in hours
  CalculationOptions options,
)

Methods

  • PrayerTimes getTimes(): Returns calculated prayer times

CalculationOptions

Configuration for prayer time calculations.

const CalculationOptions({
  required CalculationMethod method,
  required AsrJurisdiction asrJurisdiction,
  double? fajrAngle,    // Required for custom method
  double? ishaAngle,    // Required for custom method
})

Enums

CalculationMethod

  • CalculationMethod.mwl - Muslim World League
  • CalculationMethod.isna - Islamic Society of North America
  • CalculationMethod.egypt - Egyptian General Authority
  • CalculationMethod.makkah - Umm Al-Qura University
  • CalculationMethod.karachi - University of Islamic Sciences, Karachi
  • CalculationMethod.custom - Custom angles

AsrJurisdiction

  • AsrJurisdiction.standard - Standard (Shafi/Maliki/Hanbali)
  • AsrJurisdiction.hanafi - Hanafi school

PrayerTimes

Result class containing formatted prayer times.

class PrayerTimes {
  final String fajr;     // Dawn prayer
  final String sunrise;  // Sunrise time
  final String dhuhr;    // Noon prayer
  final String asr;      // Afternoon prayer
  final String maghrib;  // Sunset prayer
  final String isha;     // Night prayer
}

โš™๏ธ Calculation Methods

Method Fajr Angle Isha Angle Description
MWL 18ยฐ 17ยฐ Muslim World League
ISNA 15ยฐ 15ยฐ Islamic Society of North America
Egypt 19.5ยฐ 17.5ยฐ Egyptian General Authority
Makkah 18.5ยฐ 18.5ยฐ Umm Al-Qura University
Karachi 18ยฐ 18ยฐ University of Islamic Sciences, Karachi
Custom Custom Custom User-defined angles

๐Ÿ•Œ Asr Calculation

  • Standard (Shafi/Maliki/Hanbali): Shadow length = object height
  • Hanafi: Shadow length = 2 ร— object height

๐Ÿ’ก Examples

Different Calculation Methods

// Muslim World League method (Most common)
const mwlOptions = CalculationOptions(
  method: CalculationMethod.mwl,
  asrJurisdiction: AsrJurisdiction.standard,
);

// Islamic Society of North America method
const isnaOptions = CalculationOptions(
  method: CalculationMethod.isna,
  asrJurisdiction: AsrJurisdiction.standard,
);

// Custom angles for specific requirements
const customOptions = CalculationOptions(
  method: CalculationMethod.custom,
  fajrAngle: 18.0,
  ishaAngle: 16.0,
  asrJurisdiction: AsrJurisdiction.hanafi,
);

Different Locations Around the World

// New York, USA
final nyTimes = PrayerTimesSDK(40.7128, -74.0060, DateTime.now(), -5.0, isnaOptions);

// London, UK
final londonTimes = PrayerTimesSDK(51.5074, -0.1278, DateTime.now(), 0.0, mwlOptions);

// Tokyo, Japan
final tokyoTimes = PrayerTimesSDK(35.6762, 139.6503, DateTime.now(), 9.0, mwlOptions);

// Cairo, Egypt
final cairoOptions = CalculationOptions(
  method: CalculationMethod.egypt,
  asrJurisdiction: AsrJurisdiction.standard,
);
final cairoTimes = PrayerTimesSDK(30.0444, 31.2357, DateTime.now(), 2.0, cairoOptions);

Flutter Widget Example

import 'package:flutter/material.dart';
import 'package:prayer_times_calculation/prayer_times_calculation.dart';

class PrayerTimesWidget extends StatefulWidget {
  @override
  _PrayerTimesWidgetState createState() => _PrayerTimesWidgetState();
}

class _PrayerTimesWidgetState extends State<PrayerTimesWidget> {
  PrayerTimes? _times;

  @override
  void initState() {
    super.initState();
    _calculatePrayerTimes();
  }

  void _calculatePrayerTimes() {
    // Use your location coordinates
    const latitude = 24.7136;  // Riyadh
    const longitude = 46.6753;
    const timezone = 3.0;

    const options = CalculationOptions(
      method: CalculationMethod.mwl,
      asrJurisdiction: AsrJurisdiction.standard,
    );

    final prayerTimes = PrayerTimesSDK(
      latitude,
      longitude,
      DateTime.now(),
      timezone,
      options,
    );

    setState(() {
      _times = prayerTimes.getTimes();
    });
  }

  @override
  Widget build(BuildContext context) {
    if (_times == null) {
      return CircularProgressIndicator();
    }

    return Column(
      children: [
        Text('Today\'s Prayer Times', style: Theme.of(context).textTheme.headline6),
        SizedBox(height: 16),
        _buildTimeRow('Fajr', _times!.fajr),
        _buildTimeRow('Sunrise', _times!.sunrise),
        _buildTimeRow('Dhuhr', _times!.dhuhr),
        _buildTimeRow('Asr', _times!.asr),
        _buildTimeRow('Maghrib', _times!.maghrib),
        _buildTimeRow('Isha', _times!.isha),
      ],
    );
  }

  Widget _buildTimeRow(String prayer, String time) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 4),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(prayer, style: TextStyle(fontSize: 16)),
          Text(time, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
        ],
      ),
    );
  }
}

Specific Date Calculations

// Calculate for Ramadan 2024
final ramadanStart = DateTime.utc(2024, 3, 11);
final ramadanTimes = PrayerTimesSDK(24.7136, 46.6753, ramadanStart, 3.0, mwlOptions);

// Calculate for next Friday
final nextFriday = DateTime.now().add(Duration(days: (5 - DateTime.now().weekday + 7) % 7));
final fridayTimes = PrayerTimesSDK(40.7128, -74.0060, nextFriday, -5.0, isnaOptions);

๐Ÿ“Š Performance

The SDK is designed for high performance:

Metric Value
Execution Time <10ms on average hardware
Memory Usage <100KB
Package Size Minimal

๐ŸŽฏ Accuracy

Prayer times are calculated with ยฑ1 minute accuracy compared to official Islamic authorities. The calculations use:

  • โœ“ Standard astronomical formulas
  • โœ“ Proper solar declination and equation of time
  • โœ“ Geographic coordinate corrections
  • โœ“ Timezone adjustments
  • โœ“ Atmospheric refraction corrections

๐ŸŒ Platform Support

Works on all Dart and Flutter supported platforms:

Platform Support
Dart CLI โœ…
Flutter Mobile โœ… iOS & Android
Flutter Web โœ…
Flutter Desktop โœ… Windows, macOS, Linux
Flutter Embedded โœ…

๐Ÿงช Testing

Run the test suite:

dart test

The package includes comprehensive tests covering:

  • All calculation methods
  • Different geographical locations
  • Performance benchmarks
  • Edge cases and validation

๐Ÿ“– Documentation

Additional Resources

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

git clone https://github.com/Muslims-Community/prayer-times-calculation-dart.git
cd prayer-times-calculation-dart
dart pub get
dart test

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Support

If you find this package helpful, please consider:

  • โญ Starring the repository
  • ๐Ÿ‘ Liking the package on pub.dev
  • ๐Ÿ› Reporting bugs via GitHub Issues
  • ๐Ÿ’ก Suggesting features
  • ๐Ÿ”„ Contributing code

๐Ÿ“ž Contact


Made with โค๏ธ for the Muslim community worldwide

Follow on GitHub

Libraries

prayer_times_calculation
A minimalist, offline Prayer Times calculation SDK for Dart and Flutter