搜尋套件、儲存庫與 APP 分類

套件詳情v3.7.1

timeago

一個用於建立模糊時間戳的函式庫。(例如:「15分鐘前」)

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
75.8萬
喜歡數
2020
Pub 分數
160

安裝套件

flutter pub add timeago

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

timeago 套件提供了一種簡單的方式來產生人類可讀的模糊時間戳,例如「15分鐘前」或「2天前」。它非常適合在應用程式中顯示相對時間,透過讓時間更直覺來改善使用者體驗。此套件支援多種語言,並與所有主要平台相容,包括 Android、iOS、Web、macOS、Windows 和 Linux。它可透過簡單的 API 順暢整合至 Flutter 專案中。

適用情境

  • 在社交媒體應用中顯示貼文時間戳
  • 在聊天介面中顯示活動時間
  • 透過可讀的時間標籤增強使用者體驗
  • 在儀表板中追蹤事件持續時間
  • 與相對時間同步即時更新
  • 使用當前時間差動態更新UI

主要特色

  • 支援多種語言
  • 與 Flutter 的輕鬆整合
  • 跨平台相容性
  • 可自定義的格式化選項
  • 自動時間更新
  • 輕量且高效

適合對象

  • 社群媒體應用
  • 即時通訊應用
  • 儀表板小部件
  • 使用者活動追蹤系統
  • 任何需要可讀時間戳的應用程式

使用建議

  • 需要手動處理時區差異
  • 可能需要為非英文語言設定本地化
  • 不支援絕對日期格式化
  • 僅限相對時間顯示
  • 不適合用於精確時間戳儲存

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

timeago

timeago is a dart library that converts a date into a humanized text. Instead of showing a date 2020-12-12 18:30 with timeago you can display something like "now", "an hour ago", "~1y", etc

timeago pub package core library
timeago_flutter pub package flutter widgets

The easiest way to use this library via top-level function format(date):

import 'package:timeago/timeago.dart' as timeago;

main() {
    final fifteenAgo = DateTime.now().subtract(Duration(minutes: 15));

    print(timeago.format(fifteenAgo)); // 15 minutes ago
    print(timeago.format(fifteenAgo, locale: 'en_short')); // 15m
    print(timeago.format(fifteenAgo, locale: 'es')); // hace 15 minutos
}
IMPORTANT

timeago library ONLY includes en and es messages loaded by default.

To add more of the supported languages use timeago.setLocaleMessages(..). See locale messages.

Standard for language code

This library uses ISO 639-1 language code to identify the language. For more information see ISO 639-1.

Adding locales
timeago.setLocaleMessages('fr', timeago.FrMessages()); // Add french messages

print(timeago.format(fifteenAgo, locale: 'es')); // environ 15 minutes
Overriding locales or adding custom messages
// Override "en" locale messages with custom messages that are more precise and short
timeago.setLocaleMessages('en', MyCustomMessages());


// my_custom_messages.dart
class MyCustomMessages implements LookupMessages {
  @override String prefixAgo() => '';
  @override String prefixFromNow() => '';
  @override String suffixAgo() => '';
  @override String suffixFromNow() => '';
  @override String lessThanOneMinute(int seconds) => 'now';
  @override String aboutAMinute(int minutes) => '${minutes}m';
  @override String minutes(int minutes) => '${minutes}m';
  @override String aboutAnHour(int minutes) => '${minutes}m';
  @override String hours(int hours) => '${hours}h';
  @override String aDay(int hours) => '${hours}h';
  @override String days(int days) => '${days}d';
  @override String aboutAMonth(int days) => '${days}d';
  @override String months(int months) => '${months}mo';
  @override String aboutAYear(int year) => '${year}y';
  @override String years(int years) => '${years}y';
  @override String wordSeparator() => ' ';
}

Scope

While there are many request for adding more complex functionality I want keep this library as simple as possible to allow minimal maintenance.

The focus of this library should be

  1. Provide a single format function that transforms a date to a humanized value
  2. Give the abstractions for users to add their own languages or overriding them as they please
  3. Provide languages contributed by the community so users can add them as they need we should not add all languages by default.
  4. Library should not depend on any dependency

timeago_flutter widgets

  • Timeago
  • TimerRefresh
  • TimerRefreshWidget

Local development

  1. Install Melos (https://pub.dev/packages/melos):

dart pub global activate melos

  1. Bootstrap dependencies:

melos bootstrap

  1. Open desired package in VSCode or Webstorm

Live Demo

Here

所屬分類

依賴

依賴清單 1 項

  • intl>=0.18.0 <0.21.0

原始碼儲存庫

使用此套件的專案

所在榜單