flutter_adhan 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

Adhan Swift #

badge-languages badge-pms badge-platforms

badge-pod badge-travis badge-cov

Adhan Swift is a well tested and well documented library for calculating Islamic prayer times. Adhan Swift supports Swift 4.0, Swift 4.2, Swift 5.0 and Objective-C.

All astronomical calculations are high precision equations directly from the book “Astronomical Algorithms” by Jean Meeus. This book is recommended by the Astronomical Applications Department of the U.S. Naval Observatory and the Earth System Research Laboratory of the National Oceanic and Atmospheric Administration.

Implementations of Adhan in other languages can be found in the parent repo Adhan.

Installation #

CocoaPods #

Adhan supports CocoaPods. Simply add the following line to your Podfile:

pod 'Adhan'

Carthage #

Adhan supports Carthage. Simply add the following line to your Cartfile:

github "batoulapps/adhan-swift" "master"

Swift Package Manager #

Adhan supports SPM. Simply add the following line to your dependencies value of your Package.swift file:

// swift-tools-version:4.2
dependencies: [
    .package(url: "https://github.com/batoulapps/adhan-swift", .branch("master")),
]

Manual #

You can also manually add Adhan.

  • Download the source.
  • Add Adhan.xcodeproj as a subproject in your app's project.
  • Drag Adhan.framework to "Linked Frameworks and Libraries" in your app's target.

Usage #

To get prayer times initialize the PrayerTimes struct passing in coordinates, date, and calculation parameters.

let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params)

Initialization parameters #

Coordinates

Create a Coordinates struct with the latitude and longitude for the location you want prayer times for.

let coordinates = Coordinates(latitude: 35.78056, longitude: -78.6389)

Date

To avoid confusion with timezones the date parameter passed in should be an instance of DateComponents. The year, month, and day components need to be populated. All other components will be ignored. The year, month and day values should be for the local date that you want prayer times for. These date components are expected to be for the Gregorian calendar.

let cal = Calendar(identifier: Calendar.Identifier.gregorian)
let date = cal.dateComponents([.year, .month, .day], from: Date())

Calculation parameters

The rest of the needed information is contained within the CalculationParameters struct. Instead of manually initializing this struct it is recommended to use one of the pre-populated instances by calling the params var on the CalculationMethod enum. You can then further customize the calculation parameters if needed.

var params = CalculationMethod.moonsightingCommittee.params
params.madhab = .hanafi
params.adjustments.fajr = 2
ParameterDescription
methodMember of CalculationMethod enum
fajrAngleAngle of the sun used to calculate Fajr
maghribAngleAngle of the sun used to calculate Maghrib, used for some Calculation Methods
ishaAngleAngle of the sun used to calculate Isha
ishaIntervalMinutes after Maghrib (if set, the time for Isha will be Maghrib plus ishaInterval)
madhabMember of the Madhab enum, used to calculate Asr
highLatitudeRuleMember of the HighLatitudeRule enum, used to set a minimum time for Fajr and a max time for Isha
adjustmentsPrayerAdjustments struct with custom prayer time adjustments in minutes for each prayer time

CalculationMethod

ValueDescription
muslimWorldLeagueMuslim World League. Fajr angle: 18, Isha angle: 17
egyptianEgyptian General Authority of Survey. Fajr angle: 19.5, Isha angle: 17.5
karachiUniversity of Islamic Sciences, Karachi. Fajr angle: 18, Isha angle: 18
ummAlQuraUmm al-Qura University, Makkah. Fajr angle: 18.5, Isha interval: 90. Note: you should add a +30 minute custom adjustment for Isha during Ramadan.
dubaiMethod used in UAE. Fajr angle: 18.2, Isha angle: 18.2.
qatarModified version of Umm al-Qura used in Qatar. Fajr angle: 18, Isha interval: 90.
kuwaitMethod used by the country of Kuwait. Fajr angle: 18, Isha angle: 17.5
moonsightingCommitteeMoonsighting Committee. Fajr angle: 18, Isha angle: 18. Also uses seasonal adjustment values.
singaporeMethod used by Singapore. Fajr angle: 20, Isha angle: 18.
tehranInstitute of Geophysics, University of Tehran. Fajr angle: 17.7, Maghrib angle: 4.5, Isha angle: 14.
northAmericaReferred to as the ISNA method. This method is included for completeness but is not recommended. Fajr angle: 15, Isha angle: 15
otherFajr angle: 0, Isha angle: 0. This is the default value for method when initializing a CalculationParameters struct.

Madhab

ValueDescription
shafiEarlier Asr time (use for Shafi, Maliki, Hanbali, and Jafari)
hanafiLater Asr time

HighLatitudeRule

ValueDescription
middleOfTheNightFajr will never be earlier than the middle of the night and Isha will never be later than the middle of the night
seventhOfTheNightFajr will never be earlier than the beginning of the last seventh of the night and Isha will never be later than the end of the first seventh of the night
twilightAngleSimilar to SeventhOfTheNight, but instead of 1/7, the fraction of the night used is fajrAngle/60 and ishaAngle/60

Prayer Times #

Once the PrayerTimes struct has been initialized it will contain members for all five prayer times and the time for sunrise. The prayer times will be instances of NSDate and as such will refer to a fixed point in universal time. To display these times for the local timezone you will need to create a date formatter and set the appropriate timezone.

let formatter = DateFormatter()
formatter.timeStyle = .medium
formatter.timeZone = TimeZone(identifier: "America/New_York")!

print("fajr \(formatter.string(from: prayers.fajr))")

Full Example #

let cal = Calendar(identifier: Calendar.Identifier.gregorian)
let date = cal.dateComponents([.year, .month, .day], from: Date())
let coordinates = Coordinates(latitude: 35.78056, longitude: -78.6389)
var params = CalculationMethod.moonsightingCommittee.params
params.madhab = .hanafi
if let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params) {
    let formatter = DateFormatter()
    formatter.timeStyle = .medium
    formatter.timeZone = TimeZone(identifier: "America/New_York")!

    print("fajr \(formatter.string(from: prayers.fajr))")
    print("sunrise \(formatter.string(from: prayers.sunrise))")
    print("dhuhr \(formatter.string(from: prayers.dhuhr))")
    print("asr \(formatter.string(from: prayers.asr))")
    print("maghrib \(formatter.string(from: prayers.maghrib))")
    print("isha \(formatter.string(from: prayers.isha))")
}

Convenience Utilities #

The PrayerTimes struct has functions for getting the current prayer and the next prayer. You can also get the time for a specified prayer, making it easier to dynamically show countdowns until the next prayer.

let prayerTimes = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params)

let current = prayerTimes.currentPrayer()
let next = prayerTimes.nextPrayer()
let countdown = prayerTimes.time(for: next)

Sunnah Times #

The Adhan library can also calulate Sunnah times. Given an instance of PrayerTimes, you can get a SunnahTimes struct with the times for Qiyam.

if let sunnahTimes = SunnahTimes(from: todayPrayers) {
	print(dateFormatter.string(from: sunnahTimes.lastThirdOfTheNight)
	print(dateFormatter.string(from: sunnahTimes.middleOfTheNight)
}

Qibla Direction #

Get the direction, in degrees from North, of the Qibla from a given set of coordinates.

let nyc = Coordinates(latitude: 40.7128, longitude: -74.0059)
let qiblaDirection = Qibla(coordinates: nyc).direction

Contributing #

Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all developers. We accept feature contributions provided that they are properly documented and include the appropriate unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different locations, we do ask that the source of the comparison values be properly documented.

License #

Adhan is available under the MIT license. See the LICENSE file for more info.

this is Port project from adhan-java thanks Batoul Apps

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_adhan: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_adhan/flutter_adhan.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
30
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/time_util/utils/calendar_util.dart.

Run flutter format to format lib/time_util/utils/calendar_util.dart.

Format lib/time_util/utils/solar_time.dart.

Run flutter format to format lib/time_util/utils/solar_time.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test