パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.0

system_date_time_format

デバイスのシステム設定から日付および時刻のフォーマットパターンを取得するためのプラグイン。

AndroidiOSLinuxmacOSWebWindows
30日間ダウンロード
3.2万
いいね数
17
Pub ポイント
160

パッケージをインストール

flutter pub add system_date_time_format

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

デバイスのシステム設定から日付および時刻のフォーマットパターンを直接取得するFlutterプラグインです。ネイティブOSの設定を利用することで、複数プラットフォーム間で一貫したフォーマットを保証し、ロケール対応の日時表示が必要なアプリに最適です。このパッケージはAndroid、iOS、Linux、macOS、Web、Windowsをサポートしており、手動設定なしで正確なシステムレベルのフォーマットを提供します。ユーザーの好みに自動的に適応することで、ローカライゼーション作業を簡素化します。

用途

  • ユーザーの好みの形式で日付を表示する
  • ローカライズされたカレンダーアプリの構築
  • 地域固有の時刻表示を作成する
  • システム設定との整合性を確保する
  • マルチ言語アプリケーションのサポート

主な機能

  • デバイスのシステム設定からフォーマットを取得する
  • クロスプラットフォーム互換性
  • 自動ロケール適応
  • 手動でのフォーマット設定は不要です
  • ネイティブOSフォーマットAPIを使用します

適している対象

  • グローバルなターゲットオーディエンス向けのアプリ
  • ローカライゼーション重視のアプリケーション
  • カレンダーやスケジューリングツール
  • ユーザー向けの日時ピッカー
  • システムの整合性を重視する開発者

注意事項

  • 一部のシステムでは、プラットフォーム固有の権限が必要です
  • 事前に定義されたシステム形式に限定
  • カスタムフォーマットの上書きをサポートしない可能性があります
  • デバイスの地域設定に依存
  • 非システム形式の要件には適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

A plugin for getting date & time format from device system settings.

Pub Package Build Status Code Coverage MIT License Android support ✓ iOS support ✓ macOS support ✓ windows support ✓ linux support ✓ web support ✓


Why system_date_time_format?

Flutter does not support retrieving date and time format patterns based on the user's system settings out of the box. However, you can use the system_date_time_format plugin to get date and time format patterns for consistent formatting in your Flutter app with ease:

final datePattern = SystemDateTimeFormat.datePattern;
print(datePattern); // e.g. "M/d/yy"
Examples
iOS (Region: United States 🇺🇸) Result
ios_setup ios_result
Android (Region: United Kingdom 🇬🇧) Result
android_setup android_result
macOS (Region: Poland 🇵🇱) Result
macos_setup macos_result
windows (Region: United States 🇺🇸) Result
windows_setup windows_result
linux (Region: United States 🇺🇸) Result
linux_setup linux_result
web (Region: Poland 🇵🇱)
web_result

Usage

Read a pattern directly from the current system settings. Medium and full date patterns return null on Windows and Linux.

import 'package:system_date_time_format/system_date_time_format.dart';

void main() {
  final date = SystemDateTimeFormat.datePattern;             // e.g. "M/d/yy"
  final mediumDate = SystemDateTimeFormat.mediumDatePattern; // e.g. "MMM d, y"
  final longDate = SystemDateTimeFormat.longDatePattern;     // e.g. "MMMM d, y"
  final fullDate = SystemDateTimeFormat.fullDatePattern;     // e.g. "EEEE, MMMM d, y"
  final time = SystemDateTimeFormat.timePattern;             // e.g. "HH:mm"
}
Migrating from 1.x

See the step-by-step migration guide.

Replace await SystemDateTimeFormat().getDatePattern() with SystemDateTimeFormat.datePattern. The other format methods follow the same naming convention. Replace calls to getAllPatterns() and SystemDateTimeFormat.of(context) with the individual getters you need. Remove the SDTFScope wrapper.

Each getter reads the current settings synchronously. A widget that reads patterns in build() picks up changes on its next rebuild.

Linux

Linux reads short date and time patterns from the active LC_TIME locale. For the long date, it uses the ICU date-only style for that locale. Install the ICU development package on the Linux build machine (for example, sudo apt install libicu-dev on Ubuntu or Debian). The application requires the matching ICU runtime libraries.

Web

Web getters use the browser’s locale and hour cycle. A getter returns null when the browser reports a field that has no matching pattern, such as a named year in the Chinese calendar. Load the JavaScript asset in index.html before Flutter starts.

From version 1.3.1 and above, the preferred way is to use the local asset:

<script src="./assets/packages/system_date_time_format/web/system_date_time_format.min.js"></script>

Alternatively, you can still use the CDN link:

<script src="https://cdn.jsdelivr.net/gh/Nikoro/system_date_time_format@main/web/system_date_time_format.min.js"></script>

index.html

<!DOCTYPE html>
<html>
<head>
    <!--...-->
    <script src="./assets/packages/system_date_time_format/web/system_date_time_format.min.js"></script>
</head>
<body>
<!--...-->
</body>
</html>
Testing

Mocktail stubs instance members. To test code that reads a static format getter, pass the consuming widget a value or a reader owned by your app. In example_with_tests, the production DeviceFormats.time getter calls SystemDateTimeFormat.timePattern. A widget test supplies a mock instance:

final formats = MockDeviceFormats();
when(() => formats.time).thenReturn('HH:mm');
await tester.pumpWidget(App(formats: formats));
expect(find.text('HH:mm'), findsOneWidget);

The example also tests how the app displays unavailable date styles. App adapter · Widget tests

カテゴリー

データはまだありません。

依存関係

依存関係一覧 7 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。

ランキング