搜索插件、代码仓与 APP 分类

datepicker_dropdown 封面
插件详情v1.0.2

datepicker_dropdown

一个可自定义选项的 Flutter 下拉日期选择器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1190
喜欢数
48
Pub 分数
160

安装插件

flutter pub add datepicker_dropdown

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,提供可自定义选项的下拉式日期选择器,用于选择日期。它可无缝集成到表单和 UI 中,以紧凑且用户友好的方式选择日期,而无需打开完整的日历模态框。支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台。该控件轻量级,专为寻求简单、易访问的替代标准日期选择器的开发者设计。支持样式、日期格式和选择行为的自定义。

适合场景

  • 需要日期选择的表单输入
  • 轻量级日期输入,适用于移动和网页应用
  • 在有限的用户界面空间中可自定义的日期选择器
  • 将日期选择集成到下拉菜单中
  • 面向可访问性的日期输入组件

主要特点

  • 基于下拉框的日期选择
  • 跨平台兼容性
  • 可自定义的外观和行为
  • 支持多种日期格式
  • 与现有表单的轻松集成
  • 所需的样板代码最少

适合对象

  • 需要紧凑型日期选择器的开发者
  • UI 上存在空间限制的项目
  • 面向多个平台的应用程序
  • 注重可访问性的团队
  • 需要一致日期输入设计的 UI

使用建议

  • 仅限单日期选择
  • 无内置验证
  • 需要手动处理日期解析
  • 不适用于复杂日期范围
  • 与完整日历选择器相比,视觉反馈较少

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Date Picker Dropdown

pub package

A customizable dropdown date picker for Flutter with support for multiple field orders, validation, localization, and form-friendly callbacks.

Web demo: datepicker.robertrobinson.in

Features

  • Day, month, and year dropdowns with configurable order
  • Optional form validation for each field
  • Locale-specific month labels
  • Configurable year range, spacing, flex, styles, and decorations
  • Safe handling of invalid date combinations such as 31 February
  • Controlled-widget support when the parent rebuilds with new selected values

Main View Month View Date View Year View

Getting Started

Add the package to your pubspec.yaml:

dependencies:
  datepicker_dropdown: ^1.0.2

Then run:

flutter pub get

Basic Usage

import 'package:datepicker_dropdown/datepicker_dropdown.dart';
import 'package:datepicker_dropdown/order_format.dart';
import 'package:flutter/material.dart';

class BirthDateField extends StatefulWidget {
  const BirthDateField({super.key});

  @override
  State<BirthDateField> createState() => _BirthDateFieldState();
}

class _BirthDateFieldState extends State<BirthDateField> {
  int? _day;
  int? _month;
  int? _year;

  @override
  Widget build(BuildContext context) {
    return DropdownDatePicker(
      dateFormatOrder: OrderFormat.ydm,
      startYear: 1900,
      endYear: DateTime.now().year,
      selectedDay: _day,
      selectedMonth: _month,
      selectedYear: _year,
      onChangedDay: (String? value) {
        setState(() {
          _day = int.tryParse(value ?? '');
        });
      },
      onChangedMonth: (String? value) {
        setState(() {
          _month = int.tryParse(value ?? '');
        });
      },
      onChangedYear: (String? value) {
        setState(() {
          _year = int.tryParse(value ?? '');
        });
      },
    );
  }
}

Form Example

DropdownDatePicker(
  dateFormatOrder: OrderFormat.mdy,
  isFormValidator: true,
  isDropdownHideUnderline: true,
  startYear: 1900,
  endYear: 2025,
  hintDay: 'Day',
  hintMonth: 'Month',
  hintYear: 'Year',
  inputDecoration: InputDecoration(
    enabledBorder: const OutlineInputBorder(),
    border: OutlineInputBorder(
      borderRadius: BorderRadius.circular(10),
    ),
    contentPadding: const EdgeInsets.symmetric(horizontal: 12),
  ),
  onChangedDay: (String? value) {
    debugPrint('day: $value');
  },
  onChangedMonth: (String? value) {
    debugPrint('month: $value');
  },
  onChangedYear: (String? value) {
    debugPrint('year: $value');
  },
)

Notes

  • dateFormatOrder is the preferred property name.
  • dateformatorder is still supported as a deprecated backwards-compatible alias.
  • If the current day becomes invalid after a month or year change, the widget automatically adjusts it to the last valid day and notifies onChangedDay.
  • The widget syncs correctly when the parent rebuilds with new selectedDay, selectedMonth, or selectedYear values.

Supported Locales

en, en_abbv, num, ar, de_DE, el_GR, es_ES, fr_FR, gu_IN, hi_IN, id_ID, it_IT, ja, kn_IN, ko_KR, ml_IN, mr_IN, nl_NL, pl_PL, pt_BR, ru_RU, sv_SE, ta_IN, te_IN, th, tr, vi, zh_CN

Example App

See the example app in example/lib/main.dart for a complete integration.

Repository

Source code: github.com/Robertrobinson777/dropdown_date_picker

Support

Buy Me A Coffee

所属分类

源码仓库

使用此插件的项目

暂无相关数据。