date_field 是一個 Flutter 套件,提供了一個用於選擇 DateTime 值的表單欄位小部件,其選擇器會根據平台自動適應——Android 和 Web 使用 Material Design,iOS 使用 Cupertino。它支援所有主要平台,包括 macOS、Windows 和 Linux。該套件包含全域函數,可輕鬆在應用程式任何位置呼叫日期和時間選擇器,簡化了在表單和使用者工作流程中的整合。它確保跨平台的一致使用者體驗,同時維持原生感覺。
適用情境
表單輸入項目需要選擇日期
時間追蹤應用程式
事件調度介面
使用者資料設定出生日期
基於日曆的資料輸入
主要特色
自適應 Material 與 Cupertino 選取器
全域選擇器呼叫函數
跨平台支援(Android、iOS、Web、macOS、Windows、Linux)
與 Form 小部件的輕鬆整合
可自訂的日期/時間格式
適合對象
使用日期輸入建構跨平台應用的開發人員
需要原生日期選擇器的應用
包含時間相關數據的表單密集型應用
優先考慮平台特定使用者介面一致性的團隊
使用建議
需要 Flutter SDK 2.5 或更高版本
非英文語言環境可能需要額外的本地化設定
選擇器外觀的自訂選項有限,僅限基本選項
依賴於平台特定的渲染行為
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
Welcome to the Date Field package! 📅
This package provides two widgets, DateTimeField and DateTimeFormField, which allow users to pick a
date and/or time from an input field. You can customize the appearance of the widgets using the
decoration argument, and specify whether to ask for a date, a time, or both using the mode
parameter. You can further customize the picker by configuring dialog properties.
iOS
Android
Getting Started 🚀
Add date_field package to your dependencies in pubspec.yaml.
dependencies:...date_field:^6.0.0
Run flutter pub get to install the package.
Initialize your systems locale. If not, users might see AM/PM even when
they configured their system to use 24h format. Add the following code to your main function:
To display the adaptive dialog without the field widget, you can directly use the showAdaptiveDateTimePicker.
finalDateTime? result = awaitshowAdaptiveDateTimePicker(
context: context,
mode: DateTimeFieldPickerMode.dateAndTime,
);
Note that you can also use the showMaterialDateTimePicker and showCupertinoDateTimePicker functions to show
the Material and Cupertino pickers directly.
Features 🎨
DateTimeField: A widget that allows users to pick a date and/or time from an input field.
DateTimeFormField: A FormField that contains a DateTimeField.
showAdaptiveDateTimePicker: A function that shows a date and/or time picker dialog based on the platform,
with the ability to customize the dialog properties.
showCupertinoDateTimePicker: A function that shows a Cupertino date and/or time picker dialog.
showMaterialDateTimePicker: A function that shows a Material date picker dialog.
Migration to 4.0.0 🚀
Version 4.0.0 contains breaking changes. Use dart fix to migrate to the latest version.
Known Issues 🐛
The pickers and formatted DateTimes adjust only on iOS and Android to the Device Systems Region.
On all other platforms, the pickers adjust to the locale.
See 32006
License 📜
This package is released under the MIT license.
Contributing 🤝
Contributions to this package are welcome! If you find a bug or have a feature request, please
create an issue on the GitHub repository. If you'd like to contribute code, please create a pull
request with your changes.
Before submitting a pull request, please make sure to run the tests and ensure they all pass.
Additionally, please follow the existing coding style and make sure your code is well-documented.