Prayers Times is a Flutter package that provides utilities for calculating and displaying Islamic prayer times (Namaz times), as well as related insights like Qibla direction. It's a comprehensive solution for handling prayer timings in your Flutter applications.
- Calculate accurate Islamic prayer times (Namaz times) based on various calculation methods.
- Determine Qibla direction based on geographical coordinates.
- Calculate middle of the night and last third of the night times.
- Conversion utilities for different Islamic time formats.
Add prayers_times
as a dependency in your pubspec.yaml
file:
dependencies:
flutter:
sdk: flutter
prayers_times: <latest_version>
Import the package in your Dart file:
import 'package:prayers_times/prayers_times.dart';
To calculate and display prayer times for a specific location, follow these steps:
- Define the geographical coordinates for the location.
- Specify the calculation parameters for prayer times, such as the calculation method and madhab.
- Create a
PrayerTimes
instance using the provided coordinates and parameters. - Use the provided methods to access various prayer times and convenience utilities.
// Define the geographical coordinates for the location
Coordinates coordinates = Coordinates(21.1959, 72.7933);
// Specify the calculation parameters for prayer times
PrayerCalculationParameters params = PrayerCalculationMethod.karachi();
params.madhab = PrayerMadhab.hanafi;
// Create a PrayerTimes instance for the specified location
PrayerTimes prayerTimes = PrayerTimes(
coordinates: coordinates,
calculationParameters: params,
precision: true,
locationName: 'Asia/Kolkata',
);
To calculate prayer times for a specific date, you can create an instance of the PrayerTimes
class and provide a custom DateTime
object using the dateTime
parameter.
PrayerTimes prayerTimes = PrayerTimes(
coordinates: Coordinates(latitude, longitude),
calculationParameters: CalculationMethod.karachi(),
locationName: 'Your Location',
dateTime: DateTime(2023, 8, 15), // Specify the desired date
);
Display prayer times or Calculate accurate Islamic prayer times (Namaz times) based on various calculation methods.
print('Fajr Start Time:\t${prayerTimes.fajrStartTime!}');
print('Fajr End Time:\t${prayerTimes.fajrEndTime!}');
print('Sunrise Time:\t${prayerTimes.sunrise!}');
print('Dhuhr Start Time:\t${prayerTimes.dhuhrStartTime!}');
print('Dhuhr End Time:\t${prayerTimes.dhuhrEndTime!}');
print('Asr Start Time:\t${prayerTimes.asrStartTime!}');
print('Asr End Time:\t${prayerTimes.asrEndTime!}');
print('Maghrib Start Time:\t${prayerTimes.maghribStartTime!}');
print('Maghrib End Time:\t${prayerTimes.maghribEndTime!}');
print('Isha Start Time:\t${prayerTimes.ishaStartTime!}');
print('Isha End Time:\t${prayerTimes.ishaEndTime!}');
print('Isha End Time:\t${prayerTimes.ishaEndTime!}');
print('Tahajjud End Time:\t${prayerTimes.tahajjudEndTime!}');
The PrayerTimes
instance provides convenience utilities to determine the current and next prayer times, making it easy to display relevant information to users.
// Convenience Utilities
String current = prayerTimes.currentPrayer();
String next = prayerTimes.nextPrayer();
print('Current Prayer: $current ${prayerTimes.timeForPrayer(current)}');
print('Next Prayer: $next ${prayerTimes.timeForPrayer(next)}');
Utilize the SunnahInsights
class to calculate and display Sunnah times, such as the middle of the night and the last third of the night.
// Sunnah Times
SunnahInsights sunnahInsights = SunnahInsights(prayerTimes);
print('Middle of the Night: ${sunnahInsights.middleOfTheNight}');
print('Last Third of the Night: ${sunnahInsights.lastThirdOfTheNight}');
The Qibla
class provides methods to calculate the Qibla direction (direction of the Kaaba in Makkah) and the madina direction (direction of Al-Masjid an-Nabawi) from a given location. These calculations are based on the geographic coordinates (latitude and longitude) of the specified location and the coordinates of Makkah and Al-Masjid an-Nabawi. The calculations use spherical trigonometry to determine the angle between the specified location and the respective directions.
The qibla
method calculates the Qibla direction based on the geographic coordinates of the specified location and the coordinates of Makkah (the Holy Kaaba). The result is the clockwise angle from the North direction.
double qiblaDirection = Qibla.qibla(coordinates);
The madina
method calculates the madina direction based on the geographic coordinates of the specified location and the coordinates of Al-Masjid an-Nabawi. The result is the clockwise angle from the North direction.
double madinaDirection = Qibla.madina(coordinates);
The package offers customization options for various properties and calculations. Refer to the documentation for detailed information on customization options.
For detailed usage instructions and API documentation, please refer to the documentation.
See the CHANGELOG for a history of changes in the package.
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions, feel free to reach out:
- Email: ashrafchauhan567@gmail.com
- GitHub: @MohamedAshraf701
Contributions to the prayers_times
package are welcome! Please read the contribution guidelines before submitting a pull request.
Feel free to explore the features of the prayers_times
package and customize it to suit your needs. If you have any questions or feedback, don't hesitate to reach out. Happy coding!