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

date_time_picker 封面
套件詳情v2.1.0

date_time_picker

一個 Flutter 小部件,用於顯示日期時間表單欄位,以顯示日期或時鐘對話方塊。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2.3萬
喜歡數
375
Pub 分數
130

安裝套件

flutter pub add date_time_picker

套件介紹

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

一個 Flutter 小部件,提供日期和時間表單欄位,顯示對話框以選擇日期或時間。它支援僅日期和僅時間的選擇器,跨 Android、iOS、Web、macOS、Windows 和 Linux 提供一致的使用者介面。該套件設計為可無縫整合至表單中,透過直覺的時間和日期選擇提升使用者體驗。它利用可用的原生對話框,確保平台適當的行為。

適用情境

  • 表單輸入項目需要選擇日期
  • 時間條目在排程應用程式中
  • 預訂系統中的日期和時間輸入
  • 使用者資料設定出生日期
  • 帶時間限制的事件創建

主要特色

  • 跨平台相容性
  • 原生對話框介面
  • 對日期和時間模式的支援
  • 與 Form 小部件的輕鬆整合
  • 可自訂的外觀與行為

適合對象

  • 需要日期/時間輸入的移動和網頁應用
  • 尋求簡單可靠的日期選擇器的開發者
  • 跨平台需要一致使用者體驗的應用
  • 包含大量表單且資料具有即時性的應用程式

使用建議

  • 超出基本樣式之外的有限自訂
  • 無內建驗證邏輯
  • 需要手動處理日期解析
  • 依賴於底層平台的日期/時間格式
  • 可能需要額外的地區化設定

原始 README

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

date_time_picker

pub package

Buy Me A Beer

A Flutter widget to show a text form field to display a date or clock dialog.
This widget extend TextField and has a similar behavior as TextFormField

Usage

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  date_time_picker: "^2.1.0"

In your library add the following import:

import 'package:date_time_picker/date_time_picker.dart';

For help getting started with Flutter, view the online documentation.

Example

There are four presentations for DateTimePicker and can be defined in the type parameter:

  • DateTimePickerType.date will present a text field with the action tap showing a datePicker dialog box;
  • DateTimePickerType.time will present a text field with the action tap showing a timePicker dialog box;
  • DateTimePickerType.dateTime will present a text field with the action tap showing a datePicker dialog box then a timePicker dialog box;
  • DateTimePickerType.dateTimeSeparated will display two text fields side by side, the first for date and the second for time. Each displaying their respective dialog box, datePicker and timePicker in the tap action;
DateTimePicker(
  type: date, // options: [date | time | dateTime | dateTimeSeparated], default is date
  ...
)

initialValue or controller.text can be null, empty or a DateTime string otherwise it will throw an error.

DateTimePicker(
  initialValue: '',
  firstDate: DateTime(2000),
  lastDate: DateTime(2100),
  dateLabelText: 'Date',
  onChanged: (val) => print(val),
  validator: (val) {
    print(val);
    return null;
  },
  onSaved: (val) => print(val),
);

More complete example:

DateTimePicker(
  type: DateTimePickerType.dateTimeSeparate,
  dateMask: 'd MMM, yyyy',
  initialValue: DateTime.now().toString(),
  firstDate: DateTime(2000),
  lastDate: DateTime(2100),
  icon: Icon(Icons.event),
  dateLabelText: 'Date',
  timeLabelText: "Hour",
  selectableDayPredicate: (date) {
    // Disable weekend days to select from the calendar
    if (date.weekday == 6 || date.weekday == 7) {
      return false;
    }

    return true;
  },
  onChanged: (val) => print(val),
  validator: (val) {
    print(val);
    return null;
  },
  onSaved: (val) => print(val),
);

The result of val in onChanged, validator and onSaved will be a DateTime String or just a Time String:

  • ex.: [2020-07-20 14:30] or [15:30] DateTimePickerType.time;
  • month, day, hour and minute will be 2 digits and time always be in 24 hours mode;
  • but the presentation in text field can be formated by the dateMask parameter.

Preview

Overview

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案