year_month_picker
A Flutter package that enables users to select a year and month via a dialog or bottom sheet interface.
🚀 Web Demo: https://philongdo.github.io/#/year_month_picker
Installation
Add the following dependency to your pubspec.yaml file:
dependencies:
year_month_picker: ^1.0.2
Then, run flutter pub get to install the package.
Importing
Import the package in your Dart code where you want to use it:
import 'package:year_month_picker/year_month_picker.dart';
Usage
Show Year-Month Picker Dialog
Use showYearMonthPickerDialog to display a dialog for selecting year and month:
import 'package:year_month_picker/year_month_picker.dart';
// ...existing code...
final selected = await showYearMonthPickerDialog(
context: context,
firstYear: 2000,
lastYear: 2100,
initialYearMonth: DateTime.now(),
);
// `selected` is a DateTime (year & month) or null if cancelled
Dialog Example:
Show Year-Month Picker Bottom Sheet
Use showYearMonthPickerBottomSheet to display a bottom sheet picker:
import 'package:year_month_picker/year_month_picker.dart';
// ...existing code...
final selected = await showYearMonthPickerBottomSheet(
context: context,
firstYear: 2000,
lastYear: 2100,
initialYearMonth: DateTime.now(),
);
// `selected` is a DateTime (year & month) or null if cancelled
Bottom Sheet Example:
Customization
Both functions support various customization options:
yearItemBuilder,monthItemBuilder: Customize year/month item widgets.okButtonBuilder,cancelButtonBuilder: Customize action buttons.locale,textDirection: Localization and text direction support.onYearChanged,onMonthChanged: Callbacks for selection changes.
See the API documentation for all available parameters.
☕ Buy Me a Coffee
If you find this package useful, you can support me here: