astrocalc 0.0.1

  • Example
  • Installing
  • Versions
  • 53


This library is a Dart port of the awesome Vladimir Agafonkin (@mourner)'s JavaScript library for calculating sun and moon positions and phases for a given location and time.

Calculations for other solar system bodies are also in the works.


AstroCalc is available on Pub.

See the examples folder for usage examples.



// Latitude and longitude in degrees
BaseCalc baseCalcChild = BaseCalcChild({ DateTime date, num longitude, num latitude })

All celestial body classes inherit from the abstract class BaseCalc. On instantiation, they all calculate and expose the following properties of the body for the provided location and time (each is a Map):

eclipticCoordsEarth-based ecliptic coordinates: latitude (eclipticCoords['lat']) and longitude (eclipticCoords['lng'])
equatorialCoordsEquatorial coordinates: right ascension (equatorialCoords['ra'] and declination equatorialCoords['dec'])
positionEarth-based horizontal coordinates: azimuth (position['azimuth']) and altitude (position['altitude'])
timesTimes of astronomical interest (body-specific)

The coordinate systems are returned in radians. For more information on each, see the following links:


SunCalc sunCalc = new SunCalc({ DateTime date, num longitude, num latitude })

In addition to the coordinate systems, SunCalc calculates the following times (accessible as properties of the Map sunCalc.times)

nightEndnight ends (morning astronomical dawn starts)
nauticalDawnnautical dawn (morning nautical dawn starts)
dawndawn (morning nautical dawn ends, morning civil dawn starts)
sunrisesunrise (top edge of the sun appears on the horizon)
sunriseEndsunrise ends (bottom edge of the sun touches the horizon)
goldenHourEndmorning golden hour (soft light, best time for photography) ends
solarNoonsolar noon (sun is in the highest position)
goldenHourevening golden hour starts
sunsetStartsunset starts (bottom edge of the sun touches the horizon)
sunsetsunset (sun disappears below the horizon, evening civil twilight starts)
duskdusk (evening nautical twilight starts)
nauticalDusknautical dusk (evening astronomical twilight starts)
nightnight starts (dark enough for astronomical observations)
nadirnadir (darkest moment of the night, sun is in the lowest position)


All notable changes to this project will be documented in this file.

28/09/2017 (0.0.1)


  • Base, extendable calc class with calculations for:

    • Ecliptic coordinates (latitude and longitude)
    • Equatorial coordinates (right ascension and declination)
    • Horizonatal coordinates (azimuth and altitude)
  • Times calculations for the Sun

    • nightEnd
    • nauticalDawn
    • dawn
    • sunrise
    • sunriseEnd
    • goldenHourEnd
    • solarNoon
    • goldenHour
    • sunsetStart
    • sunset
    • dusk
    • nauticalDusk
    • night
    • nadir


import 'package:astrocalc/astrocalc.dart';

main() {
  SunCalc sunCalc = new SunCalc(
    date: new,
    longitude: 3.3839178,
    latitude: 6.5069113

Use this package as a library

1. Depend on it

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

  astrocalc: "^0.0.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

      import 'package:astrocalc/astrocalc.dart';
Version Uploaded Documentation Archive
0.0.1 Sep 29, 2017 Go to the documentation of astrocalc 0.0.1 Download astrocalc 0.0.1 archive


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
13 / 100
Code health derived from static analysis. [more]
95 / 100
Reflects how tidy and up-to-date the package is. [more]
90 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:astrocalc/astrocalc.dart.


  • Homepage is not helpful.

    Update the homepage property: create a website about the package or use the source repository URL.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 9 hints.

    Run dartfmt to format lib/astrocalc.dart.

    Run dartfmt to format lib/src/base_calc.dart.

    Similar analysis of the following files failed:

    • lib/src/constants.dart (hint)
    • lib/src/sun_calc.dart (hint)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
Dev dependencies
test ^0.12.0