flutter_prayer_time_calculator 0.0.2 copy "flutter_prayer_time_calculator: ^0.0.2" to clipboard
flutter_prayer_time_calculator: ^0.0.2 copied to clipboard

A Flutter package to calculate Islamic prayer times with customizable methods and location/timezone support.

Prayer Times #

A comprehensive Flutter package for calculating Islamic prayer times with multiple calculation methods and customizable parameters.

Features #

  • ✅ Multiple calculation methods (MWL, ISNA, Egypt, Makkah, Karachi, Tehran, Jafari)
  • ✅ Support for different Asr calculation methods (Standard, Hanafi)
  • ✅ High latitude adjustment methods
  • ✅ Customizable time formats (24h, 12h, Float)
  • ✅ Time offsets and adjustments
  • ✅ Automatic timezone and DST detection
  • ✅ Type-safe enums for all parameters
  • ✅ Clean and intuitive API

Installation #

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

dependencies:
  flutter_prayer_time_calculator: ^1.0.0

Then run:

flutter pub get

Quick Start #

Basic Usage #

import 'package:flutter_prayer_time_calculator/flutter_prayer_time_calculator.dart';

// Create PrayerTimes instance
PrayerTimes pt = PrayerTimes();

// Get prayer times (latitude and longitude are required)
Map<PrayerTime, String> times = pt.getTimes(
  latitude: 43.6532,  // Toronto latitude
  longitude: -79.3832, // Toronto longitude
);

print('Fajr: ${times[PrayerTime.fajr]}');
print('Dhuhr: ${times[PrayerTime.dhuhr]}');
print('Asr: ${times[PrayerTime.asr]}');
print('Maghrib: ${times[PrayerTime.maghrib]}');
print('Isha: ${times[PrayerTime.isha]}');

Advanced Usage #

// Using specific parameters
Map<PrayerTime, String> times = pt.getTimes(
  date: DateTime(2024, 6, 15),
  latitude: 21.4225,   // Makkah latitude
  longitude: 39.8262,  // Makkah longitude
  elevation: 277,      // Makkah elevation in meters
  timezone: 3,         // Saudi Arabia timezone
  format: TimeFormat.twelveHour,
  method: CalculationMethod.makkah,
  asrMethod: AsrMethod.hanafi,
  highLatitudeMethod: HighLatitudeMethod.angleBased,
  offsets: {
    PrayerTime.fajr: 5,     // 5 minutes later
    PrayerTime.isha: -10,   // 10 minutes earlier
  },
);

Enums Reference #

CalculationMethod #

  • CalculationMethod.mwl - Muslim World League
  • CalculationMethod.isna - Islamic Society of North America
  • CalculationMethod.egypt - Egyptian General Authority of Survey
  • CalculationMethod.makkah - Umm Al-Qura University, Makkah
  • CalculationMethod.karachi - University of Islamic Sciences, Karachi
  • CalculationMethod.tehran - Institute of Geophysics, University of Tehran
  • CalculationMethod.jafari - Shia Ithna-Ashari, Leva Institute, Qum

TimeFormat #

  • TimeFormat.twentyFourHour - 24-hour format (default)
  • TimeFormat.twelveHour - 12-hour format with AM/PM
  • TimeFormat.float - Decimal hours

AsrMethod #

  • AsrMethod.standard - Standard Asr calculation
  • AsrMethod.hanafi - Hanafi Asr calculation

HighLatitudeMethod #

  • HighLatitudeMethod.none - No adjustment
  • HighLatitudeMethod.nightMiddle - Middle of night (default)
  • HighLatitudeMethod.angleBased - Angle-based adjustment
  • HighLatitudeMethod.oneSeventh - 1/7th of night

PrayerTime #

  • PrayerTime.imsak - Pre-dawn
  • PrayerTime.fajr - Dawn
  • PrayerTime.sunrise - Sunrise
  • PrayerTime.dhuhr - Midday
  • PrayerTime.asr - Afternoon
  • PrayerTime.sunset - Sunset
  • PrayerTime.maghrib - Evening
  • PrayerTime.isha - Night
  • PrayerTime.midnight - Midnight

Parameters #

Required Parameters #

  • latitude - Location latitude (-90 to 90)
  • longitude - Location longitude (-180 to 180)
  • timezone - Timezone offset in hours

Optional Parameters #

  • date - Date for calculation (default: current date)
  • elevation - Location elevation in meters (default: 0)
  • dst - Daylight saving time (default: auto-detected)
  • format - Time format (default: 24-hour)
  • method - Calculation method (default: MWL)
  • asrMethod - Asr calculation method (default: Standard)
  • highLatitudeMethod - High latitude adjustment (default: AngleBased)
  • offsets - Time offsets in minutes for each prayer

Custom Adjustments #

Method Parameters #

// Adjust calculation parameters
pt.adjust({
  'fajr': 18.5,      // Fajr angle
  'isha': 17.0,      // Isha angle
  'maghrib': '5 min', // Maghrib offset in minutes
});

Time Offsets #

// Set time offsets in minutes
pt.tune({
  PrayerTime.fajr: 2,    // 2 minutes later
  PrayerTime.dhuhr: 1,   // 1 minute later
  PrayerTime.asr: -1,    // 1 minute earlier
});

Method Information #

Get Current Method #

CalculationMethod currentMethod = pt.getMethod();
print('Current method: ${currentMethod.name}');

Get Current Settings #

Map<String, dynamic> settings = pt.getSetting();
Map<PrayerTime, double> offsets = pt.getOffsets();

Change Method #

pt.setMethod(CalculationMethod.isna);

Flutter Widget Example #

class PrayerTimesWidget extends StatelessWidget {
  final double latitude;
  final double longitude;

  const PrayerTimesWidget({
    Key? key,
    required this.latitude,
    required this.longitude,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    PrayerTimes pt = PrayerTimes(method: CalculationMethod.isna);

    Map<PrayerTime, String> times = pt.getTimes(
      latitude: latitude,
      longitude: longitude,
      format: TimeFormat.twelveHour,
    );

    return Column(
      children: PrayerTime.values.map((prayerTime) {
        return ListTile(
          title: Text(prayerTime.displayName),
          trailing: Text(times[prayerTime] ?? ''),
        );
      }).toList(),
    );
  }
}

Error Handling #

The package will throw ArgumentError if required parameters are missing:

try {
  Map<PrayerTime, String> times = pt.getTimes();
} catch (e) {
  print('Error: $e'); // Error: Latitude and longitude are required parameters
}

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

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

Credits #

Based on the original PrayTimes.js library by Hamid Zarrabi-Zadeh.

3
likes
150
points
18
downloads

Publisher

verified publisherdevxhub.com

Weekly Downloads

A Flutter package to calculate Islamic prayer times with customizable methods and location/timezone support.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_prayer_time_calculator