timings_of_deen 0.0.1
timings_of_deen: ^0.0.1 copied to clipboard
Your comprehensive guide for daily Muslim practices. Access accurate prayer times, Qibla direction,and essential Islamic resources, all in one place..
# timings_of_deen
A comprehensive Flutter package for calculating accurate Islamic prayer times (Salat), Qibla direction, and Madina direction based on geographic coordinates and various calculation methods. This package handles complex astronomical calculations and timezone conversions to provide precise results for Muslim prayers.
## ✨ Features
* **Accurate Prayer Time Calculation**: Calculates Fajr, Sunrise, Dhuhr, Asr, Maghrib, and Isha.
* **Customizable Calculation Methods**: Supports various widely accepted methods (e.g., Muslim World League, Hanafi Asr).
* **Location-Based**: Uses latitude and longitude for precise calculations anywhere in the world.
* **Timezone Support**: Integrates with the `timezone` package for correct time display in local timezones, including daylight saving adjustments.
* **Qibla Direction**: Calculates the direction to the Kaaba in Makkah from any given coordinates.
* **Madina Direction**: Calculates the direction to Madina from any given coordinates.
* **Pre-computed Locations**: Includes basic data for districts in Bangladesh for quick setup (can be extended).
* **Debug Logging**: Provides detailed debug information during calculation to help verify results.
## 🚀 Installation
Add `timings_of_deen` to your `pubspec.yaml` file:
```yaml
dependencies:
timings_of_deen: ^latest_version # Check pub.dev for the latest version
timezone: ^latest_version # Required dependency for timezone handling
Then, run flutter pub get
in your terminal.
Initialize Timezones #
Before using the package, you must initialize the timezone data, typically in your main()
function:
import 'package:flutter/material.dart';
import 'package:timezone/data/latest.dart' as tz_data; // Import as tz_data
void main() {
WidgetsFlutterBinding.ensureInitialized();
tz_data.initializeTimeZones(); // Initialize timezone data
runApp(const MyApp());
}
📚 Usage #
Here's a basic example of how to calculate and display prayer times, Qibla, and Madina directions:
import 'package:flutter/material.dart';
import 'package:timings_of_deen/timings_of_deen.dart'; // Import the main package
import 'package:timezone/data/latest.dart' as tz_data;
import 'package:timezone/timezone.dart' as tz; // Alias timezone for clarity
import 'package:intl/intl.dart'; // For date and time formatting
void main() {
WidgetsFlutterBinding.ensureInitialized();
tz_data.initializeTimeZones();
runApp(const PrayerApp());
}
class PrayerApp extends StatelessWidget {
const PrayerApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Prayer Times Demo',
theme: ThemeData(primarySwatch: Colors.blueGrey),
home: const PrayerTimesScreen(),
);
}
}
class PrayerTimesScreen extends StatefulWidget {
const PrayerTimesScreen({super.key});
@override
State<PrayerTimesScreen> createState() => _PrayerTimesScreenState();
}
class _PrayerTimesScreenState extends State<PrayerTimesScreen> {
PrayerTimes? _prayerTimes;
double? _qiblaDirection;
double? _madinaDirection;
bool _isLoading = true;
// Example coordinates for Dhaka, Bangladesh
final Coordinates dhakaCoordinates = Coordinates(latitude: 23.8103, longitude: 90.4125);
final String dhakaTimezone = 'Asia/Dhaka';
@override
void initState() {
super.initState();
_calculateTimes();
}
void _calculateTimes() {
setState(() {
_isLoading = true;
});
final now = DateTime.now();
final locationTZ = tz.getLocation(dhakaTimezone);
final calculatedTimes = getPrayerTimesByCountry(
country: 'Bangladesh', // Or set a custom method/timezone directly
latitude: dhakaCoordinates.latitude,
longitude: dhakaCoordinates.longitude,
date: now,
useHanafiAsr: false, // Set to true for Hanafi Asr method
locationTZ: locationTZ, // Pass the specific timezone location
);
setState(() {
_prayerTimes = calculatedTimes;
_qiblaDirection = qiblaDirection(dhakaCoordinates);
_madinaDirection = madinaDirection(dhakaCoordinates);
_isLoading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Islamic Timings'),
centerTitle: true,
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Date: ${DateFormat.yMMMMEEEEd().format(_prayerTimes!.date)}',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
_buildInfoCard('Location', 'Dhaka, Bangladesh'),
_buildInfoCard('Qibla Direction', '${_qiblaDirection!.toStringAsFixed(2)}°'),
_buildInfoCard('Madina Direction', '${_madinaDirection!.toStringAsFixed(2)}°'),
_buildInfoCard('Calculation Method', 'Muslim World League (Default for Bangladesh)'),
const SizedBox(height: 20),
const Text(
'Prayer Times:',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
_buildPrayerTimeRow('Fajr', _prayerTimes!.fajr),
_buildPrayerTimeRow('Sunrise', _prayerTimes!.sunrise),
_buildPrayerTimeRow('Dhuhr', _prayerTimes!.dhuhr),
_buildPrayerTimeRow('Asr', _prayerTimes!.asr),
_buildPrayerTimeRow('Maghrib', _prayerTimes!.maghrib),
_buildPrayerTimeRow('Isha', _prayerTimes!.isha),
const Divider(),
_buildPrayerTimeRow('Tahajjud (Approx.)', _prayerTimes!.isha.subtract(const Duration(hours: 2))),
_buildPrayerTimeRow('Sehri Ends (Approx.)', _prayerTimes!.fajr.subtract(const Duration(minutes: 10))),
],
),
),
);
}
Widget _buildInfoCard(String title, String value) {
return Card(
margin: const EdgeInsets.symmetric(vertical: 4),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(title, style: const TextStyle(fontWeight: FontWeight.w600)),
Text(value),
],
),
),
);
}
Widget _buildPrayerTimeRow(String name, tz.TZDateTime time) {
return ListTile(
title: Text(name),
trailing: Text(
DateFormat('hh:mm a').format(time),
style: const TextStyle(fontWeight: FontWeight.bold),
),
);
}
}
🤝 Contributing #
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request on the GitHub repository.
📄 License #
This project is licensed under the MIT License - see the LICENSE file for details.
👨💻 Author #
Md. Rahul Reza
- Website: rahulreza.com
- Contact: contact@rahulreza.com