fp_extensions

Collection of extensions for dart and flutter. This package includes extensions for Iterable, num, Map, String, , DateTime, Duration, BuildContext, Color, Theme,File.

Usage

for detailed documentations visit here

DateTime examples

final date = DateTime(2025, 12, 2);

// ordinal days
date.ordinalDay();                      // 2nd
date.formatOrdinal('MMMM do, y');       // December 2nd, 2025
date.formatOrdinal("EEE do 'do' MMM");  // Tue 2nd do Dec  (quoted text is literal)

// relative time
DateTime.now().subtract(const Duration(hours: 5)).timeAgo();   // 5 hours ago
DateTime.now().add(const Duration(days: 3, hours: 1)).timeAgo(); // in 3 days

Ordinal suffixes are English only; locale still controls month and weekday names.

Localizing timeAgo

English, Spanish, French and German are built in and picked from the locale's language code. Unknown languages fall back to English.

past.timeAgo(const Locale('es')); // hace 5 horas
past.timeAgo(const Locale('de')); // vor 5 Stunden

Add or override a language by extending TimeAgoMessages and registering it once at startup:

class NeTimeAgoMessages extends TimeAgoMessages {
  const NeTimeAgoMessages();
  @override String past(String text) => '$text अघि';
  @override String future(String text) => '$text पछि';
  @override String seconds(int n) => '$n सेकेन्ड';
  @override String get aMinute => 'एक मिनेट';
  @override String minutes(int n) => '$n मिनेट';
  @override String get anHour => 'एक घण्टा';
  @override String hours(int n) => '$n घण्टा';
  @override String get aDay => 'एक दिन';
  @override String days(int n) => '$n दिन';
  @override String get aMonth => 'एक महिना';
  @override String months(int n) => '$n महिना';
}

TimeAgoMessages.register('ne', const NeTimeAgoMessages());

You can also pass messages: for a single call, or override just the wording with pastSuffix / futurePrefix (an empty string drops it).

Libraries

fp_extensions
collection of extensions for dart types