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

套件詳情v7.0.0

date_field

一個表單欄位小部件,使用適應性的 Material 和 Cupertino 日期時間選擇器來選擇 DateTime 值。它還提供了全域函數來提供選擇器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2150
喜歡數
139
Pub 分數
160

安裝套件

flutter pub add date_field

套件介紹

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

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! 📅

pub 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
Date field picker package gif on an iOS device Date field picker package gif on an Android device

Getting Started 🚀

  1. Add date_field package to your dependencies in pubspec.yaml.

    dependencies:
      ...
      date_field: ^6.0.0
    
  2. Run flutter pub get to install the package.

  3. 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:

    import 'package:intl/intl_standalone.dart' if (dart.library.html) 'package:intl/intl_browser.dart';
    
    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await findSystemLocale();
      runApp(const MyApp());
    }
    
  4. Import the package in your Dart code.

    import 'package:date_field/date_field.dart';
    
  5. Use the Widget. Example:

    DateTimeFormField(
      decoration: const InputDecoration(
        labelText: 'Enter Date',
      ),
      firstDate: DateTime.now().add(const Duration(days: 10)),
      lastDate: DateTime.now().add(const Duration(days: 40)),
      initialPickerDateTime: DateTime.now().add(const Duration(days: 20)),
      onChanged: (DateTime? value) {
        selectedDate = value;
      },
    ),
    
  6. To display the adaptive dialog without the field widget, you can directly use the showAdaptiveDateTimePicker.

     final DateTime? result = await showAdaptiveDateTimePicker(
       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.

Thank you for your contributions!

Maintainers 👷

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案