Skip to content
pubscout

sunrise_sunset_calc

3.0.0, released 4 years ago by avtobiografia.com

Calculates sunrise and sunset times given latitude, longitude, timezone offset and date.

WASM-ready
$ flutter pub add sunrise_sunset_calc
Source repository

What it does

Calculates the exact sunrise and sunset times for any given geographic coordinates, date, and timezone offset. It provides a simple API function to retrieve these times and also includes an async variant.

AI-written summary of version 3.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to compute sunrise and sunset times locally without relying on an external API.
  • You are building an application that adjusts its UI or behavior based on day and night cycles.

Skip it when

  • You need comprehensive astronomical data beyond basic sunrise and sunset times.

Strengths

  • Lightweight with minimal dependencies.
  • Supports both synchronous and asynchronous usage.
  • Cross-platform support including mobile, web, and desktop.

Weaknesses

  • Relies on manual timezone offsets using Durations rather than full IANA timezone database lookups.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
import 'package:sunrise_sunset_calc/sunrise_sunset_calc.dart';

main() {
  var sunriseSunset = getSunriseSunset(60.0, 60.0, 1, DateTime.now());
  print("Sunrise is at: ${sunriseSunset.sunrise.toString()}");
  print("Sunset is at: ${sunriseSunset.sunset.toString()}");
}

Alternatives

Packages that do the same job and could replace sunrise_sunset_calc.

  • latlong2

    Lightweight Dart library for latitude/longitude calculations.

  • jiffy

    Parse, manipulate, query, and format dates and times in Dart and Flutter.

  • sugar

    Standard library extension for date-times, timezones, collections, and monads.

  • time_machine2

    Comprehensive date and time library with support for timezones, calendars, cultures, and parsing.

Works with

Packages commonly used together with sunrise_sunset_calc: ones it builds on, ones built on it, and its own family.