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

month_year_picker 封面
插件详情v0.5.0+1

month_year_picker

受 Flutter 日期选择器设计启发的月份年份选择器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
23
喜欢数
92
Pub 分数
160

安装插件

flutter pub add month_year_picker

插件介绍

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

一个 Flutter 包,提供了一个月和年选择器小部件,灵感来自 Flutter 原生日期选择器的设计。它允许用户在简洁直观的界面上选择特定的月份和年份,非常适合不需要精确到天的日期输入表单。该选择器完全可自定义,并支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。该包在构建时考虑了 Flutter 的 Material 和 Cupertino 主题,确保在各种设备上保持一致的 UI。

适合场景

  • 选择出生月份和年份
  • 按月和年过滤数据
  • 设置纪念日日期
  • 配置订阅开始日期
  • 进入毕业年份

主要特点

  • Material 和 Cupertino 主题支持
  • 跨平台兼容性
  • 可自定义外观
  • 简单的 API 集成
  • 流畅的动画
  • 无对外部库的依赖

适合对象

  • 需要选择月份/年份的表单输入
  • 基于日历的应用程序
  • 用户资料设置流程
  • 数据过滤接口
  • 具有日期相关功能的移动和网页应用

使用建议

  • 不包括日期选择
  • 仅限月份和年份
  • 需要手动处理日期格式化
  • 不适用于精确的时间范围
  • 可能需要额外的业务逻辑验证

原始 README

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

Material Month/Year Picker

Pub GitHub Workflow Status

The month year picker inspired by the Flutter's date picker design.

Quick Start

  1. Open your pubspec.yaml file and add this entry:

    month_year_picker: ^0.5.0+1
    

    OR just run flutter pub add month_year_picker using your preferred terminal app.

  2. Then run flutter pub get.

  3. Import this library into your code:

    import 'package:month_year_picker/month_year_picker.dart';
    

    Additionally, ensure your MaterialApp refers to the following localizationsDelegates:

        GlobalMaterialLocalizations.delegate,
        MonthYearPickerLocalizations.delegate,
    
  4. Usage in code:

    final selected = await showMonthYearPicker(
      context: context,
      initialDate: DateTime.now(),
      firstDate: DateTime(2019),
      lastDate: DateTime(2023),
    );
    

Parameters

Parameter Description
context Must not be null. Will be passed to the internal showDialog function call.
initialDate Must not be null and must fall between the firstDate and lastDate. The initialDate will be truncated to its year and month components. When the month/year picker is first displayed, it will show the month/year of the initialDate, with initialDate selected.
firstDate Must not be null. The firstDate will be truncated to its year and month components. This is the earliest allowable month/year.
lastDate Must not be null. The lastDate will be truncated to its year and month components. This is the latest allowable month/year.
selectableMonthYearPredicate Can be null. The function to provide full control over which month/year can be selected. If provided, only the month/year that the selectableMonthYearPredicate returns true for will be selectable.
locale Can be null. If provided, will be used to set the locale for the month/year picker. Otherwise, it defaults to the ambient locale provided by Localizations.
useRootNavigator Can be null. Will be passed to the internal showDialog function call.
routeSettings Can be null. Will be passed to the internal showDialog function call.
textDirection Can be null. If provided, will be used to set the text direction for the month/year picker. Otherwise, it defaults to the ambient locale provided by Directionality.
builder Can be null. This parameter can be used to wrap the dialog widget with a parent widget.
initialMonthYearPickerMode Must not be null. Can be used to have the year picker initially appear in the MonthYearPickerMode.year mode. It defaults to the MonthYearPickerMode.month mode.

Screenshots

Mode Screenshot
Month picker in portrait mode with default locale.
Year picker in portrait mode with default locale.
Month picker in portrait mode with Malay locale.
Year picker in portrait mode with Malay locale.
Month picker in portrait mode with Arabic locale.
Year picker in portrait mode with Arabic locale.
Month picker in landscape mode with default locale.
Year picker in landscape mode with default locale.
Month picker in landscape mode with Malay locale.
Year picker in landscape mode with Malay locale.
Month picker in landscape mode with Arabic locale.
Year picker in landscape mode with Arabic locale.

Building From Source

Dependencies
  1. Dart SDK version 3.8.0 or newer.
  2. Flutter SDK version 3.32 or newer.
Steps
  1. Clone this git repo into your machine.
  2. Run .\gen-l10n.ps1 to re-generate the localised strings.

Features and Bugs

Please file feature requests and bugs at the issue tracker.

License

This project is licensed under the MIT License - see the LICENSE file for details.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。