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)


AstroCalc is a Dart library for calculating position and light phases for bodies in the solar system.