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

套件詳情v0.4.3

flutter_date_pickers

用於選擇日期、週、範圍和月份的 Flutter 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2.7萬
喜歡數
158
Pub 分數
150

安裝套件

flutter pub add flutter_date_pickers

套件介紹

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

一個 Flutter 套件,提供可自訂的日期選擇器,用於選擇日期、週、日期範圍和月份。支援多個平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。該套件提供一致且直覺的日期選擇使用者介面,可輕鬆整合至 Flutter 應用程式中。設計上靈活且可擴展,讓開發者能根據應用程式設計需求調整選擇器的外觀與行為。適用於表單、排程工具及基於日曆的應用程式。

適用情境

  • 表單輸入項目需要選擇日期
  • 排程與預訂系統
  • 日曆和計畫應用
  • 日期範圍篩選
  • 事件創建介面

主要特色

  • 天、週、範圍和月選擇器類型
  • 跨平台相容性
  • 可自訂的 UI 主題
  • 與 Flutter 的輕鬆整合
  • 對本地化的支援
  • 可設定的日期範圍

適合對象

  • 開發日曆功能的開發者
  • 需要高級日期選擇的應用程式
  • 需要多平台日期選擇器的項目
  • UI密集型表單組件

使用建議

  • 需要 Flutter SDK 2.5 或更高版本
  • 可能需要額外的樣式來支援自定主題
  • 有限的內建驗證
  • 依賴於平台特定的日期處理
  • 未針對非常大的日期範圍進行優化

原始 README

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

flutter_date_pickers

Actions Status Pub Likes Health Code size License: MIT GitHub stars

Allows to use date pickers without dialog. Provides some customizable styles for date pickers.

A set of date pickers:

  • DayPicker for one day
  • WeekPicker for whole week
  • RangePicker for random range
  • MonthPicker for month
  • YearPicker for year

How to style date picker

Every date picker constructor take a style object as a parameter (if no styles passed - defaults will be used).

For single value pickers (DayPicker, MonthPicker) it is DatePickerStyles object;

For range pickers (WeekPicker, RangePickers) it is DatePickerRangeStyles object;

Customizable styles: for all date pickers

Property Description
TextStyle displayedPeriodTitle title of the date picker
TextStyle currentDateStyle style for current date
TextStyle disabledDateStyle style for disabled dates (before first and after last date user can pick)
TextStyle selectedDateStyle style for selected date
BoxDecoration selectedSingleDateDecoration decoration for selected date in case single value is selected
TextStyle defaultDateTextStyle style for date which is neither current nor disabled nor selected
DayHeaderStyle dayHeaderStyle style for all weekday headers. For more control under weekday headers styles use dayHeaderStyleBuilder
DayHeaderStyleBuilder dayHeaderStyleBuilder builder to customize weekday header's style
DayHeaderTitleBuilder dayHeaderTitleBuilder builder to customize weekday header's title

only for range date pickers (WeekPicker, RangePicker)

Property Description
BoxDecoration selectedPeriodStartDecoration decoration for the first date of the selected range
BoxDecoration selectedPeriodLastDecoration decoration for the first date of the selected range
BoxDecoration selectedPeriodMiddleDecoration Decoration for the date of the selected range which is not first date and not end date of this range

How to make some dates not selectable date picker

By default only dates before firstDate and after lastDate are not selectable. But you can set custom disabled days. DayPicker, WeekPicker and RangePicker take a SelectableDayPredicate selectableDayPredicate where you can specify function which returns if some date is disabled or not.

If some date is disabled for selection it gets disabledDateStyle.

If selected range or week pretends to include such disabled date UnselectablePeriodException occurs. To handle it - pass onSelectionError callback to date picker.

How to make special decorations for some dates

By default cells are decorated with datePickerStyles slyles (or default if no styles was passed to date picker). If you need special decoration for some days use eventDecorationBuilder. Currently only for DayPicker, WeekPicker and RangePicker.

  • If date is not selected basic styles will be merged with styles from eventDecorationBuilder.
  • If date is current date styles from eventDecorationBuilder win (if there are).
  • Otherwise basic styles (datePickerStyles) win.

What time I will get after selection?

If one day selected: you will get start of the day (00:00:00).

If range/week selected: for start you will get start of the day (00:00:00) by default. for end you will get end of the day (23:59:59.999) by default.

If month selected: you will get start (00:00:00) of the 1 day of month by default. If selected month same as month of the firstDate - you will get firstDate.

Usage

// Create week date picker with passed parameters
Widget buildWeekDatePicker (DateTime selectedDate, DateTime firstAllowedDate, DateTime lastAllowedDate, ValueChanged<DatePeriod> onNewSelected) {

 // add some colors to default settings
    DatePickerRangeStyles styles = DatePickerRangeStyles(
      selectedPeriodLastDecoration: BoxDecoration(
          color: Colors.red,
          borderRadius: BorderRadiusDirectional.only(
              topEnd: Radius.circular(10.0),
              bottomEnd: Radius.circular(10.0))),
      selectedPeriodStartDecoration: BoxDecoration(
        color: Colors.green,
        borderRadius: BorderRadiusDirectional.only(
            topStart: Radius.circular(10.0), bottomStart: Radius.circular(10.0)),
      ),
      selectedPeriodMiddleDecoration: BoxDecoration(
          color: Colors.yellow, shape: BoxShape.rectangle),
    );
    
  return WeekPicker(
      selectedDate: selectedDate,
      onChanged: onNewSelected,
      firstDate: firstAllowedDate,
      lastDate: lastAllowedDate,
      datePickerStyles: styles
  );
}

Example app

Please checkout example.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案