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

插件详情v2.1.0

datetime_picker_formfield_new

一个会发出 DateTime 的 TextFormField,可帮助显示 Material、Cupertino 和其他样式的选择器对话框。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8350
喜欢数
34
Pub 分数
140

安装插件

flutter pub add datetime_picker_formfield_new

插件介绍

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

一个 Flutter 包,提供可发出 DateTime 值并集成 Material、Cupertino 及其他样式日期/时间选择器对话框的 TextFormField。它通过在跨平台环境中结合输入字段与直观的选择器界面,简化了表单处理。专为需要选择日期或时间的表单设计,支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台。该包通过提供一致且适应平台的选型器,以最少的设置增强了用户体验。

适合场景

  • 需要选择日期/时间的表单输入
  • 跨平台日期/时间输入
  • 与表单验证的集成
  • 可自定义的选取器样式
  • 动态表单字段更新
  • 移动和网页应用中的友好时间输入

主要特点

  • 支持 Material 和 Cupertino 选择器
  • 发出 DateTime 对象
  • 跨平台兼容性
  • 与 Form 小部件的轻松集成
  • 可自定义的对话框外观
  • 内置验证支持

适合对象

  • 开发跨平台表单的开发者
  • 需要原生外观的日期/时间输入的应用程序
  • 注重跨设备一致用户体验的团队
  • 使用 Flutter 表单架构的项目
  • 希望日期选择器代码量最少的用户

使用建议

  • 需要 Flutter 2.0+
  • 可能需要额外的样式来支持复杂主题
  • 仅限基本的日期/时间格式
  • 无内置本地化支持
  • 依赖于底层平台的选择器行为
  • 不适合高度自定义的选取器 UI

原始 README

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

DateTimeField

A TextFormField that emits DateTimes and helps show Material, Cupertino, and other style picker dialogs.

Fork with support for flutter >3.0.0

Example

See the example tab (example/lib/main.dart) for more.

screenshot.gif

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';

// ...

class BasicDateField extends StatelessWidget {
  final format = DateFormat("yyyy-MM-dd");
  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Text('Basic date field (${format.pattern})'),
      DateTimeField(
        format: format,
        onShowPicker: (context, currentValue) {
          return showDatePicker(
            context: context,
            firstDate: DateTime(1900),
            initialDate: currentValue ?? DateTime.now(),
            lastDate: DateTime(2100),
          );
        },
      ),
    ]);
  }
}

class BasicTimeField extends StatelessWidget {
  final format = DateFormat("HH:mm");
  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Text('Basic time field (${format.pattern})'),
      DateTimeField(
        format: format,
        onShowPicker: (context, currentValue) async {
          final time = await showTimePicker(
            context: context,
            initialTime: TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
          );
          return DateTimeField.convert(time);
        },
      ),
    ]);
  }
}

class BasicDateTimeField extends StatelessWidget {
  final format = DateFormat("yyyy-MM-dd HH:mm");
  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Text('Basic date & time field (${format.pattern})'),
      DateTimeField(
        format: format,
        onShowPicker: (context, currentValue) async {
          return await showDatePicker(
            context: context,
            firstDate: DateTime(1900),
            initialDate: currentValue ?? DateTime.now(),
            lastDate: DateTime(2100),
          ).then((DateTime? date) async {
            if (date != null) {
              final time = await showTimePicker(
                context: context,
                initialTime:
                    TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
              );
              return DateTimeField.combine(date, time);
            } else {
              return currentValue;
            }
          });
        },
      ),
    ]);
  }
}

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目